Repository navigation
fix(agents): keep exec approval followup observation deadline on the monotonic clock - #185288
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 changesUse monotonic time for exec approval follow-up observation and round Gateway wait budgets to integer milliseconds. Example: The wall clock moves backward 30 seconds during a controlled 20-second observation window.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains This PR fixes a current observation-deadline bug with a focused change and sufficient production-path proof; current-head security approval remains enforced. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherAfter an approved asynchronous command finishes, the exec host dispatches a continuation and observes its accepted agent run through Gateway waits; observation expiry preserves that run's delivery ownership. flowchart LR
A[Approved command result] --> B[Exec host followup entry]
B --> C[Continuation dispatch]
C --> D[Accepted agent run]
C --> E[Monotonic observation loop]
E --> F[Gateway agent wait]
F --> E
E --> G[Completion or observation expiry]
Technical reviewBest possible solution: Merge the focused monotonic-clock repair after current-head security approval, then consolidate the overlapping PR. Do we have a high-confidence way to reproduce the issue? Current-main arithmetic directly exposes the clock-step failure, and contributor traces demonstrate both directions; no target code was executed during this review. Is this the best way to solve the issue? The patch is the smallest complete repair: keep the process-local deadline in one monotonic clock domain and preserve the existing integer RPC contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4024bddd8ef2. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +3, Tests +28. Total +31 across 2 files. Added test files: 0. 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 (8 earlier review cycles)
Reviewed October 27, 2026, 4:15 AM ET / 08:15 UTC (Revision 9). |
323db33 to
dc2173a
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
What Problem This Solves
When an async
exec_approval_followuprun completes on the gateway, OpenClaw keeps observing it for a bounded 6-minute window before deciding whether to resume the originating session. That observation window is budgeted on the wall clock (Date.now()) but consumed by the monotonic timer that backs the gatewayagent.waitRPC. When the system wall clock is adjusted (NTP step, VM clock sync, or a laptop waking from hibernation), the two clocks diverge and the observation window is distorted.waitForAgentFollowupRunseedsobservationDeadline = Date.now() + timeoutand readsremainingMs = deadline - Date.now(), passing that budget into a gateway wait consumed on the monotonic clock (performance.now()/setTimeout). Budget computed in one clock domain, spent in another.observationDeadlineand readremainingMs/retryDelayMswithperformance.now(), matching the monotonic consumer.src/agents/bash-tools.exec-approval-followup.ts(3 deadline readsDate.now()→performance.now(); per-wait budget rounded up withMath.ceilfor the gatewayagent.waitintegertimeoutMsschema); the deadline regression test now controls the monotonic clock."deadline",transportErrorsaccounting) are untouched.Why This Change Was Made
The observation deadline is a pure process-local closure (never serialized/persisted/cross-process), so a monotonic clock is the only correct source. The gateway consumer already computes its own monotonic
DispatchDeadline; passing it a wall-clock-derived remaining budget is a cross-clock-domain mismatch. Switching the three reads keeps the seed and every remaining-budget read on the same (monotonic) domain, zero external contract change.Date.now()and rely on the per-waitMath.mincap; rejected because the cap only bounds a single wait, not the total observation window, nor theretryDelayMs <= 0exit from a forward wall jump.Math.ceilon the remaining budget never shrinks the observation window and always yields an integer accepted by the gateway validator.User Impact
Exec approval follow-ups for async commands now complete on a stable, clock-skew-proof observation window. Under NTP/hibernation clock steps, a healthy agent run is no longer prematurely declared complete (dropping slow terminal output), and a finished run is no longer observed far beyond its deadline.
Evidence
1. Shipped exec-host public-entry clock-skew proof, both directions. Driven through the exec-host public shipped entry
sendExecApprovalFollowupResult(bash-tools.exec-host-shared.ts) — the exact functionexec-host-node.ts/exec-host-gateway.tscall after an approved async exec. It registers the handoff, thensendExecApprovalFollowupruns through the productionGatewayRecoveryRuntimethe Gateway registers at startup — noregisterGatewayRecoveryRuntimeoverride, no internal-function call. Both theagentdispatch (productionrecovery.dispatchAgent→ real in-processagent.run, accepted against a synthetic-provider run that stays pending) and the wait (productionrecovery.waitForAgent→ shipped wait transport) are unmodified shipped code. A 30 s wall step (−30 s / +30 s) is injected insidewaitForAgentFollowupRunvia aDate.nowproxy; a pass-through probe onrecovery.waitForAgentrecords the round-1 budget handed to the wait transport. (Observation budget shortened 6 m→20 s as a disclosed control; the per-wait cap cannot mask it.)Keeping the budget on the monotonic clock makes the shipped wait budget immune to wall-clock steps in both directions. The accepted run stays the sole delivery owner (
direct_deliveries=0; no competing direct delivery), and the integertimeoutMspasses the shippedvalidateAgentWaitParams.2. Integer-boundary proof (P2).
performance.now()is fractional; theagent.waitschema requires an integertimeoutMs.sendExecApprovalFollowupwas driven through a recovery runtime whosewaitForAgentre-runs the shipped validator on the exact params. Same fractional remaining budget (59999.75 ms), before vs after the one-lineMath.ceil:Math.ceil(59999.75) === 60000never shrinks the budget;Math.max(1, ...)keeps the positive minimum.3. Regression. Pre-fix the new test fails (
Number.isInteger(59999.75)false); post-fix it passes, full suite green (18/18).What was not tested: the divergence itself (NTP/hibernation) is injected by the proof; direct-delivery and session-resume paths are unchanged and covered by existing suites.
Collision check:
origin/mainstill has the wall-clock reads (bug live); sibling PR #181942 touches the same three reads for the same defect; both open.