Repository navigation
fix(cli): keep the gateway suspend wait window on the monotonic clock - #184576
mikasa0818 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 changes before merge. What this changesMeasures the Gateway suspend polling window with performance.now() instead of Date.now(). Example: Run openclaw gateway suspend --wait 30 while the Gateway stays busy and the wall clock moves backward 10 minutes.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains This PR fixes a current clock-domain bug, but the previously reported recursive Date.now mock remains in the regression test. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe suspend CLI converts an operator's wait duration into a polling deadline, sends Gateway prepare RPCs, and reports either a suspension lease or a busy outcome. flowchart LR
A[Operator command] --> B[Suspend CLI]
C[Monotonic clock] --> B
B --> D[Gateway RPC client]
D --> E[Gateway prepare response]
E --> B
B --> F[Lease or busy outcome]
Technical reviewBest possible solution: Keep the three monotonic clock substitutions and repair the regression fixture to fail on excess prepares on the base. Do we have a high-confidence way to reproduce the issue? Current-main source shows the wall-clock deadline paired with elapsed-time sleeps, and the supplied real-WebSocket trace demonstrates continued prepares after a backward clock step; no target code was executed during this review. Is this the best way to solve the issue? Changing all three deadline reads in the existing polling owner is the smallest complete production repair and preserves lease timestamps, request identity, and protocol behavior. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4ca8912994b3. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +3, Tests +68. Total +71 across 3 files. Added test files: 1. 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 (2 earlier review cycles)
Reviewed October 26, 2026, 8:59 AM ET / 12:59 UTC (Revision 3). |
8bddfd9 to
10323c3
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
10323c3 to
17c1b64
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
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]>
|
Thanks @mikasa0818. This is now fixed at the root in #186484 (bf10fbe): process-local deadlines and budgets go through one monotonic clock owner, src/shared/monotonic-time.ts (bundled extensions use performance.now()). Your commit from this PR is kept in that merge and you're credited as co-author, so I'm closing this one as covered. For new deadline code, please use that owner rather than a per-site change. |
…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
Fixes:
openclaw gateway suspend --wait Nkeeps issuinggateway.suspend.preparecalls far past the operator-advertised wait window when the system wall clock steps backward — the window deadline is seeded and compared on the wall clock while the poll sleeps run on monotonic timers.User Impact
User impact: an operator's
--wait Nwindow now always ends after N seconds of real elapsed time, regardless of NTP corrections or VM/laptop resume. The CLI never issues a prepare that could suspend the Gateway after the operator's advertised window, and the boundedTimed out waiting for the Gateway to become idleoutcome is reported in real time instead of hanging on a wall-clock-inflated loop.Why This Change Was Made
runGatewaySuspendseedsdeadlineMs = Date.now() + waitMs, guards each attempt withDate.now() >= deadlineMs, and computesremainingMs = deadlineMs - Date.now(), while the poll sleeps throughnode:timers/promiseson the monotonic clock. A backward wall-clock step stretches the window by the step, so the loop keeps issuing real prepare calls forN + step.The window now lives on
performance.now()— seed, per-attempt guard, and remaining computation — which is monotonic and unaffected by wall-clock adjustments. This continues the cross-clock-domain series (#174151, #181335, and the merged fleet: #155846, #182180, #182778, #182859, #183742); the suspend wait window is an unclaimed CLI site in the same family.The committed regression runs on real timers with a short 200ms window (the window sleeps through
node:timers/promises, which fake timers cannot replace) and only the wall-clock reading rewound; the fixed tree stops preparing within the real window while a rewound wall clock keeps every maxAttempts attempt running. The existing suite'smockClocknow advances a mockedperformance.nowreading alongsideDate.now, preserving its original assertions.No suspend protocol, lease, or resume semantics change; behavior on a clock that never steps is identical.
Evidence
Pre-fix RED — stock main (
d18177d60f9), regression test only: every prepare reports busy with a 150ms retry hint, the window is 200ms, and the wall clock is frozen 10 minutes behind. Stock main runs every maxAttempts attempt:Post-fix GREEN — the same scenario stops preparing within the real window, and both suites pass:
Real runtime proof (real Gateway WebSocket transport, in-process wall-clock rewind)
A real local WebSocket gateway fixture speaks the real Gateway wire protocol (server
connect.challenge→ clientconnect→ hello-ok →gateway.suspend.prepareresponses). The productioncallGatewayFromCliWithTransportruns its full client stack — event-loop readiness, device identity bootstrap, challenge connect — and every prepare answers busy with a 500ms retry hint. OnlyDate.nowis rewound in-process;performance.now()reports all real elapsed times. The window is a real 30-second--wait. (Captured in a standalone Node process so no vitest worker keeps the event loop busy; the client bootstrap takes ~19s before the first prepare.)Stock main is still issuing real prepare calls at the 60-second cap (81 prepares, past the whole 30-second window — it would continue for the length of the rewind); with this PR the window ends at 30.4s of real time after 24 real prepares and reports the bounded busy outcome.
Behavior matrix (prepare always busy,
retryAfterMs: 500,--wait 30, wall clock rewound 10min at prepare #1):Also verified on the changed tree:
pnpm format:checkand the changed-file lint/typecheck lanes frompnpm check:changed(the pnpm/corepack-shelling lanes fail on this Windows contributor box for the environmental reasons documented on #182778/#182859/#183742, unrelated to this diff). CI runs those lanes authoritatively.