Skip to content

fix(agents): keep embedded run budget on the monotonic clock across approval wall-clock jumps - #184116

Merged
obviyus merged 4 commits into
openclaw:mainfrom
SunnyShu0925:fix/bug-234-approval-deadline-wall-clock
Oct 27, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
SunnyShu0925:fix/bug-234-approval-deadline-wall-clock

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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 on Date.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 the human_question protection 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-clock deadlineAtMs stays authoritative for queue ownership, deadline publication and downstream Date.now() consumers.

User Impact

  • An approval pause no longer eats the run budget: the run resumes with exactly the time it had left, so a mid-approval clock correction stops aborting runs that still had budget.
  • A pending plugin approval stays a genuine human-input pause across a clock step instead of losing that protection.
  • Queue deadlines, lane scheduling, compaction grace, audit-ledger timestamps and code-mode budgets are unchanged.

Why This Change Was Made

deadlineAtMs must stay wall-clock: queue ownership, deadline publication and downstream consumers compare it with Date.now(). The budget arithmetic that has to survive an approval pause does not. scheduleAbortTimer seeds monotonicDeadlineMs = performance.now() + delayMs as it captures the wall-clock deadline; the pause branch keeps that field and resume uses Math.max(1, monotonicDeadlineMs - performance.now()). The plugin wait does the same locally: its pending predicate compares performance.now() against deadlineMonotonicMs, while beginApprovalWait keeps 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. Only Date.now is 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 (still Date.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 gateway runs with a preload that shifts only Date.now; a real WebSocket client owns the approval. The provider asks for echo 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.

pre-fix (same build, the 2 lines reverted to origin/main) post-fix (head)
agent.wait timeout — Request timed out before a response was generated ok
provider requests 1 2
final answer present false true
$ node --import tsx/esm gateway-exec-approval-proof.mts <repo> pre 15000
PROOF-EXEC gateway-ready port=19126 mode=pre
PROOF-EXEC paused-on-exec-approval approvalId=253b9b5a-… budgetMs=8000 wallClockStepMs=15000 shiftApplied=true
PROOF-EXEC agent.wait={"status":"timeout", … "timeoutPhase":"provider","providerStarted":true}
PROOF-EXEC provider-requests=1
PROOF-EXEC final-answer-present=false
{"event":"result","mode":"pre","verdict":"BUDGET_COLLAPSED"}

$ node --import tsx/esm gateway-exec-approval-proof.mts <repo> post 15000
PROOF-EXEC gateway-ready port=19167 mode=post
PROOF-EXEC paused-on-exec-approval approvalId=98fa885b-… budgetMs=8000 wallClockStepMs=15000 shiftApplied=true
PROOF-EXEC exec.approval.resolve=deny {"ok":true}
PROOF-EXEC agent.wait={"status":"ok", …}
PROOF-EXEC provider-requests=2
PROOF-EXEC final-answer-present=true
{"event":"result","mode":"post","verdict":"BUDGET_PRESERVED"}

2. Pending plugin approval (in-process Gateway harness)

A plugin before_tool_call hook requires approval for a code-mode tool; a separate approval client receives plugin.approval.requested; the clock steps +600 000 ms while pending, then the owning run's watchdog decision is read.

$ npx vitest run --config proof.vitest.config.ts -t "pending plugin approval protected"
PROOF-PLUGIN pending-approval watchdog-decision={"action":"observe","reason":"human_question"}
PROOF-PLUGIN run-still-active=true
PROOF-PLUGIN plugin.approval.resolve={"ok":true}
PROOF-PLUGIN agent.wait={"status":"ok", … "terminalReply":{"text":"PLUGIN_APPROVAL_CLOCK_COMPLETE"}}

Regression: with the production files reverted to HEAD~1, keeps the remaining budget when the wall clock jumps before an approval fails (expected "vi.fn()" to not be called at all) and keeps a plugin approval protected when the wall clock jumps while pending fails 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/main still computes both remainders with Date.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 97765dbb8bf212f2b7b80bae2afe782dd3d3d073 and 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)

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 26, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: Main prematurely times out without a final answer after the approval is denied.
  • After: The candidate preserves the remaining execution budget and returns FINAL_AFTER_APPROVAL_DENIAL.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrow repair with shipped-Gateway before/after evidence, preserved lifecycle contracts, and no actionable findings; pending CI remains a landing gate.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The integrated head is exercised through an isolated built Gateway, public WebSocket approval denial, agent.wait, and session history using a local compatible model: forward clock correction times out on main and returns a final answer on the candidate. Supplied in-process Gateway output separately exercises the plugin human-question guard and successful settlement; focused regressions cover cleanup and cancellation. Real host-clock changes and an independent rollback Gateway run are not claimed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A clock correction can interrupt a healthy approval-gated turn or remove protection while a person is still answering.
