Repository navigation
fix(agents): keep embedded run budget on the monotonic clock across approval wall-clock jumps - #184116
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 changesThis PR uses monotonic time for embedded execution-budget accounting and pending plugin-approval protection while preserving published wall-clock deadlines. Example: An eight-second agent run encounters a +15-second wall-clock correction before pausing for exec approval.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current execution-budget bug with a focused change and convincing Gateway proof; no actionable defects were found, and exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded attempt timeout owner consumes execution budgets and approval lifecycle events, then schedules cancellation and publishes deadlines; the plugin approval owner separately protects genuinely pending human input from stalled-run recovery. flowchart TD
A[Agent turn] --> B[Embedded timeout owner]
C[Approval lifecycle] --> B
B --> D[Monotonic execution budget]
B --> E[Published wall clock deadline]
F[Plugin approval owner] --> G[Human input wait protection]
G --> H[Stalled run watchdog]
Technical reviewBest possible solution: Land the existing focused monotonic-accounting repair once the required checks pass. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the clock-domain mismatch, and supplied built-Gateway comparisons reproduce premature timeout before the fix; this review executed no target code. Is this the best way to solve the issue? The patch repairs elapsed-time arithmetic in the existing owners while retaining wall-clock publication, approval decisions, cancellation, and compaction grace; the changed tests protect distinct timing and recovery failures. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 22f1ebdbc2ba. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +12, Tests -6. Total +6 across 4 files. Added test files: 0. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 (6 earlier review cycles)
Reviewed October 27, 2026, 10:56 AM ET / 14:56 UTC (Revision 7). |
8901876 to
1919c5c
Compare
|
🦞👀 Re-review progress:
|
…pproval wall-clock jumps Ref: BUG-234-cron-stream-approval-deadline-wall-clock
1919c5c to
cd9066f
Compare
|
🦞👀 Re-review progress:
|
Built Gateway approval pause/resume proofCompared main A public Gateway client submits an agent turn with an 8-second budget. The deterministic local model requests harmless A process-only preload applies a +15-second
Every run published and successfully resolved a real approval ticket. Main wrongly exhausts its budget before eight seconds of genuine elapsed time and never sends the follow-up provider request. Both candidate runs preserve the remainder and return Scope: this proves the embedded exec approval pause/resume path under forward correction. The separate plugin human-question guard and rollback-overrun case were not independently exercised by this proof. No private hooks, raw-state seeding, owner-constant edits, real provider keys, or host-clock changes were used. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…deadline-wall-clock
Current-main integration proofMerged main Rebuilt both exact refs in isolated Node 24.22.1 Docker and repeated the public Gateway approval-skew flow once per ref: eight-second run budget, +15-second in-process Date.now step after provider start, harmless exec approval requested, public denial, agent.wait and history observation. No host/system clock change.
Focused tests on the integrated candidate: 17/17 passed across approval recovery and attempt-timeout preparation, including both skew regressions. The prior twice-per-ref and no-step controls remain linked above; this repeat verifies the changed current-main owner. No production or test changes beyond the clean main integration were necessary. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in b39ec5b. Thanks @SunnyShu0925. Approval waits no longer use up the run budget after a clock jump. |
|
@obviyus Thanks! |
…pproval wall-clock jumps (openclaw#184116) fix(agents): keep the embedded run budget on the monotonic clock across approval waits The embedded run budget was measured with the wall clock across exec approval waits, so a forward clock step while waiting for approval used up the budget and the run timed out without a final answer. The budget now uses monotonic time. Evidence: a real agent turn with an 8-second budget, an exec approval resolved through exec.approval.resolve, and Date.now stepped forward 15 seconds inside the process only. On main the run timed out after about 2 to 3 seconds of real time with no final answer (three runs); with this change it continued and produced its final answer (three runs, including on the head merged with current main). Runs without a clock step succeed on both refs. Details: openclaw#184116 (comment). Thanks @SunnyShu0925. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
An embedded agent run paused for a tool approval loses its remaining execution budget when the system wall clock steps while the approval is pending (NTP correction, DST change, manual date change). Resume recomputed the remainder as
deadline.deadlineAtMs - Date.now()with both readings onDate.now(): a forward step collapses it to ~0 ms so the run aborts the moment the approval resolves, and a backward step inflates it so the run overruns its real deadline.The plugin-approval human-input wait (
agent-tools.before-tool-call.approval.ts) had the same defect: a forward step dropped thehuman_questionprotection that keeps stuck-run recovery off a turn a human is still answering, and a backward step pinned the turn as waiting past a genuine timeout.Fix: carry a monotonic deadline (
performance.now()) beside the wall-clock one and take the resume remainder and wait expiry from it. Wall-clockdeadlineAtMsstays authoritative for queue ownership, deadline publication and downstreamDate.now()consumers.User Impact
Why This Change Was Made
deadlineAtMsmust stay wall-clock: queue ownership, deadline publication and downstream consumers compare it withDate.now(). The budget arithmetic that has to survive an approval pause does not.scheduleAbortTimerseedsmonotonicDeadlineMs = performance.now() + delayMsas it captures the wall-clock deadline; the pause branch keeps that field and resume usesMath.max(1, monotonicDeadlineMs - performance.now()). The plugin wait does the same locally: its pending predicate comparesperformance.now()againstdeadlineMonotonicMs, whilebeginApprovalWaitkeeps wall-clock time so approval records and the audit ledger keep meaningful timestamps. A wholesale move to one monotonic clock was rejected: it ripples through the watchdog and lane scheduling.Evidence
Proof revision
cd9066f35d3. OnlyDate.nowis shifted;performance.now()and timers are untouched. The exec budget is proven through the shipped Gateway CLI process; the plugin human-input wait through an in-process Gateway harness because its observable (the owning run's watchdog decision) has no Gateway RPC surface. Models are a local OpenAI-compatible provider. Not claimed: a real NTP step on a live host and the watchdog's own exec-approval deadline (stillDate.now(), a second-level grace guard).1. Exec approval through the shipped Gateway CLI (current head)
agents.defaults.timeoutSeconds: 8,tools.exec.mode: "ask".node openclaw.mjs gatewayruns with a preload that shifts onlyDate.now; a real WebSocket client owns the approval. The provider asks forecho EXEC_APPROVAL_CLOCK_PROOF; +15 000 ms lands after the budget is armed and before the pause computes its remainder; the approval resolves as deny.origin/main)agent.waittimeout—Request timed out before a response was generatedok2. Pending plugin approval (in-process Gateway harness)
A plugin
before_tool_callhook requires approval for a code-mode tool; a separate approval client receivesplugin.approval.requested; the clock steps +600 000 ms while pending, then the owning run's watchdog decision is read.Regression: with the production files reverted to
HEAD~1,keeps the remaining budget when the wall clock jumps before an approvalfails (expected "vi.fn()" to not be called at all) andkeeps a plugin approval protected when the wall clock jumps while pendingfails with{action:"stop"}; both pass at the current head.Collision check: the earlier overlapping attempt, #143327, is closed and omitted the plugin wait; no open PR touches these files, and
origin/mainstill computes both remainders withDate.now().Additional built Gateway Evidence
#184116 (comment)
Main twice wrongly times out after a +15-second process-only wall-clock step during exec approval pause; candidate twice preserves the eight-second execution budget and returns its final answer after public denial. Both no-step controls succeed. The follow-up commit removes only the contributor changelog entry because release notes are release-owned; it does not change runtime code.
Regression consolidation
The CI test-line ratchet exposed net test growth. Consolidated the clock-skew cases into the existing approval lifecycle tables, retained the scoped-approval, timing, cancellation, recovery and human-question protection assertions, reused the existing abort-aware promise helper, and removed one-row table boilerplate. The PR now changes test lines by −6 against main. Focused Linux validation: 17/17 passed, including both skew cases, plus Oxfmt. No production changes after the built-Gateway proof.
Current-main integration proof
Merged main
97765dbb8bf212f2b7b80bae2afe782dd3d3d073and rebuilt both refs. One approval-skew run per ref: current main times out after 2.159s, integrated candidate succeeds after 2.093s with the follow-up provider request and final answer. Focused tests pass 17/17. #184116 (comment)