Skip to content

connector: retry transient token recovery failures instead of logging out - #294

Open
Fizzadar wants to merge 4 commits into
mainfrom
nick/connection-state-lifecycle
Open

Fizzadar wants to merge 4 commits into
mainfrom
nick/connection-state-lifecycle

Conversation

@Fizzadar

@Fizzadar Fizzadar commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

A failed token recovery used to report BAD_CREDENTIALS "logged out by another client" for any error, keep the dead token so IsLoggedIn stayed true, stop the poll loop until restart, and re-run a password login on every send. Network, 5xx and rate-limit failures now report TRANSIENT_DISCONNECT and retry with capped, jittered backoff, and recovery itself backs off so sends no longer trigger password logins. Only a rejected refresh and re-login from a session-wide call (receive, the receive auth probe or the startup token check) invalidates the session: the token is cleared and line-token-expired is sent and persisted so restarts keep the same state. Sends and media only return the error, since a 403 there can be about the object. Idle SSE timeouts report TRANSIENT_DISCONNECT until the stream reopens, and a startup token check that fails transiently reports TRANSIENT_DISCONNECT and waits for a working token in the background before running the one-shot startup work and starting the workers. The account check after a PIN approval retries network and server errors so a blip doesn't cost another PIN prompt.

🤖 Generated with Claude Code

… out

A failed token recovery used to send BAD_CREDENTIALS "logged out by another
client" for any error, keep the dead token so IsLoggedIn stayed true, and stop
the poll loop for good, while every later send re-ran a password login.

Network, 5xx and rate-limit failures now report TRANSIENT_DISCONNECT and the
poll loop keeps retrying with capped, jittered backoff, and recovery itself
backs off so sends no longer trigger a password login each. Only a rejected
refresh and re-login invalidates the session, clearing the token and sending
line-token-expired, which is persisted so a restart reports the same state.
Idle SSE timeouts and a startup token check that fails transiently now report
TRANSIENT_DISCONNECT, and CONNECTED is sent once the stream opens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@indent
indent Bot marked this pull request as ready for review October 28, 2026 20:14
@indent

indent Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Issues

All clear! No issues remaining. 🎉

4 issues already resolved
  • When the startup token check fails and recovery fails transiently, Connect carries on, but the one-shot startup steps (phone notifications, E2EE storage key, blocked contacts, chat sync) all fail on the recovery backoff and are never re-run. The login later shows CONNECTED without them. (fixed by commit ac22648)
    Found by Indent Review Agent
  • Any send or media call that hits a 403 and then fails recovery for a local reason (no refresh token, no stored credentials, QR login required) now clears the token and persists line-token-expired, even though the access token may still be valid. (fixed by commit ac22648)
    Found by Indent Review Agent
  • If PIN approval succeeds but the following profile verification fails with a network or 5xx error, the error is treated as transient and recovery re-runs the login, re-prompting the user for a PIN on each retry. (fixed by commit ac22648)
    Found by Indent Review Agent
  • Startup now waits forever if getProfile keeps failing with a non-auth, non-transient error (e.g. 4xx other than 401/403, or a profile decode failure). startSession never runs, so no polling, sync or message delivery, though the token is valid and main connected in this case. (fixed by commit f8cbb83)
    Found by Indent Review Agent

CI Checks

All CI checks passed on 635f688.

Review agents

Select any unchecked box below to run or rerun that agent.

Passed (1)
  • Indent Review Agent · No remaining issues found
Full results

Indent Review Agent

  • Summary: No remaining issues found
  • Last ran on commit: 635f6886
  • Latest result
    {
      "summary": "No remaining issues found",
      "findings": []
    }

Comment thread pkg/connector/client.go Outdated
Comment thread pkg/connector/auth_recovery.go Outdated
…sh startup after token recovery

- Only receive, the receive auth probe and the startup token check
  invalidate the session when recovery fails. Sends and media can get a
  403 about the object itself, so a failed recovery there only returns
  the error, as before.
- When the startup token check fails transiently, wait for a working
  token in the background before running the one-shot startup work
  (phone notifications, E2EE storage key, block list, chat sync) and
  starting the workers, instead of running it against a failing token.
- Retry the post-PIN account check a few times on network or server
  errors, so a blip doesn't throw away the approved login and prompt for
  another PIN.
Any other getProfile failure (an unexpected 4xx or a decode error) says
nothing about the token, so start the session instead of waiting
forever.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant