Repository navigation
Conversation
prepareScheduledTaskSettlement computed its deadline and remaining budget with Date.now() (wall clock) while the consuming probe's spawnSync timeout and sleep poll are monotonic timers. A wall-clock jump forward shrank the probe timeout (a 280s budget became 50s, or 1ms past a 330s roll), killing PowerShell prematurely; a backward roll could keep the deadline loop from exiting. Align with the sibling isScheduledTaskDefinitionAbsent, which already uses performance.now() for the same budget. Update the settlement test's clock mock to drive performance.now(), which now owns the deadline. Ref: BUG-149-schtasks-state-probe-settlement-deadline-wall-clock (local finding)
|
🦞👀 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 changesThis PR measures Scheduled Task settlement deadlines with performance.now() so wall-clock adjustments cannot distort the waiting budget. Example: The wall clock advances 380 seconds during openclaw gateway stop --force --json.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains This PR fixes a current Windows settlement deadline bug with a minimal change and no actionable code findings. Its required CI workflows await approval. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherWindows Gateway lifecycle commands capture the Scheduled Task run identity, stop the owned processes, and consume settlement observations before confirming stop or attempting restart. flowchart TD
A[Gateway stop or restart] --> B[Capture task run identity]
B --> C[Stop owned Gateway processes]
C --> D[Monotonic settlement budget]
D --> E[PowerShell Task Scheduler query]
E --> F[Settled replaced or unavailable]
Technical reviewBest possible solution: Keep all settlement deadline arithmetic on performance.now() within the existing lifecycle owner. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the mixed-clock budget, and supplied Windows CLI output demonstrates pre-fix refusal under forward clock skew; no target code was executed during this review. Is this the best way to solve the issue? Replacing every clock read in the existing closure is the smallest complete fix, preserving settlement outcomes without introducing another owner, configuration, or persisted state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4f592f12c35c. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +35. Total +35 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 Reviewed November 15, 2026, 10:12 AM ET / 15:12 UTC. |
|
Thanks for the work here. We're closing this along with the other open PRs that apply the same change one call site at a time. This series moves individual deadlines to the monotonic clock one at a time; the shared owner is src/shared/monotonic-time.ts, and remaining call sites should be handled together. Please open one issue (or one PR at the shared owner) that covers the whole pattern, with a reproduction of real user-visible harm, instead of separate per-site PRs. Further per-site variants of this pattern will be closed. |
fix: keep five local elapsed-time waits on the monotonic clock Five local waits measured elapsed time with the wall clock, so a clock step (NTP correction, sleep/wake, manual change) ended them early or let them overrun: the exec-approval follow-up wait, the runtime auth deadline, the managed update handoff response wait, and two Windows scheduled-task waits (process exit and settlement). They now use `src/shared/monotonic-time.ts`, passing `monotonicNow` to `scheduleAbsoluteDeadline` where it's used. Epoch values that cross process, RPC or persistence boundaries stay epochs, RPC timeouts stay integers, upstream epoch auth deadlines are untouched, and the handoff `closed` command keeps its helper-owned settlement. No new text. Evidence: full-build CLI with the process-local Date.now stepped by a preload in that process only, main twice and this change twice, plus unstepped controls. Exec-approval follow-up: main ends after about 60 s; this change waits the real ~360 s, the same as unstepped. Runtime auth: a forward step makes main expire after ~367 ms of a ~9.3 s allowance and a backward step makes it overrun to ~12.4 s; this change keeps the allowance and aborts on time. The Windows scheduled-task sites have unit-level proof with a stepped clock, and the handoff wait has source-level proof through a real child pipe. 75 consumer and 55 daemon tests pass; full build and packed smoke pass. CI red is inherited from main (receipt: #199951 (comment)). Receipts: #199951 (comment). Supersedes the closed per-site PRs #181942, #187439, #190976, #195457, #199640 and #199665. Co-authored-by: Ayaan Zaidi <[email protected]>
…199951) fix: keep five local elapsed-time waits on the monotonic clock Five local waits measured elapsed time with the wall clock, so a clock step (NTP correction, sleep/wake, manual change) ended them early or let them overrun: the exec-approval follow-up wait, the runtime auth deadline, the managed update handoff response wait, and two Windows scheduled-task waits (process exit and settlement). They now use `src/shared/monotonic-time.ts`, passing `monotonicNow` to `scheduleAbsoluteDeadline` where it's used. Epoch values that cross process, RPC or persistence boundaries stay epochs, RPC timeouts stay integers, upstream epoch auth deadlines are untouched, and the handoff `closed` command keeps its helper-owned settlement. No new text. Evidence: full-build CLI with the process-local Date.now stepped by a preload in that process only, main twice and this change twice, plus unstepped controls. Exec-approval follow-up: main ends after about 60 s; this change waits the real ~360 s, the same as unstepped. Runtime auth: a forward step makes main expire after ~367 ms of a ~9.3 s allowance and a backward step makes it overrun to ~12.4 s; this change keeps the allowance and aborts on time. The Windows scheduled-task sites have unit-level proof with a stepped clock, and the handoff wait has source-level proof through a real child pipe. 75 consumer and 55 daemon tests pass; full build and packed smoke pass. CI red is inherited from main (receipt: openclaw#199951 (comment)). Receipts: openclaw#199951 (comment). Supersedes the closed per-site PRs openclaw#181942, openclaw#187439, openclaw#190976, openclaw#195457, openclaw#199640 and openclaw#199665. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
On Windows, stopping or updating the Gateway can hang or bail out early when the system clock is adjusted: the scheduled-task settlement probe computes its deadline and remaining budget from
Date.now()(wall clock) while the PowerShell probe'sspawnSynctimeout and the pollsleepare monotonic timers. A clock jump forward shrinks the probe timeout (a 280s budget collapsed to 50s, or 1ms past a 330s roll), killing PowerShell before settlement can be observed; a clock jump backward keeps the wall-clock deadline from ever elapsing, so the loop never exits. The fix uses a monotonic clock (performance.now()) for the deadline and remaining budget, matching the siblingisScheduledTaskDefinitionAbsentin the same file.prepareScheduledTaskSettlementseeds its deadline and reads the remaining budget from the wall clock (Date.now()), while the consumingspawnSynctimeout andsleeppoll are monotonic timers — a cross-clock-domain budget.deadline,remaining, and the exit comparisons withperformance.now()so the budget lives entirely on the monotonic clock.Date.now()usages insideprepareScheduledTaskSettlementinsrc/daemon/schtasks-state-probe.tsbecameperformance.now(), plus a new regression test and an update to the existing settlement test's clock mock.stopScheduledTask/restartScheduledTask), the settlement result shape, and the default timeout constants all remain unchanged.Why This Change Was Made
prepareScheduledTaskSettlementis the only cross-clock-domain spot left in this file: its siblingisScheduledTaskDefinitionAbsentalready computesremainingTimeout()andexpired()fromperformance.now(), and the file's other deadline helpers useperformance.now()too. The settlement deadline is a purely process-internal closure variable — never serialized, persisted, or compared across processes — so a full switch to the monotonic clock is safe and keeps the budget aligned with the monotonic timers that consume it. No new parser, policy branch, or configuration surface is introduced. The existingschtasks.settlement.test.tsclock mock was moved fromDate.now()toperformance.now()while preserving the test's intent (settlement exhausts the full stop budget without a false restart).performance.now()is exactly the clock the surroundingspawnSynctimeout and pollsleepalready use, so the deadline can no longer be skewed by a wall-clock step.settlement unavailable.performance.now()is monotonic per process, so a deadline seeded before a process restart is not portable — not a concern here because the deadline is a local closure variable read only within one call. Node'sperformance.now()resolution on Windows is millisecond-class, matching the previousDate.now()granularity, so the sub-second comparisons keep their behavior. Boundary left unchanged: the default timeout constants and thestop/restartcaller contract.User Impact
Windows Gateway stop/update no longer stalls or fails spuriously when the system clock is adjusted (NTP resync, manual set, DST), because the settlement deadline is no longer skewed by wall-clock jumps. The settlement still waits the full configured stop budget before declaring the task unavailable, and still refuses a restart only when settlement genuinely cannot be confirmed.
Evidence
Real shipped command, real runner (before/after): a
windows-latestrunner installs a real Scheduled-Task Gateway (openclaw gateway install), then runs the actual shippedopenclaw gateway stop --forcewhile a preload steps the wall clock (Date.now();performance.now()stays monotonic) between the settlement deadline seed and budget read — exactly the NTP/manual-set/DST incident. Both builds drive the realschtasks.exe/PowerShell subprocess; the only difference is the clock source of the settlement deadline (Date.now()pre-fix vsperformance.now()post-fix):openclaw gateway stopok (50s budget)Proof artifact + workflow:
SunnyShu0925/oc-winproofrun #40486854535.Raw CLI output (inline, current head
e804ccc7dcd) — verbatim, redacted to service/port only (no IPs, keys, endpoints):Under the same wall-clock jump the pre-fix build fails the very
openclaw gateway stopthat succeeds on the post-fix build: the collapsed 1ms budget times out the real PowerShell probe, settlement reportsunavailable, andterminate()refuses to confirm the stop. The backward jump is equally inert post-fix (stop exit=0 elapsed=5.41s).Unit regression (forward wall-clock skew), pre-fix RED / post-fix GREEN:
Full daemon shard: 118 files / 1943 tests passed.
Beyond the clock budget, the settlement state machine and its JSON parsing are not re-tested here: they are covered by the existing 37-test settlement suite (unchanged apart from its clock-mock alignment).
Open PR collision check: searched open PR topics
settlement/schtasks/monotonic clockand changed-file lists — no open PR touchessrc/daemon/schtasks-state-probe.tsorsrc/daemon/schtasks.settlement.test.ts. The long-lived draft #138344 also editssrc/daemon/schtasks-state-probe.ts, but its scope is scheduled-task definition listing, not the settlement deadline clock source.This replaces a previously closed PR carrying the identical commit (same fix, same proof); the branch is unchanged apart from being pushed from a different fork.