Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(gateway): tolerate transient poll errors during device authorization - #14056

Open
hobostay wants to merge 1 commit into
Kilo-Org:mainfrom
hobostay:fix/gateway-poll-transient-errors
Open

fix(gateway): tolerate transient poll errors during device authorization#14056
hobostay wants to merge 1 commit into
Kilo-Org:mainfrom
hobostay:fix/gateway-poll-transient-errors

Conversation

@hobostay

Copy link
Copy Markdown
Contributor

What

Makes poll() in @kilocode/kilo-gateway (packages/kilo-gateway/src/auth/polling.ts) tolerate transient errors from the poll function instead of aborting on the first one.

Why

During device authorization sign-in, the poll function (pollDeviceAuth) throws on any non-202/403/410 non-OK status (500/502/429) and on network failures. poll() previously let that throw propagate, so a single transient error — a gateway deploy, a proxy hiccup, a brief network drop — killed the entire login flow while the user was mid-authorization in the browser, forcing them to start over. The PollResult.error contract already distinguishes terminal failures (denied/expired, returned as { continue: false, error }) from everything else; a thrown request error is not a terminal state and shouldn't end the flow.

Now a thrown poll error is treated as a failed attempt: polling continues, and the last error is thrown only once maxAttempts is exhausted (instead of the generic timeout message). Terminal result errors still stop polling immediately, and the no-data and timeout paths are unchanged.

Testing

Added packages/kilo-gateway/test/auth/polling.test.ts covering: recovery after transient thrown errors (fails on the previous implementation), last-error propagation with full attempt consumption on exhaustion, immediate stop on terminal result errors, and the unchanged no-error timeout path. bun test (packages/kilo-gateway, 115 pass) and bun run typecheck are green.

const result: PollResult<T> = await pollFn()
// A thrown poll error (e.g. a transient 5xx or network failure) is not
// terminal: remember it and keep polling until attempts run out.
const result: PollResult<T> | undefined = await Promise.resolve()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Every thrown error is retried, including permanent ones.

pollDeviceAuth (device.ts:38-40) throws for any non-OK status other than 202/403/410, so permanent failures like 400/404 are now retried instead of failing fast. Because maxAttempts is derived from the code expiry (device-auth-tui.ts:37), a permanent error can now keep the sign-in spinner running for the full expiry window (minutes). A 429 is likewise retried on a fixed interval without honoring Retry-After. Consider distinguishing transient (5xx/network) from terminal errors, e.g. an optional retryable predicate on PollOptions, or document that all thrown errors are intentionally retried.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

}
}

if (error) throw error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: if (error) can drop the real error and report a stale one.

The truthiness check means a pollFn that rejects/throws a falsy value (undefined, null, 0, "") falls through to the generic timeout message and hides the cause; error !== undefined would be accurate. Separately, error is never cleared after a successful poll, so if an early attempt throws and all later attempts return { continue: true }, exhaustion reports the old transient error instead of the timeout. Consider resetting error to undefined after a successful pollFn call.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 2
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/kilo-gateway/src/auth/polling.ts 21 Catch-all retry also retries permanent/non-transient errors (400/404/429), potentially delaying an inevitable failure until code expiry.
packages/kilo-gateway/src/auth/polling.ts 41 if (error) drops falsy thrown values and can surface a stale error from an earlier attempt instead of the timeout.
Files Reviewed (3 files)
  • packages/kilo-gateway/src/auth/polling.ts - 2 suggestions
  • packages/kilo-gateway/test/auth/polling.test.ts - no issues
  • .changeset/gateway-poll-transient-errors.md - no issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

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