Reason: The change restores the established execution-budget and human-input contracts without introducing settings or changing approval policy.

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

Before merge

None.

Findings

None.

Agent review details

How this fits together

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

Technical review

Best 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

  • Embedded execution deadline and approval pauses keeps the original intent (03e4bc0: The lifecycle consolidation preserved unused execution and compaction-grace budgets during approval waits and published deadlines to downstream owners.)
  • Plugin approval human-input protection keeps the original intent (097e6a8: Pending plugin approvals must survive stalled-run recovery until a decision, cancellation, or their bounded timeout plus grace.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +12, Tests -6. Total +6 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 17 5 +12
Tests 2 58 64 -6
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 75 69 +6

Review metrics

Metric Value Why it matters
Production versus test changes Production +17/-5; tests +58/-64 The additional production state distinguishes elapsed-time accounting from published epoch deadlines; regression consolidation reduces test lines while retaining lifecycle assertions.

Root-cause cluster

Relationship: canonical
Canonical: #184116
Summary: This PR owns the remaining approval-budget repair and also covers plugin human-input protection; both overlapping earlier attempts are closed unmerged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Wall-clock corrections can prematurely abort approval-gated runs or inflate their execution budget, with a limited environmental trigger.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • 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 (6 earlier review cycles)
  • reviewed 2026-10-26T02:53:38.149Z sha 8901876295949398cce581dd2f41416d81cdbf94 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-26T07:02:34.430Z sha 1919c5c43e76ccdb36dc90fdf4074fc729c3322d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T07:24:58.227Z sha cd9066f :: needs maintainer review before merge. :: none
  • reviewed 2026-10-27T02:22:25.487Z sha cd9066f :: needs maintainer review before merge. :: none
  • reviewed 2026-10-27T13:51:53.838Z sha b206d97 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-27T14:18:47.243Z sha 1dc520e :: needs maintainer review before merge. :: none

Reviewed October 27, 2026, 10:56 AM ET / 14:56 UTC (Revision 7).

@SunnyShu0925
SunnyShu0925 force-pushed the fix/bug-234-approval-deadline-wall-clock branch from 8901876 to 1919c5c Compare October 26, 2026 06:52
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
…pproval wall-clock jumps

Ref: BUG-234-cron-stream-approval-deadline-wall-clock
@SunnyShu0925
SunnyShu0925 force-pushed the fix/bug-234-approval-deadline-wall-clock branch from 1919c5c to cd9066f Compare October 26, 2026 07:18
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Built Gateway approval pause/resume proof

Compared main 137e96f495684747a9963ccf7d46c5888f7121d7 against contributor revision cd9066f35d3f56de24d51183e7aed9596f3c3303, using isolated Node 24.22.1 Linux Docker builds. The subsequent commit only removes the contributor's release-owned changelog entry; runtime inputs are unchanged.

A public Gateway client submits an agent turn with an 8-second budget. The deterministic local model requests harmless echo approval-proof with ask=always. The client receives exec.approval.requested, denies through exec.approval.resolve after approximately 0.5 seconds, and observes agent.wait and session history. No command was granted.

A process-only preload applies a +15-second Date.now step during the first provider request, after the run budget arms but before the tool call reaches approval pause. The same step applies on both main and candidate. Monotonic clocks/timers and the external observer remain unchanged; the system clock was never altered.

Run Clock step Genuine elapsed time Provider requests Result
Main 1 +15s 2.505s 1 Timeout; no visible final
Main 2 +15s 2.692s 1 Timeout; no visible final
Main control none 2.355s 2 Final answer returned
Candidate 1 +15s 3.734s 2 Final answer returned
Candidate 2 +15s 2.650s 2 Final answer returned
Candidate control none 2.896s 2 Final answer returned

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 FINAL_AFTER_APPROVAL_DENIAL, matching no-step controls.

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.

@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Current-main integration proof

Merged main 97765dbb8bf212f2b7b80bae2afe782dd3d3d073 into the contributor branch, producing ed620d087ebe47d53b6a1e069087bcbb03f6a43b. The approval owner merged cleanly: main's decision-settlement handling and this PR's monotonic pending-wait deadline are both preserved.

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.

Built ref Genuine elapsed Approval request/denial Provider calls Outcome
Current main 2.159 s 1 / 1 1 Premature timeout; no final
Integrated candidate 2.093 s 1 / 1 2 Success; visible FINAL_AFTER_APPROVAL_DENIAL

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.

@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@obviyus
obviyus merged commit b39ec5b into openclaw:main Oct 27, 2026
132 of 133 checks passed
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Landed in b39ec5b. Thanks @SunnyShu0925. Approval waits no longer use up the run budget after a clock jump.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@obviyus Thanks!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants