Repository navigation
fix(infra): keep Windows process start deadline on the monotonic clock - #184162
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 uses monotonic time for Windows process-identity probe deadlines and rounds subprocess timeout budgets to integer milliseconds. Example: The wall clock jumps forward 10 seconds during Windows Gateway process verification.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR: it fixes a concrete Windows deadline defect still present on main, with convincing CLI proof and no actionable findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway lifecycle and shared PID-identity callers supply a PID and timeout to the Windows reader, which tries native identity, PowerShell, and WMIC before returning a creation timestamp or null. flowchart TD
A[Gateway lifecycle and PID checks] --> B[Windows process identity reader]
B --> C[Native identity lookup]
C --> D[PowerShell fallback]
D --> E[WMIC fallback]
C --> F[Creation timestamp or null]
D --> F
E --> F
Technical reviewBest possible solution: Land this focused correction in the existing Windows identity reader while preserving native lookup, fallbacks, and timestamp semantics. Do we have a high-confidence way to reproduce the issue? Source establishes the clock-domain mismatch, and supplied Windows CLI traces demonstrate paired failure and recovery under injected skew; this read-only review executed no target code. Is this the best way to solve the issue? Changing all elapsed-budget reads together and rounding subprocess timeouts is the smallest complete repair using the existing owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 96da011f8040. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +48. Total +48 across 2 files. Added test files: 0. View PR surface stats
Review metrics
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 (5 earlier review cycles)
Reviewed October 27, 2026, 12:59 AM ET / 04:59 UTC (Revision 6). |
3167fa4 to
9a0e755
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
9a0e755 to
1c264fa
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
Thank you @SunnyShu0925 for finding and fixing this clock-jump bug! The fix is now on main through replacement #190236 (f7d6774), with your contribution credited in the PR and replacement commit. |
What Problem This Solves
readWindowsProcessStartTimeSyncderives its deadline and per-attempt remaining budget from the wall clock (Date.now()) but hands those budgets tospawnSynctimeouts, which are consumed by the monotonic clock. When the wall clock is shifted, the two clocks disagree and Windows process-start detection either stalls (clock rolled back → inflated remaining budget) or kills a healthy probe (clock jumped forward → negative remaining).Problem: cross-clock-domain deadline — wall-clock seed/remaining read, monotonic timeout consumption.
Solution: derive the deadline and both remaining-budget reads from
performance.now()so all three sit on the monotonic clock, and round both positive budgets up withMath.ceilto preserve Node'sspawnSyncinteger-timeout contract (fractional timeouts throwERR_OUT_OF_RANGE). The exhausted-budget checks (<= 0) are retained.What changed:
src/infra/windows-process-start.ts— threeDate.now()→performance.now(), plusMath.ceilon both positive budgets. Nothing else changed: return contract, timeout values,timeoutMsparameter, and all callers are untouched. The deadline is a process-local closure variable — never serialized, persisted, reported, or compared against a wall-clock value.Why This Change Was Made
The same cross-clock-domain bug family has been fixed across the codebase (prior monotonic-clock PRs), and the sibling Darwin reader (
src/shared/pid-alive.ts) already rounds its monotonic remaining budget withMath.ceilbefore spawning.User Impact
On Windows, system time adjustments (manual changes, NTP corrections) no longer make process-start identity checks return
nullor stall. Concretely,openclaw gateway stopkeeps terminating its own Gateway after a clock jump instead of reporting success while the Gateway keeps serving. Rounding fractional budgets also prevents Node'sERR_OUT_OF_RANGErejection whenperformance.now()subtraction yields a fractional timeout.Evidence
Shipped CLI proof — complete Windows Gateway workflow (
windows-latest,SunnyShu0925/oc-winproofworkflowwindows-cli-proof-184162.yml, run 40443823765). The job runs the shippedopenclaw gateway install --allow-unconfigured --force(real Scheduled Task Gateway), waits until it listens, then runs the shippedopenclaw gateway stop --force --json, which resolves the Scheduled Task owner and re-verifies the live Gateway PID withreadWindowsProcessStartTimeSync()before terminating it.NODE_OPTIONS=--import cli-clock-shift.mjsstepsDate.now()forward +10s on the deadline read inside that reader;performance.now()is untouched, so the skew is a pure NTP-style wall-clock jump. The only build difference between the two halves is the three-line revert.That block is a verbatim subset of the run log (repeated
#2lines collapsed). The stepped stop only shifts the reader on the pre-fix build — the fixed reader never readsDate.now(), so no shift fires there.gateway stopDate.now()stoppedperformance.now()+Math.ceilIsolated reader matrix (same reader, run 40279893860, real PowerShell child, native identity disabled): post-fix forward +10s → real start time in 159ms; pre-fix forward +10s →
nullin 0.07ms (healthy probe skipped). Backward −10s: inflated budget pre-fix vs 147ms post-fix.Regression test (
src/infra/windows-process-start.test.ts, folded into the existing suite):it.eachover ±10s wall shifts asserts the WMIC deadline stays insidetimeoutMs, and a secondit.eachover fractional elapsed (0.4/0.8ms) asserts everyspawnSynctimeout is an integer within budget. Pre-fix RED2 failed | 25 passed; post-fix GREEN27 passed(verified on the current head).oxfmt --checkandoxlintclean on both files. No lockfile changes; production diff is net 0 LOC.