Repository navigation
fix(subagents): keep the subagent spawn reconcile budget on the monotonic clock - #186412
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: needs maintainer review before merge. What this changesMeasures the subagent spawn reconciliation deadline with performance.now() so wall-clock changes cannot distort its retry budget. Example: The host clock jumps forward 10 seconds while a pending subagent launch is being reconciled.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current reconciliation-budget bug with a focused change; the prior findings are resolved, and no introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherNative and ACP subagent launches share a Gateway dispatch owner that reconciles ambiguous transport failures using the original idempotency key and returns settled acceptance or an error. flowchart TD
A[Native or ACP spawn] --> B[Shared Gateway dispatch]
B --> C[Gateway agent RPC]
C --> D[Ambiguous transport failure]
D --> E[Monotonic reconciliation budget]
E --> C
C --> F[Accepted run or terminal error]
Technical reviewBest possible solution: Use the monotonic clock for every read of the existing in-process reconciliation budget, as this PR does. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the failure directly, and the contributor supplies matching base-failing regression output and a real-WebSocket before/after trace; no target code was executed during this review. Is this the best way to solve the issue? This is the smallest complete fix: keep elapsed-time accounting in the existing shared reconciliation owner without adding state, abstractions, or policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d3184ac52b6a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests 0. Total +4 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel 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 October 27, 2026, 10:53 PM ET / October 28, 2026, 02:53 UTC (Revision 2). |
…onic clock reconcileSubagentAgentDispatch anchored its reconciliation deadline and the remaining-budget reads to Date.now() (wall clock), then fed the result into two monotonic consumers: the Gateway RPC timeout (callGateway timeoutMs) and the inter-iteration delay (node:timers/promises setTimeout). A wall-clock step (NTP sync) landing between two loop iterations distorts remainingMs: a forward step shrinks it below zero and prematurely kills a healthy reconciliation, while a backward step stretches the Gateway timeout and the delay well past the intended budget. The deadline is a pure in-process closure variable (never serialized, persisted, or reported across processes), so it is safe to anchor to performance.now(). All three reads now use the monotonic clock, keeping the budget stable across wall steps. The regression folds into the existing ambiguous-dispatch reconcile case: its pending replay steps Date.now() forward 10s and the case still requires the admitted run plus the 800ms per-call Gateway RPC cap, so the suite keeps its real 800ms interval wait and adds no test lines.
d3dd3da to
b8c6156
Compare
|
@clawsweeper re-review Addressing the three before-merge items from the last review on the same head:
The production change is unchanged from the reviewed head: the three budget reads in |
|
🦞👀 Re-review progress:
|
|
Closing: this change has been absorbed into maintainer PR #186484 (monotonic deadlines cutover). My original commit is preserved there with credit. Thanks! |
fix: measure deadlines and budgets on one monotonic clock owner Many deadline, budget and timeout calculations used Date.now(), so a wall-clock step (NTP correction, VM resume, manual change) made them expire early or run long. Contributors had been fixing these one call site at a time. Core now has one owner, src/shared/monotonic-time.ts, for process-local deadlines and elapsed time, replacing the supervisor-local helper and the per-site variants. Bundled extensions use performance.now() directly. Wall-clock values stay where they are persisted, shown to users or exchanged between processes: the public provider deadline stays epoch-valued, with monotonic enforcement kept privately, and the plugin SDK facade is unchanged. This absorbs the per-site fixes from @SunnyShu0925 (#186039, #186134, #186412, #184716, #184613) and @mikasa0818 (#184576, #184525, #182064), whose original commits are kept. Update, Doctor, Windows-only and security-held sites are listed under "Not fixed here" in the PR. Evidence: built CLI suspend wait, browser Gateway CDP waits, Discord READY wait and node host-stats checkpoint, each with Date.now stepped inside the process only. On main each misbehaved under the clock step (early expiry or a stretched wait); with this change each matched the no-step control. Media generation's guard blocks local fixtures, so that family relies on the shared owner's regression. Production 479 changed lines, tests net 0. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: mikasa0818 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…86484) fix: measure deadlines and budgets on one monotonic clock owner Many deadline, budget and timeout calculations used Date.now(), so a wall-clock step (NTP correction, VM resume, manual change) made them expire early or run long. Contributors had been fixing these one call site at a time. Core now has one owner, src/shared/monotonic-time.ts, for process-local deadlines and elapsed time, replacing the supervisor-local helper and the per-site variants. Bundled extensions use performance.now() directly. Wall-clock values stay where they are persisted, shown to users or exchanged between processes: the public provider deadline stays epoch-valued, with monotonic enforcement kept privately, and the plugin SDK facade is unchanged. This absorbs the per-site fixes from @SunnyShu0925 (openclaw#186039, openclaw#186134, openclaw#186412, openclaw#184716, openclaw#184613) and @mikasa0818 (openclaw#184576, openclaw#184525, openclaw#182064), whose original commits are kept. Update, Doctor, Windows-only and security-held sites are listed under "Not fixed here" in the PR. Evidence: built CLI suspend wait, browser Gateway CDP waits, Discord READY wait and node host-stats checkpoint, each with Date.now stepped inside the process only. On main each misbehaved under the clock step (early expiry or a stretched wait); with this change each matched the no-step control. Media generation's guard blocks local fixtures, so that family relies on the shared owner's regression. Production 479 changed lines, tests net 0. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: mikasa0818 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
The subagent spawn reconciliation deadline was measured on the wall clock (
Date.now()), so a host clock jump (NTP correction, VM pause/resume, manual time change) corrupted the retry budget and could wrongly kill a healthy reconciliation, or silently stretch the Gateway timeout for an unhealthy one.reconcileSubagentAgentDispatchinsrc/agents/subagents/spawn/subagent-spawn-gateway.tsseededdeadline = Date.now() + SUBAGENT_AGENT_RECONCILE_TIMEOUT_MS(6_400ms) and recomputed the remaining budget withDate.now(). That value feeds two monotonic consumers: the Gateway RPC timeout (callGatewaytimeoutMs) and the inter-iterationdelay(node:timers/promisessetTimeout). A forward wall-clock jump between two iterations drivesremainingMs = deadline - Date.now()below zero and the loop rethrows the original unavailable error, killing a reconciliation that would otherwise recover; a backward jump stretches the timeout and the delay past the intended budget.performance.now(), the clock both consumers already run on. A difference of two monotonic reads is immune to wall-clock drift.reconcileSubagentAgentDispatch— deadline seed,remainingMs, and thedelayupper bound — switched fromDate.now()toperformance.now(). The constants (800/6_400), the retry/throw policy, the dispatched request shape, and transport-error handling are unchanged; no wire behavior changed.deadlinestays a pure in-process closure value (never serialized or reported across processes), so nothing observes it as an epoch.User Impact
A subagent spawn no longer fails spuriously when the host clock is corrected or a VM is resumed during the 6.4s reconciliation window, and the Gateway RPC retries and inter-iteration delays reflect real elapsed time only.
Evidence
Regression (RED → GREEN) — the existing
reconciles ambiguous dispatch (terminal=…)case insrc/agents/subagents/spawn/subagent-spawn.test.tsnow stepsDate.now()forward 10s on the pending replay, and still requires the admitted run plus the 800ms per-call Gateway RPC cap. It reuses that case's single 800ms interval wait, so no new sleep is added, and the suite's test-line total stays flat (net delta: 0; the ratchet reports "Tree is over the ceiling; this change does not add test lines").Real Gateway transport trace — isolated Gateway (
startGatewayServer: token auth, loopback, fake OpenAI-compatible provider) driven by the productioncallNativeSubagentGatewayover a real WebSocket. The firstagentRPC gets a 60ms client timeout, so the run is created but the reply arrives after the client gives up;Date.now()is then stepped forward 10s while that same call is reconciling. Base revision:Same harness on the fixed source:
gateway timeout after 60msat +221msstatus=in_flight,runId=reconcile-proof-target-60-441174-1-3reconciles ambiguous dispatch)The step is the only difference between the runs: on the base revision it zeroes the delay and then drives
remainingMsnegative, so the loop rethrows the original timeout and abandons a healthy run; on the fixed revision the interval and the budget come fromperformance.now(), so the replay of the same idempotency key returns the already-admitted run (single run — a second launch would have produced another run id).Checks: oxlint clean, oxfmt clean on both changed files, test-line ratchet reports no growth. Open PR collision check: no open PR touches
src/agents/subagents/spawn/subagent-spawn-gateway.ts, andorigin/mainstill usesDate.now()at all three sites.