Repository navigation
fix(daemon): use monotonic clock for scheduled task settlement deadline - #185577
SunnyShu0925 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 maintainer review before merge. What this changesThis PR measures Windows Scheduled Task settlement deadlines with performance.now() so system-clock adjustments cannot distort the wait 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✅ Ready for maintainer review This PR is a focused, useful fix for a current Windows settlement bug, with no actionable code findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherWindows Gateway lifecycle commands capture the scheduled task's run identity, stop the owned process, and probe Task Scheduler until settlement, replacement, or timeout is established. flowchart TD
A[Gateway stop or restart] --> B[Capture task run identity]
B --> C[Stop owned Gateway process]
C --> D[Monotonic settlement deadline]
D --> E[PowerShell Task Scheduler probe]
E --> F[Settled replaced or unavailable]
Technical reviewBest possible solution: Merge the focused clock replacement while preserving the existing settlement and ownership contracts. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the mixed-clock budget, and the contributor supplies pre-fix Windows CLI refusal plus red-to-green timeout regressions; no target code was executed during this read-only review. Is this the best way to solve the issue? Replacing every clock read in the existing closure is the smallest complete fix: it keeps deadline arithmetic in one clock domain without adding state, configuration, or another owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2ad29df57724. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource 0, Tests +35. Total +35 across 3 files. Added test files: 0. 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 27, 2026, 6:32 AM ET / 10:32 UTC (Revision 3). |
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)
5308a06 to
e804ccc
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
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).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: no open PR touches
schtasks-state-probe.ts/schtasks.settlement.test.ts(searched open PR topicssettlement/schtasks/monotonic clockand changed-file lists).Per review: added a real-Windows proof (forward + backward clock steps, before/after table) and fixed the new regression test's floating-promise lint by returning the
withMockedPlatformpromise from the test callback (CIcheck-lint-core-2).