Skip to content

fix(agents): keep exec approval followup observation deadline on the monotonic clock - #185288

Closed
SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/bash-exec-approval-followup-deadline-monotonic-155
Closed

SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/bash-exec-approval-followup-deadline-monotonic-155

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When an async exec_approval_followup run 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 gateway agent.wait RPC. 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.

  • Problem: waitForAgentFollowupRun seeds observationDeadline = Date.now() + timeout and reads remainingMs = 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.
  • Solution: align the whole observation budget to the monotonic clock — seed observationDeadline and read remainingMs / retryDelayMs with performance.now(), matching the monotonic consumer.
  • What changed: src/agents/bash-tools.exec-approval-followup.ts (3 deadline reads Date.now()→performance.now(); per-wait budget rounded up with Math.ceil for the gateway agent.wait integer timeoutMs schema); the deadline regression test now controls the monotonic clock.
  • What did NOT change: the transport retry/backoff policy and the observation lifecycle (reason "deadline", transportErrors accounting) 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.

  • Best fix: yes — one canonical owner, no new parser/policy branch.
  • Alternative: keep Date.now() and rely on the per-wait Math.min cap; rejected because the cap only bounds a single wait, not the total observation window, nor the retryDelayMs <= 0 exit from a forward wall jump.
  • Risk: low — Math.ceil on 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 function exec-host-node.ts / exec-host-gateway.ts call after an approved async exec. It registers the handoff, then sendExecApprovalFollowup runs through the production GatewayRecoveryRuntime the Gateway registers at startup — no registerGatewayRecoveryRuntime override, no internal-function call. Both the agent dispatch (production recovery.dispatchAgent → real in-process agent.run, accepted against a synthetic-provider run that stays pending) and the wait (production recovery.waitForAgent → shipped wait transport) are unmodified shipped code. A 30 s wall step (−30 s / +30 s) is injected inside waitForAgentFollowupRun via a Date.now proxy; a pass-through probe on recovery.waitForAgent records 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.)

# BACKWARD (−30s rewind)
[proof] production recovery runtime present = true (Gateway auto-registered)
[proof] recovery.waitForAgent budget timeoutMs=20000 -> shipped wait transport   # post-fix: BOUNDED
[proof] recovery.waitForAgent budget timeoutMs=49999 -> shipped wait transport   # pre-fix: INFLATED +30s
# FORWARD (+30s jump)
[proof] recovery.waitForAgent budget timeoutMs=20000 -> shipped wait transport   # post-fix: BOUNDED, observation proceeds
[proof] outcome=undefined elapsed=2652ms / NO agent.wait dispatched             # pre-fix: observation ENDED IMMEDIATELY (drops slow output)
leg skew production-recovery budget (round 1) window
post-fix −30 s 20000 bounded
pre-fix −30 s 49999 inflated +30 s
post-fix +30 s 20000 (proceeds) bounded
pre-fix +30 s none (ends immediately) drops slow output

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 integer timeoutMs passes the shipped validateAgentWaitParams.

2. Integer-boundary proof (P2). performance.now() is fractional; the agent.wait schema requires an integer timeoutMs. sendExecApprovalFollowup was driven through a recovery runtime whose waitForAgent re-runs the shipped validator on the exact params. Same fractional remaining budget (59999.75 ms), before vs after the one-line Math.ceil:

before: [waitForAgent] timeoutMs=59999.75 -> shipped validator: REJECT
after : [waitForAgent] timeoutMs=60000   -> shipped validator: ACCEPT

Math.ceil(59999.75) === 60000 never 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/main still has the wall-clock reads (bug live); sibling PR #181942 touches the same three reads for the same defect; both open.

@clawsweeper

clawsweeper Bot commented Oct 27, 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.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

This external contributor PR changes sensitive security components. A maintainer must review these changes before merging.

Current SHA: dc2173a20bbf0536e0ed6e8d1201277ab793b05e

These sensitive security changes were made:

  • src/agents/bash-tools.exec-approval-followup.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

After reviewing the changes, post a new PR comment containing only approval commands, each on its own line:

/allow-security-sensitive-change

A later push requires a fresh approval comment.

@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. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

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

  • Before: The remaining wait budget grows to roughly 50 seconds.
  • After: The remaining wait budget stays bounded at 20 seconds.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair supported by production-transport traces under controlled clock injection and targeted regression coverage.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Contributor terminal traces exercise the exec-host follow-up entry through an automatically registered production Gateway recovery runtime and shipped transport with injected positive and negative wall-clock steps; corrected budgets remain bounded, fractional budgets pass validation, and direct delivery does not compete.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: System clock adjustments make exec follow-up observation finish prematurely or continue beyond its intended window.
Reason: The change restores the existing bounded-observation contract without changing delivery ownership, configuration, or public APIs.

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

Before merge

  • Await maintainer action - A maintainer must review dc2173a and approve it through the enforced security-sensitive-change gate.

Findings

None.

Agent review details

How this fits together

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

Technical review

Best 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

  • Bounded exec follow-up observation keeps the original intent (602b575: Bound ambiguous observation while leaving delivery with the accepted agent run to avoid duplicate replies or command reruns.)
  • Deadline regression coverage keeps the original intent (267da05: Consolidate redundant tests while preserving lifecycle and regression boundaries.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 432356a adds src/agents/bash-tools.exec-approval-followup.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 432356a68438; files: src/agents/bash-tools.exec-approval-followup.ts)

PR surface

Source +3, Tests +28. Total +31 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 7 4 +3
Tests 1 30 2 +28
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 37 6 +31

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Wall-clock adjustments distort a bounded background observation window, with limited impact and unchanged accepted-run delivery ownership.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • 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 (8 earlier review cycles)
  • reviewed 2026-10-27T01:26:36.031Z sha 323db334d0e95350135e7e3bf8509746df3f70f6 :: needs real behavior proof before merge. :: [P2] Round the remaining budget before sending agent.wait
  • reviewed 2026-10-27T03:04:28.417Z sha dc2173a :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-27T04:24:35.315Z sha dc2173a :: blocked before merge. :: none
  • reviewed 2026-10-27T05:24:04.237Z sha dc2173a :: blocked before merge. :: none
  • reviewed 2026-10-27T06:43:17.252Z sha dc2173a :: blocked before merge. :: none
  • reviewed 2026-10-27T06:55:37.342Z sha dc2173a :: blocked before merge. :: none
  • reviewed 2026-10-27T07:22:37.094Z sha dc2173a :: blocked before merge. :: none
  • reviewed 2026-10-27T07:42:37.854Z sha dc2173a :: blocked before merge. :: none

Reviewed October 27, 2026, 4:15 AM ET / 08:15 UTC (Revision 9).

@SunnyShu0925
SunnyShu0925 force-pushed the fix/bash-exec-approval-followup-deadline-monotonic-155 branch from 323db33 to dc2173a Compare October 27, 2026 02:49
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 27, 2026
@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot 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
@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
@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
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@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
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawtributors PR from a clawtributor P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-review-required security-sensitive-changed size: XS status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants