Repository navigation
Conversation
|
Codex review: blocked before merge. What this changesThis PR limits embedded-run credential resolution and runtime auth exchanges to 700 seconds while preserving background OAuth settlement. Example: The stallauth provider's scheduled token exchange stops responding.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains This PR fixes a remaining unbounded auth wait on main without introducing a separate auth owner; no actionable code findings remain. Priority: P1 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe embedded-run auth controller resolves a selected profile, exchanges provider credentials, installs runtime auth, and coordinates refresh and profile recovery. flowchart TD
A[Embedded agent run] --> B[Auth controller]
B --> C[Credential resolution]
C --> D[Durable OAuth owner]
B --> E[Provider runtime exchange]
E --> F[Runtime credential installation]
B --> G[Timeout and existing recovery]
Technical reviewBest possible solution: Retain the focused controller deadlines and existing durable OAuth owner, then complete the enforced security approval. Do we have a high-confidence way to reproduce the issue? Current main exposes the unbounded awaits, and the supplied Gateway control reproduces the stalled refresh on the pinned base; no target code was executed during this review. Is this the best way to solve the issue? Bounding observation immediately around the existing awaits is the smallest complete repair for this embedded-run failure and prevents late results from reaching controller publication. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d45ff6de6c48. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +20, Tests +345. Total +365 across 4 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (50 earlier review cycles; latest 8 shown)
Reviewed October 27, 2026, 3:37 PM ET / 19:37 UTC (Revision 51). |
…penclaw#93952 oauth-manager part) Port of the oauth-manager half of PR openclaw#93952 head (276c0e7fff). 6.11 already carries the runtime-auth-refresh + auth-controller halves (378c76e) and declares OAUTH_REFRESH_INLOCK_TIMEOUT_MS but never used it; this wires the held-lock critical section (keychain load + buildApiKey + network refresh) through withRefreshCallTimeout so a wedged in-lock op cannot pin the cross-agent lock. 6.11 blobs matched the PR base exactly, so the diff applied byte-clean. (ported from PR openclaw#93952 head 276c0e7fff, delta 73e6c4730b..276c0e7fff)
276c0e7 to
ff8c5fe
Compare
|
Rebased onto current Rebase notes:
Verification at the new head: The PR body now includes the required What Problem This Solves, Evidence, and Real behavior proof sections; evidence includes the scoped test runs above and the fork production soak on mac-mini.lan and rh-bot.lan since 2026-06 with no recurrence of the auth-refresh freeze. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
There was a problem hiding this comment.
Pull request overview
This PR prevents long-running agent lanes from deadlocking indefinitely when runtime auth work (OAuth refresh, keychain access, provider auth hooks, or cross-agent lock waits) never settles. It introduces hard deadlines around all auth boundaries that can block, ensuring the single-flight in-flight handle always clears and waiters unblock with an error instead of hanging forever.
Changes:
- Add
withRuntimeAuthRefreshDeadline()andRUNTIME_AUTH_REFRESH_HARD_TIMEOUT_MSto hard-timeout a single runtime auth operation. - Apply the hard deadline consistently across refresh and cold-start/profile-rotation auth boundaries in
auth-controller.ts, and ensurerefreshInFlightis cleared based on identity rather than generation gating. - Bound the entire OAuth “held-lock” critical section (not just the network call) with
OAUTH_REFRESH_INLOCK_TIMEOUT_MS, plus add invariant tests for timeout ordering.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/agents/runtime-auth-refresh.ts | Introduces a hard-deadline wrapper and default hard timeout for runtime auth operations. |
| src/agents/runtime-auth-refresh.test.ts | Adds unit tests covering timeout/rejection/propagation semantics and the default timeout budget invariant. |
| src/agents/embedded-agent-runner/run/auth-controller.ts | Applies the hard deadline at refresh + cold-start/profile-rotation auth boundaries and adjusts in-flight clearing logic. |
| src/agents/embedded-agent-runner/run/auth-controller.test.ts | Adds regressions ensuring hung provider auth cannot permanently wedge the lane (refresh + cold-start). |
| src/agents/auth-profiles/oauth-manager.ts | Wraps the entire held-lock OAuth refresh critical section with an in-lock timeout budget. |
| src/agents/auth-profiles/oauth-manager.test.ts | Adds invariant coverage for call-timeout < in-lock-timeout < stale-window. |
| src/agents/auth-profiles/constants.ts | Adds OAUTH_REFRESH_INLOCK_TIMEOUT_MS and documents the timeout ordering invariants. |
|
Addressed the Copilot review nits in df08d00d4ebfcd7a3da2e43432c866872b4efd98:
Wording-only change (comments, test names, one error-message string plus its matching test expectation). Locally verified: |
Drive a real OAuth manager and SQLite state through the embedded-run auth controller while the provider refresh hangs. The owner's own 120s observation deadline releases the run first, the stored row stays a pending refresh fence, and once the provider answers the owner settles the rotated credential durably. A new run then adopts it without a second provider refresh, and the timed-out run never receives it. This also pins the budget order: if the controller deadline dropped below the owner's observation deadline, the run would surface the controller timeout instead and the test fails.
Brings the branch onto current main; GitHub reported it CONFLICTING. One conflict, in auth-controller.ts: openclaw#157294 (2819676) inlined resolveApiKeyForCandidate into applyApiKeyInfo. The credential-resolution deadline now wraps that inlined getApiKeyForModelCore call; the label still names the model whose provider is being resolved. The 700 s budget still holds against main's owner constants: OAUTH_REFRESH_LOCK_OPTIONS 20 retries x 10 s and OAUTH_REFRESH_CALL_TIMEOUT_MS 120 s, so 2 x 320 s + 60 s.
On main the OAuth manager persists through the shared-state SQLite worker broker, which only the forked database cohort hosts. In the thread cohort the durable-owner case never reached its provider: resolveOAuthAccess rejected with "Shared-state admission requires the host broker", and the test then waited on providerStarted until its 120 s timeout. Route the file through test/vitest/vitest.database-worker-core-paths.mjs, as c8283bc did for the Gateway tool suite. No assertion changes.
The durable-owner case restored real timers and polled the SQLite row with vi.waitFor. The owner already tracks its settlement through trackAsyncWork, so the test now starts the run inside an AsyncWorkScope, drains that scope after the provider answers, and asserts the rotated row once. With the drain removed the row assertion fails, so the scope is what the test waits on.
|
Merged
Measured at With Test cost: The red jobs at The type error came in with #156221 ( Still open, and not mine to close:
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
auth-controller.ts prepareRuntimeAuthForModel: keep main's authProfileBinding revalidate/assertCurrent before the exchange and its raw apiKey (main now unwraps sentinels inside prepareProviderRuntimeAuth); the runtime auth exchange deadline wraps that call. auth-controller.ts applyApiKeyInfo: keep main's forceRefresh parameter and lockedProfile rule; the credential-resolution deadline wraps that getApiKeyForModelCore call.
|
@clawsweeper re-review The only change since the reviewed head |
|
🦞👀 Re-review progress:
|
…uth provider seam openclaw#177676 made createOAuthManager take no adapter; provider I/O now goes through oauth-provider-operations. The durable-owner case still passed an adapter, so tsgo reported TS2554/TS7006 and at runtime the synthetic refresh never ran: the case waited on providerStarted until Vitest's 120000 ms limit (CI run 39457916748, checks-node-changed-1 and check-test-types-core-2). The case now installs the refresh through mockOAuthProviderOperations, restores those spies after each case, and races provider start against the run so a run that settles first fails with its own error instead of a test timeout.
|
Following up on the October 20 review: I checked the actual CI logs: the deadline suite passes 5/5 and the adjacent controller suite 31/31, and the affected typecheck passes. That run tested merge The requested real-transport recovery proof is still open. A bounded local loopback attempt stopped before collection because the available dependency tree lacked |
|
@clawsweeper re-review The CI item from the October 20 review is cleared at The real-transport recovery proof is still open and is not claimed here. |
|
🦞👀 Re-review progress:
|
|
The shipped Gateway proof is now in the description. I built
Not covered: the credential-resolution deadline, and a real provider's transport. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Thanks @amittell for identifying this hang and providing the Gateway evidence. A credited replacement is now merged in #189144 (7bd53ff28f69), using the existing run deadline and cancellation signal while preserving provider abort recovery. Closing this as superseded; your co-author credit is preserved in the landed commit. |
Related: #141477, #143588
What Problem This Solves
An embedded agent run can hang indefinitely when credential resolution or a provider's
prepareRuntimeAuthexchange never returns. Refresh waiters in that run and later turns in its session then wait behind it.User Impact
A stalled auth step stops blocking the caller after 700 seconds with a named credential-resolution or runtime-auth-exchange error. The existing profile rotation, model fallback, or failure path can continue. Scheduled refresh retains its existing 60-second retry. OAuth's own 120-second observation deadline still reports first.
Why This Change Was Made
The existing auth controller now wraps its two unbounded awaits with
withTimeout. Timing out stops the caller waiting; it does not cancel the provider operation or durable OAuth settlement. Runtime-state publication follows the bounded await, so a late exchange result cannot overwrite recovered credentials.The 700-second budget covers two OAuth manager attempts, each allowing 20 lock retries of at most 10 seconds plus 120 seconds observing the refresh owner, with 60 seconds of headroom.
The earlier OAuth-ownership and native-Codex-login changes were removed. Main owns those decisions through #141477, #143588 and #114397. The scope reduction explains why they stay out of this patch.
Evidence
Current source head:
ec9ef19962244843fb4f0afae5fde2998f951b50.Shipped Gateway proof, October 26
I built the head (tree
8a87962e0a77dedd18bb1cc46d2d92fdd7717e05) and its main parent3cd9bddb36d93d43b50595dfd0d5b18a4478a0c9(treefc84a6dc017f0c9bc5449115798afb40348579c9) on macOS arm64 with Node 24.22.1 and pnpm 12.15.0:pnpm install --frozen-lockfile, thennode --import ./scripts/tsx.mjs scripts/build-all.mts qaRuntime. Both exited 0.dist/entry.jsSHA256 is49ecb6dcdb303775c003a27e500291e4d09bcda423a8b5f893e3087661fbf419for the head andaf6911c7dba6fd52ebf145b72f91b6e093ebd26cbdf077b491e06beb2c8d6be6for main. Tracked source was unchanged before each run.Each run used a fresh HOME, state and config, a loopback Gateway started with
node openclaw.mjs gateway run --bind loopback --allow-unconfigured, and one turn sent withnode openclaw.mjs agent --agent main --session-id <id> --message ... --json --timeout 1800. Two api-key profiles were saved withopenclaw models auth paste-api-keyusing synthetic keys.The provider is a small local plugin loaded through
plugins.load.paths, the same shape as the qa-labworker-inference-generation-providerfixture. ItsprepareRuntimeAuthmakes a real HTTP token exchange to a loopback server withnode:httpand no client timeout, and returns the runtime key andexpiresAtit gets back. The exchange server answers exchange 1 with a 60-second key, holds exchange 2 open (the injected stall), and answers later exchanges with 1-hour keys. A recording proxy in front ofscripts/e2e/mock-openai-server.mjslogs which runtime key each model request carries. Aproof_waittool from the same plugin keeps the run alive while the stall plays out. The keys (rt-<exchange>-<profile>) are fixture labels, not credentials, and no real provider or remote endpoint was involved.Scheduled refresh stalls, the deadline releases it, the retry recovers, the late result arrives after recovery (head). The first key expires inside the refresh margin, so the scheduled refresh starts 5 s after it and its exchange is the one held.
The deadline fired 700.03 s after exchange 2 started and the retry ran 60.02 s later. The late
rt-2-primary-LATEreached the hook 3.0 s afterrt-3-primarywas in place, and the next model request, 6.5 s after that, still carriedrt-3-primary.Control on main
3cd9bddb36d9, same script: exchange 2 started at 18:21:55.794Z, noRuntime auth refresh failedline was logged (0 matches in the Gateway log, 1 in the head run), and no retry exchange ran. The harness answered exchange 2 after 820 s, at 18:35:35.830Z, withrt-2-primary-LATE; main published it and model request 2 at 18:35:40.790Z carriedrt-2-primary-LATE. Main only recovers when the stalled exchange answers.An auth-error waiter joins the stalled refresh (head). Same plugin and stall; the first model request gets a scripted 401.
The waiter was released 700.01 s after exchange 2 started and the lane ended 0.73 s later with a named auth failure. This run took the failure path; it did not rotate to the second saved profile, and I have not established why. Exchange 2 was answered at 17:31:53.808Z, after the driver had already sent the Gateway SIGTERM, and no further model request was made (1 in total).
Control on main, same script: the 401 joined exchange 2 (started 18:41:45.982Z), the same stuck-session recovery failure was logged at 18:47:40.029Z, and no deadline line appeared at 700 s. The run ended only when the harness answered exchange 2 at 18:54:46.206Z, after 780 s:
lane task error: lane=main durationMs=789103 error="Reply operation stalled" errorName=AbortErrorfollowed 0.05 s later.One earlier head attempt is excluded: its driver probed
/healthinstead of/readyz, andopenclaw agentfailed withgateway timeout after 10000msbefore any turn started.What these runs do not cover: the credential-resolution deadline around
getApiKeyForModelCore(only the runtime auth exchange was stalled here), a real provider's transport, and a stall longer than 780 to 820 s on main.CI
At 18:57Z on October 26,
ec9ef19962244843fb4f0afae5fde2998f951b50has 154 check runs: 70 successful, 83 skipped, 1 neutral (CodeQL), none failed. CI run 39798925803 executed merge01d9455a98b4da685d667a5851ca1fb0c12966e5with base74ca496bf40e1e702e824aa597620b9e1798efab. In changed-test job 119894750645,auth-controller.deadline.test.tspassed 5/5 (cold-start timeout, shared refresh waiters, late-result rejection, profile rotation, durable OAuth settlement) and the adjacentauth-controller.test.ts31/31. Changed-test job 119894750760 passed the database-worker registry suite 11/11, and core-test typecheck job 119895491762 succeeded.Local source-only checks on October 24:
git diff --check upstream/main...HEADpassed, andgit merge-tree --write-tree HEAD 2e7668b2eaad12171ef4421b68286de6063b7e77produced clean treeb2300c3b10df17be5ecc52a61b3ee6c0bfbefcb3.Historical negative controls, measured on
e282c0c20c1and not rerun at the current head: reverting the controller to its base made the cold-start, refresh-waiter and credential-resolution cases fail (3 failed, 2 passed). Removing the durable-settlement drain failed the row assertion; removing database-cohort routing timed out the OAuth case. Commands and results.The commit statuses
openclaw/security-sensitive-reviewandopenclaw/ci-gatestill read "A maintainer must approve the current PR revision". Current-head security approval remains with a maintainer; no approval or gate bypass is claimed.