Repository navigation
Description
When a stored OAuth refresh token returns invalid_grant during an interactive API command, accepting automatic reauthorization can fail before the browser opens:
reauth: keychain access: resolve keyring backend: command runtime is required
Verified in v0.47.1 and the callback on current main 82e7fd6. The reauth closure in internal/cmd/root.go passes the HTTP request context into command callbacks. That context need not contain the command runtime or the authclient credential/store/resolver bindings installed on the CLI context. Restoring only the runtime advances the failure to read OAuth client credentials: credentials reader is required.
Reproduction: with an expired/revoked stored OAuth account and an interactive terminal, run an allowed API read such as gog --account you@example.invalid gmail labels get INBOX --json, then accept “Re-authorize now?”. Expected: the existing client/grant reaches browser authorization and retries the read after successful consent. Actual: the callback can fail with missing command dependencies before authorization. A synthetic regression exercises the same callback with a bare request context, fake credentials, and an offline pre-browser guard; it needs no real Google account.
Proposed repair: bind the original command runtime and authclient operations to the incoming request context, preserving its cancellation and values. Keep the stored grant, confirmation, identity validation and token persistence behavior.
Related: #974 introduced native recovery; #1196 concerns doctor recovery hints, and #1260 concerns Ads/default-service passkey prompts. This is a separate callback-dependency failure and does not change service defaults or authentication policy.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Oct 30, 2026
Codex review: this still needs some work.
Summary
Current main still contains the callback dependency defect, and the same-author open fix PR explicitly closes this issue.
Reproducibility: yes. the Gmail label prefetch omits the command context, the transport forwards the request context, and the recovery callback requires missing runtime and credential bindings; no live reproduction was run.
Next step
Review #1278 for dependency restoration and a failing-before regression, keeping this issue open until that fix is resolved.
Security
None.
Review details
Best possible solution:
Restore command dependencies on the incoming request context while retaining cancellation, recorded grants, confirmation, identity validation, and token persistence ownership.
Do we have a high-confidence way to reproduce the issue?
Yes: the Gmail label prefetch omits the command context, the transport forwards the request context, and the recovery callback requires missing runtime and credential bindings; no live reproduction was run.
Is this the best way to solve the issue?
Binding the original dependencies onto the incoming context is a focused repair; replacing that context wholesale would lose cancellation and request values.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning medium; reviewed against 82e7fd6005d4.
Label changes
Label changes:
P2: Automatic recovery fails for expired or revoked stored OAuth grants, with manual authorization available as a workaround.impact:auth-provider: Missing command dependencies prevent Google OAuth reauthorization before browser consent.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:linked-pr-open: Current issue advisory state selects this label.clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.Label justifications:
P2: Automatic recovery fails for expired or revoked stored OAuth grants, with manual authorization available as a workaround.impact:auth-provider: Missing command dependencies prevent Google OAuth reauthorization before browser consent.Evidence reviewed
What I checked:
internal/cmd/root.go:298, 82e7fd6005d4)internal/cmd/gmail_labels.go:390, 82e7fd6005d4)internal/cmd/auth.go:93, 82e7fd6005d4)internal/cmd/root.go:298, 229da12809c1)internal/googleapi/reauth_glue_test.go:36, 82e7fd6005d4)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.Reviewed October 30, 2026, 3:06 PM ET / 19:06 UTC.
fix(auth): retain command dependencies during automatic reauthorization
steipete commentedon Nov 5, 2026
Landed in #1278 as ebe74f2. The automatic reauthorization callback restores the command runtime and OAuth client dependencies on the incoming context, preserving cancellation, the selected client, and stored services/scopes.
The synthetic regression reproduces the old missing-runtime failure and verifies the restored dependencies and grant. Existing transport tests prove retry with the refreshed token. Full
make ci, independent P0–P2 review, and all exact-head CI checks passed: https://github.com/openclaw/gogcli/actions/runs/42082522973. No live consent run happened. Thanks @TheAngryPit; contributor credit is retained in the squash commit.fix(auth): retain command dependencies during automatic reauthorization