Skip to content

fix(status): finish a --no-wait login once it is approved - #26

Open
leeminseung wants to merge 2 commits into
bee-computer:mainfrom
leeminseung:fix/status-finishes-no-wait-login
Open

leeminseung wants to merge 2 commits into
bee-computer:mainfrom
leeminseung:fix/status-finishes-no-wait-login

Conversation

@leeminseung

@leeminseung leeminseung commented Oct 20, 2026 •

Copy link
Copy Markdown

After bee login --no-wait and an approval in the Bee app, bee status now 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 way bee login does. In that case bee status makes 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

  • Whether to keep the second commit, which makes bee logout clear a pending login. I suggest keeping it (see "Code").
  • Whether the MCP bee_status tool should finish a pending login too. Its code describes it as reading local state only, so I left it unchanged.
  • Whether bee status should 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-wait prints 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-wait as "useful for agents/automation; finish later with bee status or by re-running bee login". With 0.7.3 on macOS:

  1. bee login --no-wait prints a link that is valid for about 6 minutes.
  2. The link is approved in the Bee app on the phone.
  3. bee status prints "Not logged in." It keeps printing that on every later run.
  4. bee login resumes the same pending request, sees the approval at once, and saves the token. Only after this does bee status show the account.

An agent or script that follows the hint and polls bee status never sees the login finish, and the approval is lost once the request expires. The code on main behaves the same way.

bee status only reads the stored token (sources/commands/status/index.ts, lines 38 to 42 on main). The pending request that --no-wait saves (the pairing:<env> keychain item, or pairing-<env>.json with the file store) is read only by bee login. So after an approval, nothing stores a token until bee login runs again, which matches what #9 reports after bee 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 status rather than a second bee login --no-wait, because the hint and the README already send callers to bee status, and scripts written against them poll it. A caller that uses --no-wait often cannot block for minutes, such as an agent whose commands run under a time limit, so bee status has to report the outcome. It makes at most one pairing request and never polls, while bee login without --no-wait keeps polling until the request is approved or expires.

Saved request What bee status does
Approved Finishes the login the way bee login does (clears the pending request, checks the token with /v1/me, stores it), then reports the account as usual
Approved, but /v1/me fails Prints "Not logged in." with the error and stores nothing. As in bee login, the pending request was cleared when the token came back, so the next step is bee login
Still waiting Prints "Not logged in.", says the login is pending, and repeats the link and how long it stays valid
Expired, by the server's answer or by its saved expiresAt Prints "Not logged in.", clears the pending request, and says to run bee login again
The pairing check fails (network, server error, unexpected answer) Prints "Not logged in." with the error, and keeps the pending request so the next bee status can ask again
None Prints "Not logged in." as before, without any network call

Every case exits 0, as bee status on main does 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 status behaves as before.

After the link is approved:

$ bee status
API: production (https://app-api-developer.ce.bee.amazon.dev/)
Pending login approved. Logged in.
Token: abcd...wxyz
Verified as Jane Doe (id 42).

While approval is still pending:

$ bee status
API: production (https://app-api-developer.ce.bee.amazon.dev/)
Not logged in.
Login pending approval.
Authentication link: https://bee.computer/connect#<request id>
This authentication request will expire in approximately 5 minutes.
After approving, run 'bee status' again to finish, or run 'bee login' to wait for approval.

Waiting

With no stored token and a pending login, bee status now makes the same pairing request that bee login polls with. Offline, the existing retries in requestAppPairing run before the failure is shown, which takes about 2.5 minutes (151 seconds of backoff). When a token is stored, bee status already calls /v1/me, whose own retry loop has the same settings, so a logged-in bee status already waits about as long offline.

If the server accepts the connection but never answers, the check has no time limit, because requestAppPairing sets none. This happened in one of two tries against production, both with this branch. A bee status sent 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 first bee status after the approval finished the login at once. bee login polls 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 status could 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/me and stores it (verifyAndSaveToken) are now small functions. bee login and the new finishPendingLogin, which bee status calls, both use them. bee login behaves as before, apart from the malformed entry described next.

loadPairingState now ignores a saved request that is missing fields, the same way loadProxyConfig ignores a malformed proxy config. Without this, a truncated or hand-edited entry would make bee status fail with a Buffer.from type error, and on main it already makes every bee login fail. Such an entry is now skipped, so the next bee login starts a new request and replaces it.

The second commit makes bee logout clear a pending login, a malformed one included. Without it, a link approved before bee logout could sign the user back in on the next bee status. It is a separate commit in case you would rather handle logout differently.

How it was tested

  • bun run typecheck and bun run build pass.
  • 11 new tests run offline, with the pairing API and /v1/me stubbed. 7 of them fail on main. The other 4 cover behaviour that should not change.
  • With outbound network blocked and the two files that call live Bee hosts left out, the suite goes from 374 to 385 passing, with 0 failures (commands below). It also passes at the first commit alone, so dropping the logout commit keeps the branch green.
  • Against a local stand-in for the pairing API, a replay of the steps above through sources/main.ts finishes the login on this branch and keeps printing "Not logged in." on main.
  • Against production on macOS, two tries, described under "Waiting". In the one that went through, the first bee status after 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.

git ls-files 'sources/*.test.ts' 'sources/**/*.test.ts' \
  | grep -v -e '^sources/client.test.ts$' -e 'appPairingRequest.test.ts$' \
  | xargs sandbox-exec -f no-network.sb bun test

no-network.sb blocks outbound connections except loopback.

(version 1)
(allow default)
(deny network-outbound)
(allow network-outbound (remote ip "localhost:*"))
(allow network-outbound (remote unix-socket (subpath "/private/var/folders")))
(allow network-outbound (remote unix-socket (subpath "/private/tmp")))
  • sources/commands/status/index.test.ts adds 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/me rejects 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.ts adds 1 test. bee login resumes 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.ts adds 1 test. bee logout clears a pending login.
  • In the status tests, global fetch is replaced in beforeEach. 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.
  • The two files left out are sources/client.test.ts and sources/commands/auth/appPairingRequest.test.ts. With them included and the network blocked, the same 3 tests fail before and after.
  • The changed test files passed 10 runs in random order, and the full suite passes with --parallel.
  • The replay used a --preload script that replaces fetch. It is not part of this PR, and I can share it.

Notes for reviewers

  • The README and the hint are unchanged, since what they say about bee status is now true.
  • Running bee login --no-wait a second time still only prints the link again.
  • A resumed bee login still clears the pending request on any error, as before.
  • Not tested: bee status and a resumed bee login finishing the same request at the same moment.
  • This branch merges cleanly with every open PR except feat: improvements for CLI based agent interface, TUI dashboard #8, which already conflicts with main in .gitignore, README.md and bun.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

leeminseung and others added 2 commits October 20, 2026 20:45
`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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant