Repository navigation
fix(agents): keep runtime auth deadline budget in the monotonic domain - #190976
SunnyShu0925 wants to merge 1 commit into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: blocked before merge. What this changesThis PR measures the startup authentication deadline with a monotonic clock while preserving upstream epoch deadlines. Example: A 5-second startup authentication budget encounters a 30-second backward wall-clock correction.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this PR fixes a current startup authentication timeout defect, resolves the prior scope concern, and introduces no identified correctness defect. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherThe embedded runner's auth controller supplies credential lookup and token exchange operations to the deadline helper, which returns their result or aborts authentication when the shared budget expires. flowchart TD
A[Embedded agent runner] --> B[Auth controller]
B --> C[Runtime auth deadline]
D[Monotonic startup budget] --> C
E[Upstream epoch deadline] --> C
C --> F[Credential lookup and exchange]
F --> G[Result or authentication abort]
Technical reviewBest possible solution: Retain the focused monotonic startup-budget repair in the existing deadline owner without changing the upstream epoch contract. Do we have a high-confidence way to reproduce the issue? Current-main source directly shows the seed-to-read wall-clock rollback failure, supported by the contributor's baseline regression output; this read-only review ran no target code. Is this the best way to solve the issue? The change repairs elapsed-time accounting at its existing owner, reuses the shared monotonic clock, and preserves unlimited deadlines, cancellation, and upstream deadline semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9ee326108708. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +13, Tests +66. Total +79 across 2 files. Added test files: 1. View PR surface stats
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 (1 earlier review cycle)
Reviewed November 2, 2026, 4:55 AM ET / 09:55 UTC (Revision 2). |
startupDeadline was seeded from Date.now() and the remaining budget read from Date.now() at each withTimeout call. A backward host clock (NTP correction) between seed and read stretched remainingMs, letting the auth exchange overrun its run deadline budget. Seed the own deadline with monotonicNow() and convert an upstream wall-clock command-queue deadline to the monotonic domain at the boundary (cf. run-wait.ts).
05744d1 to
11b2c8e
Compare
|
@clawsweeper re-review Refreshed for the current head. Changes since the last review:
|
|
🦞👀 Re-review progress:
|
|
Thanks for the work here. We're closing this along with the other open PRs that apply the same change one call site at a time. This series moves individual deadlines to the monotonic clock one at a time; the shared owner is src/shared/monotonic-time.ts, and remaining call sites should be handled together. Please open one issue (or one PR at the shared owner) that covers the whole pattern, with a reproduction of real user-visible harm, instead of separate per-site PRs. Further per-site variants of this pattern will be closed. |
fix: keep five local elapsed-time waits on the monotonic clock Five local waits measured elapsed time with the wall clock, so a clock step (NTP correction, sleep/wake, manual change) ended them early or let them overrun: the exec-approval follow-up wait, the runtime auth deadline, the managed update handoff response wait, and two Windows scheduled-task waits (process exit and settlement). They now use `src/shared/monotonic-time.ts`, passing `monotonicNow` to `scheduleAbsoluteDeadline` where it's used. Epoch values that cross process, RPC or persistence boundaries stay epochs, RPC timeouts stay integers, upstream epoch auth deadlines are untouched, and the handoff `closed` command keeps its helper-owned settlement. No new text. Evidence: full-build CLI with the process-local Date.now stepped by a preload in that process only, main twice and this change twice, plus unstepped controls. Exec-approval follow-up: main ends after about 60 s; this change waits the real ~360 s, the same as unstepped. Runtime auth: a forward step makes main expire after ~367 ms of a ~9.3 s allowance and a backward step makes it overrun to ~12.4 s; this change keeps the allowance and aborts on time. The Windows scheduled-task sites have unit-level proof with a stepped clock, and the handoff wait has source-level proof through a real child pipe. 75 consumer and 55 daemon tests pass; full build and packed smoke pass. CI red is inherited from main (receipt: #199951 (comment)). Receipts: #199951 (comment). Supersedes the closed per-site PRs #181942, #187439, #190976, #195457, #199640 and #199665. Co-authored-by: Ayaan Zaidi <[email protected]>
…199951) fix: keep five local elapsed-time waits on the monotonic clock Five local waits measured elapsed time with the wall clock, so a clock step (NTP correction, sleep/wake, manual change) ended them early or let them overrun: the exec-approval follow-up wait, the runtime auth deadline, the managed update handoff response wait, and two Windows scheduled-task waits (process exit and settlement). They now use `src/shared/monotonic-time.ts`, passing `monotonicNow` to `scheduleAbsoluteDeadline` where it's used. Epoch values that cross process, RPC or persistence boundaries stay epochs, RPC timeouts stay integers, upstream epoch auth deadlines are untouched, and the handoff `closed` command keeps its helper-owned settlement. No new text. Evidence: full-build CLI with the process-local Date.now stepped by a preload in that process only, main twice and this change twice, plus unstepped controls. Exec-approval follow-up: main ends after about 60 s; this change waits the real ~360 s, the same as unstepped. Runtime auth: a forward step makes main expire after ~367 ms of a ~9.3 s allowance and a backward step makes it overrun to ~12.4 s; this change keeps the allowance and aborts on time. The Windows scheduled-task sites have unit-level proof with a stepped clock, and the handoff wait has source-level proof through a real child pipe. 75 consumer and 55 daemon tests pass; full build and packed smoke pass. CI red is inherited from main (receipt: openclaw#199951 (comment)). Receipts: openclaw#199951 (comment). Supersedes the closed per-site PRs openclaw#181942, openclaw#187439, openclaw#190976, openclaw#195457, openclaw#199640 and openclaw#199665. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
When the host clock is corrected backward (NTP resync) between the moment the startup auth budget is seeded and the moment the remaining budget is read, the embedded-agent-runner stretched that budget. The seed and the read both used
Date.now(), while the budget is consumed by a relativesetTimeout. This change seeds the startup budget in the monotonic domain so a backward step can no longer extend it.createRuntimeAuthDeadlineseeded its startup deadline withDate.now() + timeoutMsand read the remaining budget asdeadline.deadlineAtMs - Date.now(). A backward jump between those two reads inflatedremainingMs, so the startup auth exchange received far more than its configuredtimeoutMs.monotonicNow()(frozen at creation) and read each source in its own clock domain — the startup path subtractsmonotonicNow(), the upstream path keeps subtractingDate.now().src/agents/runtime-auth-refresh.ts(seed + per-source read) and a newsrc/agents/runtime-auth-refresh.test.tscovering both paths.Why This Change Was Made
Only the startup deadline is moved into the monotonic domain. It is the budget this helper owns: seed and read both live inside
createRuntimeAuthDeadline, so freezing it at creation removes the seed→read jump entirely. The upstreamgetDeadline()source is a different owner's value — a wall-clock epoch by contract — and this helper does not reseed it. Reading it againstDate.now()is therefore arithmetically unchanged, and a backward correction still stretches that one source. That is an existing upstream limitation, named here rather than claimed as fixed. The two sources are told apart by reference equality (deadline === startupDeadline).monotonicNow() + Math.max(0, deadlineAtMs - Date.now())for both sources) cancels its own twomonotonicNow()reads, so it leaves the startup seed→read stretch exactly as it was while implying protection it does not provide.attempt-async-tasks.tsandattempt-stream-settle.tsand the upstream deadline epoch are untouched; they are separate follow-ups, not regressions introduced here.User Impact
An embedded-agent run no longer waits longer than its configured startup auth budget when the host clock steps backward during a provider authentication exchange. A stalled exchange aborts at
timeoutMsinstead of holding the run slot for the inflated budget.Evidence
1. Real stalled exchange through the shipped runner
A real
openclaw agent --localrun againstmicrosoft-foundrywithapiKey: "__entra_id_dynamic__"performs the provider's realprepareRuntimeAuthV2exchange, withazreplaced by a local script that accepts the call and then never answers (a stalled authentication service).agents.defaults.timeoutSecondsis 8. A preload shim reads each deadline seed on the real clock and rewindsDate.now()by 20s on every later read — a backward NTP step.durationMs=-11828is the rewind itself: the run measures its own duration with theDate.now()the shim moved back, so 20s − 8.17s ≈ 11.8s. The stalled exchange still aborted at its 7997ms budget.2. Same code, pre-fix vs post-fix budget
The real
createRuntimeAuthDeadlinedriven through the realwithTimeout/setTimeoutconsumer, with the same shim and a 5000ms budget:Pre-fix source:
deadlineAtMs: Date.now() + timeoutMsthendeadlineAtMs - Date.now(); the 30s backward step lands entirely inside that difference. Post-fix the seed and the read are the same monotonic clock, so the step is invisible.3. Behavior matrix (budget captured from
setTimeout, 5000ms budget, clock rewound 30s)The second row is the documented upstream limitation: its test pins the bounded-budget contract only, not clock-jump immunity.
4. Unit regression
auth-controller.test.ts(the caller's suite) passes 39/39.Collision check: no open PR touches
src/agents/runtime-auth-refresh.tsorembedded-agent-runner/run/auth-controller.ts;origin/mainstill carries the wall-clock seed bug.