Skip to content

fix(agents): agent runs hang when a provider auth step never returns - #93952

Closed
amittell wants to merge 9 commits into
openclaw:mainfrom
amittell:fix/auth-refresh-deadline-guard
Closed

amittell wants to merge 9 commits into
openclaw:mainfrom
amittell:fix/auth-refresh-deadline-guard

Conversation

@amittell

@amittell amittell commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Related: #141477, #143588

What Problem This Solves

An embedded agent run can hang indefinitely when credential resolution or a provider's prepareRuntimeAuth exchange 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 parent 3cd9bddb36d93d43b50595dfd0d5b18a4478a0c9 (tree fc84a6dc017f0c9bc5449115798afb40348579c9) on macOS arm64 with Node 24.22.1 and pnpm 12.15.0: pnpm install --frozen-lockfile, then node --import ./scripts/tsx.mjs scripts/build-all.mts qaRuntime. Both exited 0. dist/entry.js SHA256 is 49ecb6dcdb303775c003a27e500291e4d09bcda423a8b5f893e3087661fbf419 for the head and af6911c7dba6fd52ebf145b72f91b6e093ebd26cbdf077b491e06beb2c8d6be6 for 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 with node openclaw.mjs agent --agent main --session-id <id> --message ... --json --timeout 1800. Two api-key profiles were saved with openclaw models auth paste-api-key using synthetic keys.

The provider is a small local plugin loaded through plugins.load.paths, the same shape as the qa-lab worker-inference-generation-provider fixture. Its prepareRuntimeAuth makes a real HTTP token exchange to a loopback server with node:http and no client timeout, and returns the runtime key and expiresAt it 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 of scripts/e2e/mock-openai-server.mjs logs which runtime key each model request carries. A proof_wait tool 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.

17:41:02.025Z  exchange 1 answered: rt-1-primary, ttl 60 s
17:41:07.768Z  exchange 2 requested by the scheduled refresh; server holds the response
17:41:49.689Z  model request 1, Authorization rt-1-primary -> mock returns a proof_wait call
17:52:47.796Z  gateway: Runtime auth refresh failed for stallauth: Runtime auth exchange for stallauth timed out after 700000ms
17:53:47.818Z  exchange 3 requested by the scheduled retry -> rt-3-primary, ttl 3600 s
17:53:50.924Z  exchange 2 answered after 763.1 s: rt-2-primary-LATE (the plugin hook receives it at 17:53:50.925Z)
17:53:57.462Z  model request 2 (after proof_wait returned), Authorization rt-3-primary
17:54:04Z      openclaw agent exit 0: "status": "ok", reply PROOF-93952-B-DONE; 2 model requests in total

The deadline fired 700.03 s after exchange 2 started and the retry ran 60.02 s later. The late rt-2-primary-LATE reached the hook 3.0 s after rt-3-primary was in place, and the next model request, 6.5 s after that, still carried rt-3-primary.

Control on main 3cd9bddb36d9, same script: exchange 2 started at 18:21:55.794Z, no Runtime auth refresh failed line 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, with rt-2-primary-LATE; main published it and model request 2 at 18:35:40.790Z carried rt-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.

