Repository navigation
fix(status): finish a --no-wait login once it is approved - #26
Open
leeminseung wants to merge 2 commits into
Open
leeminseung wants to merge 2 commits into
leeminseung wants to merge 2 commits into
Conversation
`bee login --no-wait` saves the pairing request and tells the user to confirm with `bee status`, but status only looked at the stored token. After the request was approved it kept printing "Not logged in." until `bee login` was run a second time. With no stored token, status now checks a saved pairing request once, without polling. An approved request is finished the way `bee login` finishes it: the pairing state is cleared, and the token is verified with /v1/me and stored. A pending request prints the link again, an expired one is cleared with a hint to run `bee login`, and a failed check is reported while the request is kept for another try. The pairing check, the expiry rule and the token storage are shared with `bee login` rather than copied. A saved pairing request with missing fields is now ignored when loaded, so it cannot break either command. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Now that `bee status` can finish a saved pairing request, logout also drops that request, so a status check after logging out cannot sign the user back in. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After
bee login --no-waitand an approval in the Bee app,bee statusnow finishes the login. When no token is stored, it checks the saved pairing request once and, if it was approved, verifies and stores the token the waybee logindoes. In that casebee statusmakes a network request, which has no time limit of its own, and may write the token store. About 180 of the roughly 600 added lines are production code, and the rest are tests.Decisions for you
bee logoutclear a pending login. I suggest keeping it (see "Code").bee_statustool should finish a pending login too. Its code describes it as reading local state only, so I left it unchanged.bee statusshould get a time limit in this PR or after fix(login): stop retrying a request the caller already aborted #18 (see "Waiting").What was wrong
bee login --no-waitprints an authentication link, saves the pending pairing request, and exits. Its last line says "Then run 'bee status' to confirm, or 'bee login' again to resume and finish". The README describes--no-waitas "useful for agents/automation; finish later withbee statusor by re-runningbee login". With 0.7.3 on macOS:bee login --no-waitprints a link that is valid for about 6 minutes.bee statusprints "Not logged in." It keeps printing that on every later run.bee loginresumes the same pending request, sees the approval at once, and saves the token. Only after this doesbee statusshow the account.An agent or script that follows the hint and polls
bee statusnever sees the login finish, and the approval is lost once the request expires. The code onmainbehaves the same way.bee statusonly reads the stored token (sources/commands/status/index.ts, lines 38 to 42 onmain). The pending request that--no-waitsaves (thepairing:<env>keychain item, orpairing-<env>.jsonwith the file store) is read only bybee login. So after an approval, nothing stores a token untilbee loginruns again, which matches what #9 reports afterbee login --no-wait. That issue also lists other attempts that failed for the reporter, and I have not looked into those.What changes
I changed
bee statusrather than a secondbee login --no-wait, because the hint and the README already send callers tobee status, and scripts written against them poll it. A caller that uses--no-waitoften cannot block for minutes, such as an agent whose commands run under a time limit, sobee statushas to report the outcome. It makes at most one pairing request and never polls, whilebee loginwithout--no-waitkeeps polling until the request is approved or expires.bee statusdoesbee logindoes (clears the pending request, checks the token with/v1/me, stores it), then reports the account as usual/v1/mefailsbee login, the pending request was cleared when the token came back, so the next step isbee loginexpiresAtbee loginagainbee statuscan ask againEvery case exits 0, as
bee statusonmaindoes when it prints "Not logged in.". "Not logged in." is still printed whenever there is no login, and "Verified as" still appears only when there is one, so scripts that look for either line keep working. With a stored token, or in proxy mode,bee statusbehaves as before.After the link is approved:
While approval is still pending:
Waiting
With no stored token and a pending login,
bee statusnow makes the same pairing request thatbee loginpolls with. Offline, the existing retries inrequestAppPairingrun before the failure is shown, which takes about 2.5 minutes (151 seconds of backoff). When a token is stored,bee statusalready calls/v1/me, whose own retry loop has the same settings, so a logged-inbee statusalready waits about as long offline.If the server accepts the connection but never answers, the check has no time limit, because
requestAppPairingsets none. This happened in one of two tries against production, both with this branch. Abee statussent around the time of the approval got no answer for more than four minutes, and the request expired before I stopped the command. In the other try, the firstbee statusafter the approval finished the login at once.bee loginpolls with the same call, so it can hang the same way.A limit fits best on top of #18, which stops retrying a request the caller has aborted.
bee statuscould then pass a timeout signal that ends both waits. If you would rather have the limit in this PR, I can add it once #18 is merged. I can also add it now as a signal that cuts off a request with no answer, but until #18 lands the retries after it would still take up to about 2.5 minutes.Code
Status reuses the login code instead of copying it. In
sources/commands/login/index.ts, one poll of the pairing API (checkAppPairing), the expiry rule (isPairingExpired) and the step that checks a token with/v1/meand stores it (verifyAndSaveToken) are now small functions.bee loginand the newfinishPendingLogin, whichbee statuscalls, both use them.bee loginbehaves as before, apart from the malformed entry described next.loadPairingStatenow ignores a saved request that is missing fields, the same wayloadProxyConfigignores a malformed proxy config. Without this, a truncated or hand-edited entry would makebee statusfail with aBuffer.fromtype error, and onmainit already makes everybee loginfail. Such an entry is now skipped, so the nextbee loginstarts a new request and replaces it.The second commit makes
bee logoutclear a pending login, a malformed one included. Without it, a link approved beforebee logoutcould sign the user back in on the nextbee status. It is a separate commit in case you would rather handle logout differently.How it was tested
bun run typecheckandbun run buildpass./v1/mestubbed. 7 of them fail onmain. The other 4 cover behaviour that should not change.sources/main.tsfinishes the login on this branch and keeps printing "Not logged in." onmain.bee statusafter the approval printed "Pending login approved. Logged in." and verified the account.Test details
The counts above come from this command on macOS, run from the repository root.
no-network.sbblocks outbound connections except loopback.sources/commands/status/index.test.tsadds 9 tests. An approved request is finished (token stored, pending request cleared, masked token and account printed). A pending request is checked exactly once, its link is repeated, and it is kept. A request the server reports as expired is cleared. A request past its expiry time is cleared without contacting Bee. With no pending login, or a saved request with missing fields, the output is unchanged. A failed check is reported and the request kept. When/v1/merejects the approved token, nothing is stored and the request is cleared. A stored token wins and the pending request is left alone.sources/commands/login/index.test.tsadds 1 test.bee loginresumes an approved pending request, stores the token and clears the request. This path had no test, and this change refactors it.sources/commands/logout/index.test.tsadds 1 test.bee logoutclears a pending login.fetchis replaced inbeforeEach. Both stubs answer an unexpected URL with a 400, which the CLI does not retry, so a failing test cannot fall through to a real host.sources/client.test.tsandsources/commands/auth/appPairingRequest.test.ts. With them included and the network blocked, the same 3 tests fail before and after.--parallel.--preloadscript that replacesfetch. It is not part of this PR, and I can share it.Notes for reviewers
bee statusis now true.bee login --no-waita second time still only prints the link again.bee loginstill clears the pending request on any error, as before.bee statusand a resumedbee loginfinishing the same request at the same moment.mainin.gitignore,README.mdandbun.lock. With fix(login): stop retrying a request the caller already aborted #18 merged on top, typecheck passes and the suite has 392 passing and 0 failing.🤖 Generated with Claude Code