Skip to content

A 5xx while waiting for sign-in approval no longer ends the login - #808

Open
pullely wants to merge 1 commit into
mainfrom
claude/cliauth-poll-retry-5xx
Open

pullely wants to merge 1 commit into
mainfrom
claude/cliauth-poll-retry-5xx

Conversation

@pullely

@pullely pullely commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

What changed

orun auth login (browser flow) and orun auth login --device keep waiting for approval when the platform answers a poll with an HTTP 5xx, or with code internal_error, instead of ending the login on the first one. Such an answer is handled like a dropped connection: it counts against maxConsecutivePollFailures, the loop sleeps its poll interval (or the server's Retry-After when that is longer, never past the grant deadline) and polls again. Four in a row still give up with giving up after 4 consecutive poll failures, and the error wraps the server's answer.

  • retryablePollError: any 5xx or code internal_error is retryable. 401, 403, 404 and 410 stay terminal whatever their code.
  • pollRetryWait: the poll interval, stretched to Retry-After, capped at the time left on the grant.
  • BrowserLogin (cli_code redeem) and DeviceLogin route 5xx into the existing transport-failure branch. The counter is renamed pollFails because it no longer counts only transport failures. The 429 branches and Refresh are unchanged.

Why

During the 2026-11-11 prod database outage, sign-in was impossible. sourceplane/orun-cloud#2356 fixed the platform side: identity-worker now answers a database blip on the grant read with a retryable 503 internal_error instead of 401 not_found, and a device poll whose grant read failed answers RFC 8628 slow_down. The released CLI already handles that. But the CLI still returned on any non-pending, non-429 *APIError in the cli_code loop, and on anything but 403/410/429 in the device loop. So a single blip during the browser flow still ended the login, now with a clear "temporarily unavailable" error rather than a misleading one. This closes that gap.

Refresh is left alone: the platform answers a store failure there with 503, and RefreshSession already keeps the stored session in that case (only 401/404/410 clear it).

How it was verified

go test ./internal/cliauth/... passes (ok … 46s), go vet ./internal/cliauth/ and gofmt -l are clean.

New cases in internal/cliauth/login_test.go. The fake backend gains browserUnavailable / deviceUnavailable (polls answered 503 internal_error, placed after the pending polls, so the blip lands on the poll that would redeem the approved grant) and unavailableRetryAfter:

  • TestBrowserLogin_UnavailableMidPollRetried: pending → 503 → redeem completes the login (3 polls).
  • TestBrowserLogin_UnavailableOutageTerminal: 503 on every poll gives up after exactly 4 polls with the consecutive-poll-failures error wrapping the 503 *APIError.
  • TestDeviceLogin_UnavailableMidPollRetried: pending → 503 with Retry-After: 2 → complete. The test asserts ≥ 3 s elapsed, so the 2 s Retry-After was honored over the grant's 1 s interval.
  • TestDeviceLogin_UnavailableOutageTerminal: the same give-up as the browser case, on the device flow.
  • TestRetryablePollError, TestPollRetryWait: table tests for the classifier (including 401 internal_error → terminal, 429 → not this branch) and the wait.

With retryablePollError forced to false (the old behavior), all four flow tests fail with redeem Orun login: Service temporarily unavailable (internal_error) / DeviceLogin error = Service temporarily unavailable (internal_error).

Checklist

  • make fmt lint test passes locally (for internal/cliauth: gofmt, go vet, go test)
  • Tests cover the change (a regression test for a bug fix)
  • Docs updated in sourceplane/orun-website: no doc change (no flag or output changes)
  • Release notes: to be written with the release that ships this
  • Commits are signed off (git commit -s)

🤖 Generated with Claude Code

Both sign-in poll loops (the browser cli_code redeem and the device
flow) now treat an HTTP 5xx answer, or code internal_error, like a
dropped connection: it counts against maxConsecutivePollFailures, the
loop sleeps its poll interval (stretched to Retry-After when that is
longer, never past the grant deadline) and polls again. Four in a row
still give up with "giving up after 4 consecutive poll failures".

The platform now answers a database blip on the grant read with 503
internal_error (sourceplane/orun-cloud#2356), but the released CLI
ended the login on the first 503, so a blip during the browser flow
still cost the user their sign-in. 401, 403, 404 and 410 stay terminal
whatever their code; Refresh is unchanged (it already keeps the session
on a 503).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Rahul Varghese <rahul.varghese@sourceplane.ai>
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.

2 participants