17:18:44.216Z  exchange 1 answered: rt-1-backup, ttl 60 s   (this run's first profile)
17:18:53.732Z  exchange 2 requested by the scheduled refresh; server holds the response
17:20:12.068Z  model request 1 -> status=401; the auth-error refresh joins exchange 2
17:20:50Z ...  stalled session: ... classification=stalled_agent_run ... recovery=none   (every 30 s)
17:24:50.051Z  stuck session recovery outcome: status=failed action=none ... Watchdog cleanup blocked: exact owner retains write-capable work
17:30:33.741Z  Runtime auth refresh failed for stallauth: Runtime auth exchange for stallauth timed out after 700000ms
17:30:34.236Z  embedded run failover decision: ... decision=surface_error reason=auth attempt=1 retry=0 rotations=0
17:30:34.474Z  lane task error: lane=main durationMs=714243 error="Couldn't sign in to the AI service. ..." errorName=FailoverError
17:30:41Z      openclaw agent exit 1

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=AbortError followed 0.05 s later.

One earlier head attempt is excluded: its driver probed /health instead of /readyz, and openclaw agent failed with gateway timeout after 10000ms before 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, ec9ef19962244843fb4f0afae5fde2998f951b50 has 154 check runs: 70 successful, 83 skipped, 1 neutral (CodeQL), none failed. CI run 39798925803 executed merge 01d9455a98b4da685d667a5851ca1fb0c12966e5 with base 74ca496bf40e1e702e824aa597620b9e1798efab. In changed-test job 119894750645, auth-controller.deadline.test.ts passed 5/5 (cold-start timeout, shared refresh waiters, late-result rejection, profile rotation, durable OAuth settlement) and the adjacent auth-controller.test.ts 31/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...HEAD passed, and git merge-tree --write-tree HEAD 2e7668b2eaad12171ef4421b68286de6063b7e77 produced clean tree b2300c3b10df17be5ecc52a61b3ee6c0bfbefcb3.

Historical negative controls, measured on e282c0c20c1 and 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-review and openclaw/ci-gate still read "A maintainer must approve the current PR revision". Current-head security approval remains with a maintainer; no approval or gate bypass is claimed.

@amittell
amittell requested a review from a team as a code owner June 17, 2026 05:24
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 17, 2026
@clawsweeper

clawsweeper Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This 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.

  • Before: Refresh waiters remain blocked until the exchange answers.
  • After: The wait ends after 700 seconds, the scheduled retry recovers, and a late exchange result cannot replace the recovered key.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair supported by shipped Gateway traces and distinct regression coverage; enforced security approval remains separate from patch readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The pinned head was exercised on macOS through Gateway and openclaw agent using a provider plugin with a real loopback HTTP client: a held exchange timed out, scheduled recovery installed a new key, a late response left that key intact, and a joining auth-error waiter exited; this resolves the previous transport-proof request without claiming external-provider coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A provider auth step that never returns leaves an agent run and subsequent session work waiting indefinitely.
Reason: A bounded failure restores existing recovery without new configuration, persistence, public APIs or competing ownership.

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
Reviewed head: ec9ef19962244843fb4f0afae5fde2998f951b50

Before merge

  • Await maintainer action - Review the credential-boundary changes at ec9ef19 and, if approved, issue the enforced /allow-security-sensitive-change approval.

Findings

None.

Tests

  • Missing end-to-end proof: Credential-resolution stalls have controller-test coverage rather than separate Gateway evidence; the supplied Gateway runs exercise runtime-exchange recovery and late-result rejection.
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Embedded auth preparation and credential resolution changes intended behavior with a stated reason (8f64807: History traces preparation through helper deduplication and later controller refactors; the patch preserves their inputs, credential protection and publication order while explaining the new observation bound. Some older blob inspection encountered the checkout's lazy-fetch limit.)
  • Stale runtime refresh protection keeps the original intent (b9ddfa6: The earlier repair rejected stale refresh completions after profile changes; the new timeout rejects before publication and retains the existing active-state check.)
  • Durable OAuth settlement keeps the original intent (fix(auth): fence shared OAuth refresh generations #141477: Caller deadlines observe refresh owners without canceling durable settlement; the patch explicitly preserves that distinction and tests eventual adoption.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +20, Tests +345. Total +365 across 4 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 47 27 +20
Tests 2 345 0 +345
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 392 27 +365

Review metrics

Metric Value Why it matters
Production versus test growth Production +47/-27; tests and routing +345/-0 The production change reuses the existing timeout helper; the tests protect distinct cold-start, shared-waiter, late-result, profile-rotation and durable-settlement failures.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: A stalled provider auth operation can indefinitely block an active agent run, its refresh waiters and later session turns.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (50 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-18T18:01:56.077Z sha 04fe642fb7c45d6a057de28e9256243aeab57953 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-18T19:13:06.561Z sha 04fe642fb7c45d6a057de28e9256243aeab57953 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-23T09:46:24.436Z sha f3bc6e3b75bd8b9686224b082f806f29362b2006 :: needs real behavior proof before merge. :: [P3] Await durable settlement instead of polling real time
  • reviewed 2026-09-23T17:23:43.346Z sha c14caeb :: needs real behavior proof before merge. :: [P3] Await durable settlement instead of polling real time
  • reviewed 2026-10-09T22:32:57.599Z sha e282c0c :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T16:33:41.777Z sha 67f54f3 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-20T19:28:34.517Z sha 0040dff :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-25T18:51:46.959Z sha ec9ef19 :: needs real behavior proof before merge. :: none

Reviewed October 27, 2026, 3:37 PM ET / 19:37 UTC (Revision 51).

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 17, 2026
amittell added a commit to amittell/openclaw that referenced this pull request Jun 22, 2026
amittell added a commit to amittell/openclaw that referenced this pull request Jul 2, 2026
…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)
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 7, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 7, 2026
@amittell
amittell force-pushed the fix/auth-refresh-deadline-guard branch from 276c0e7 to ff8c5fe Compare July 8, 2026 04:31
Copilot AI review requested due to automatic review settings July 8, 2026 04:31
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 8, 2026
@amittell

amittell commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (22376d8) and refreshed the PR body. New head: ff8c5fea5a3700fcaff387ca66b7959ce148d8da.

Rebase notes:

  • The only conflict was src/agents/auth-profiles/oauth-manager.ts. Resolved by keeping main's current doRefreshOAuthTokenWithLock body — the KeyedAsyncQueue refresh queue from refactor: consolidate exact keyed async queues #99691, the refresh-contention classification from fix(auth): clean OAuth contention diagnostics #101573, and readBootstrapCredential({ store, ... }) (src/agents/auth-profiles/oauth-manager.ts:559) — and re-applying only the OAUTH_REFRESH_INLOCK_TIMEOUT_MS whole-section wrap (src/agents/auth-profiles/oauth-manager.ts:494, constant + invariant at src/agents/auth-profiles/constants.ts:60).
  • The other six files auto-merged cleanly; the withRuntimeAuthRefreshDeadline design is unchanged (src/agents/runtime-auth-refresh.ts, shared withAuthDeadline at src/agents/embedded-agent-runner/run/auth-controller.ts:148 covering refresh, credential resolution, and cold-start boundaries).
  • src/agents/auth-profiles/constants.ts was normalized with oxfmt since this PR touches it (one export statement collapse that predated this PR).

Verification at the new head: node scripts/run-vitest.mjs run src/agents/runtime-auth-refresh.test.ts src/agents/embedded-agent-runner/run/auth-controller.test.ts src/agents/auth-profiles/oauth-manager.test.ts — 3 files, 39 tests passed, including the tests added on main by #99134/#101573. Nine sibling oauth lock/queue/refresh test files also pass. tsgo core lane exits 0; oxlint and oxfmt --check clean on all seven changed files.

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.

@amittell

amittell commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Copilot AI left a comment

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.

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() and RUNTIME_AUTH_REFRESH_HARD_TIMEOUT_MS to 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 ensure refreshInFlight is 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.

Comment thread src/agents/runtime-auth-refresh.ts Resolved
Comment thread src/agents/runtime-auth-refresh.test.ts Resolved
Comment thread src/agents/runtime-auth-refresh.ts Resolved
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jul 8, 2026
@amittell

amittell commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the Copilot review nits in df08d00d4ebfcd7a3da2e43432c866872b4efd98:

  • src/agents/runtime-auth-refresh.ts — reworded the hard-timeout comment from "sits above" to "covers at least", matching the >= invariant (constant unchanged at 300s = 120s + 180s).
  • src/agents/runtime-auth-refresh.test.ts — test name now says "at or above the OAuth manager call + stale-lock budget", aligned with the toBeGreaterThanOrEqual assertion.
  • src/agents/embedded-agent-runner/run/auth-controller.ts — removed the #88xx placeholder ref; the comment now states the incident context in plain words.
  • src/agents/runtime-auth-refresh.ts — generalized the deadline error to "Runtime auth operation for ..." since the helper also wraps cold-start credential resolution and runtime auth prep, and updated the helper doc comment plus the test asserting the exact message.

Wording-only change (comments, test names, one error-message string plus its matching test expectation). Locally verified: node scripts/run-vitest.mjs run src/agents/runtime-auth-refresh.test.ts src/agents/embedded-agent-runner/run/auth-controller.test.ts — 18/18 passed. CI validates the full suite on the new head.

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 8, 2026
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.
@amittell

amittell commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged main (6b2afbfe981) into the branch, GitHub had it CONFLICTING, and closed the P3. Three commits on top of c14caebfb53, no rebase:

  • 06e15e65b1d merge. One conflict, in auth-controller.ts: refactor(agents): deslop runners, harness and recovery #157294 (281967681fd) inlined resolveApiKeyForCandidate into applyApiKeyInfo, so the credential-resolution deadline now wraps that inlined getApiKeyForModelCore call. The 700 s budget still holds against main's constants: 20 lock retries x 10 s + 120 s per attempt, two attempts, plus 60 s.
  • 2a344b9d58c routes auth-controller.deadline.test.ts through the forked database cohort. On main the OAuth manager persists through the shared-state SQLite broker, which threads don't host. 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 sat on providerStarted until Test timed out in 120000ms. One registry line, as c8283bcc86c did for the Gateway tool suite. No assertion changes.
  • e282c0c20c1 is the P3 ("Await durable settlement instead of polling real time"). The durable-owner case now starts the run inside an AsyncWorkScope, drains it after the provider answers, and asserts the rotated row once. The vi.waitFor is gone.

Measured at e282c0c20c1 on an M4 Pro:

auth-controller.deadline.test.ts                       5 passed
auth-controller.test.ts                               23 passed
test/scripts/database-worker-registry.test.ts         12 passed
auth-controller.ts reverted to main                    3 failed, 2 passed
drain removed from the durable-owner case              1 failed, 4 passed
routing entry removed                                  1 failed, 4 passed
check:changed --base 6b2afbfe981                       all gates pass

With auth-controller.ts reverted the cold-start exchange fails expected false to be true, and the refresh-waiter and credential-resolution cases fail expected { settled: false } to deeply equal { settled: true, ... }: nothing settles at the limit. With the drain removed the row assertion fails (expected { type: 'oauth', …(4) } to match object { …(2) }), so the scope is what the test waits on. With the routing entry removed the durable-owner case times out at 120000 ms. The older vi.waitFor version also passes 5/5 once routed, so the timeout was the routing and the P3 is a separate change.

Test cost: pnpm test src/agents/embedded-agent-runner/run/auth-controller.deadline.test.ts --maxWorkers=1, 5 tests, 8.7 s Vitest duration, 16.9 s wall. The durable-owner case takes about 950 ms, the other four under 200 ms each. No CI seconds yet at this head.

The red jobs at c14caebfb53 (run of 2026-09-23 15:18 UTC) were all in files this PR doesn't touch, and all pass on main 6b2afbfe981 and on the merged head:

                                                           main 6b2afbfe981   e282c0c20c1
check-test-types-core-4   TS2741, session-row-placement-
                          projection.lifecycle.test.ts     0 errors           0 errors
compact-large-30          subagent-registry.test.ts        102 passed         102 passed
compact-large-31          subagent-registry.timing.test.ts 1 passed           1 passed
compact-large-25          server.sessions.list-explicit-
                          ownership.test.ts                7 passed           7 passed

The type error came in with #156221 (f6a3ed707c2, 15:14 UTC) and 09012603235 fixed it on main at 15:52 UTC; the run started in between. Main reworked those registry tests later the same day (#156685 "await completion after requester disposal", 1f067fa03de "join owned cleanup before fixture assertions"). The canceled dispatch check is the ClawSweeper dispatch job from the 17:08 UTC body edit: both dispatch steps succeeded (Dispatched ClawSweeper review.), the job was canceled in its post steps, and revision 46 reviewed this head at 17:23 UTC.

Still open, and not mine to close:

  • openclaw/security-sensitive-review needs a maintainer's /allow-security-sensitive-change on the new head.
  • No run through a real provider transport. The evidence above is mocked hooks, fake timers and a real OAuth manager on real SQLite.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

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.
@amittell

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The only change since the reviewed head 67f54f36254b is 0040dffdaeb9, a merge of upstream main. Its first parent is the reviewed head, so this PR's own changes are the same 4 files.

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

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.

Copy link
Copy Markdown
Contributor Author

Following up on the October 20 review: ec9ef19962244843fb4f0afae5fde2998f951b50 repairs the stale OAuth test seam. The fixture now calls the no-argument OAuth manager, mocks provider operations at the supported seam, and reports an early initialization failure instead of waiting for a provider that never starts.

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 01d9455a98b4da685d667a5851ca1fb0c12966e5, combining this source head with base 74ca496bf40e1e702e824aa597620b9e1798efab.

The requested real-transport recovery proof is still open. A bounded local loopback attempt stopped before collection because the available dependency tree lacked @solidjs/vite-plugin; it produced no behavior evidence. I updated the description to distinguish current CI results, historical negative controls, and that remaining proof gap. The separate security-review and aggregate gate statuses also remain failed, with current-head security approval reserved for a maintainer.

@amittell

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The CI item from the October 20 review is cleared at ec9ef19962244843fb4f0afae5fde2998f951b50: 70 check runs pass, 67 are skipped and CodeQL is neutral. In checks-node-changed-2, auth-controller.deadline.test.ts passes 5/5 and auth-controller.test.ts 31/31, and check-test-types-core-2 passes. The two red commit statuses are openclaw/security-sensitive-review and openclaw/ci-gate, both reading "A maintainer must approve the current PR revision".

The real-transport recovery proof is still open and is not claimed here.

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@amittell

Copy link
Copy Markdown
Contributor Author

The shipped Gateway proof is now in the description. I built ec9ef1996224 and its main parent 3cd9bddb36d9 and drove a loopback Gateway from each with openclaw agent. A local provider plugin's prepareRuntimeAuth does a real HTTP token exchange; the second exchange, the scheduled refresh, is held open.

  • Head: Runtime auth exchange for stallauth timed out after 700000ms fired 700.03 s after the held exchange started. The scheduled retry ran 60.02 s later and got rt-3-primary. The held exchange then answered with rt-2-primary-LATE (763.1 s), and the next model request 6.5 s later still carried rt-3-primary. The turn finished ok with 2 model requests.
  • Main, same script: no timeout line and no retry. When the harness answered the held exchange at 820 s, main adopted rt-2-primary-LATE and used it on the next request.
  • With a 401 that joins the held refresh, the head released the waiter at 700.01 s and ended the lane 0.73 s later with a named auth failure. Main logged a failed stuck-session recovery and ended only when the exchange answered at 780 s. That head run took the failure path rather than rotating to the second saved profile; the description says so.

Not covered: the credential-resolution deadline, and a real provider's transport.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-review-required security-sensitive-changed size: M status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants