Skip to content

fix(infra): keep Windows process start deadline on the monotonic clock - #184162

Closed
SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/bug-137-windows-process-start-deadline-wall-clock
Closed

SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/bug-137-windows-process-start-deadline-wall-clock

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

readWindowsProcessStartTimeSync derives its deadline and per-attempt remaining budget from the wall clock (Date.now()) but hands those budgets to spawnSync timeouts, 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 with Math.ceil to preserve Node's spawnSync integer-timeout contract (fractional timeouts throw ERR_OUT_OF_RANGE). The exhausted-budget checks (<= 0) are retained.

What changed: src/infra/windows-process-start.ts — three Date.now() → performance.now(), plus Math.ceil on both positive budgets. Nothing else changed: return contract, timeout values, timeoutMs parameter, 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 with Math.ceil before spawning.

User Impact

On Windows, system time adjustments (manual changes, NTP corrections) no longer make process-start identity checks return null or stall. Concretely, openclaw gateway stop keeps terminating its own Gateway after a clock jump instead of reporting success while the Gateway keeps serving. Rounding fractional budgets also prevents Node's ERR_OUT_OF_RANGE rejection when performance.now() subtraction yields a fractional timeout.

Evidence

Shipped CLI proof — complete Windows Gateway workflow (windows-latest, SunnyShu0925/oc-winproof workflow windows-cli-proof-184162.yml, run 40443823765). The job runs the shipped openclaw gateway install --allow-unconfigured --force (real Scheduled Task Gateway), waits until it listens, then runs the shipped openclaw gateway stop --force --json, which resolves the Scheduled Task owner and re-verifies the live Gateway PID with readWindowsProcessStartTimeSync() before terminating it. NODE_OPTIONS=--import cli-clock-shift.mjs steps Date.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.

=== post-fix (performance.now + Math.ceil) :: openclaw gateway stop ===
stop exit=0
  "action": "stop",
  "ok": true,
  "result": "stopped",
VERDICT[post-fix]: STOPPED gateway identity verified and terminated
CONTROL[post-fix]: CONTROL_STOPPED plain stop released 19123

=== pre-fix (Date.now) :: openclaw gateway stop ===
[proof-inject] wall-clock step +10000ms applied on Date.now read #2
[proof-inject] wall-clock step +10000ms applied on Date.now read #3
[proof-inject] wall-clock step +10000ms applied on Date.now read #6
stop exit=0
  "action": "stop",
  "ok": true,
  "result": "stopped",
VERDICT[pre-fix]: STOP_FAILED gateway still listening on 19123
CONTROL[pre-fix]: CONTROL_STOPPED plain stop released 19123

That block is a verbatim subset of the run log (repeated #2 lines collapsed). The stepped stop only shifts the reader on the pre-fix build — the fixed reader never reads Date.now(), so no shift fires there.

Build Reader clock stepped gateway stop Port 19123 afterwards Unstepped control
main Date.now() reports stopped still listening stopped
PR head performance.now() + Math.ceil verifies + terminates released stopped

Isolated 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 → null in 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.each over ±10s wall shifts asserts the WMIC deadline stays inside timeoutMs, and a second it.each over fractional elapsed (0.4/0.8ms) asserts every spawnSync timeout is an integer within budget. Pre-fix RED 2 failed | 25 passed; post-fix GREEN 27 passed (verified on the current head).

oxfmt --check and oxlint clean on both files. No lockfile changes; production diff is net 0 LOC.

@clawsweeper

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

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: The probe can return no identity, and gateway stop can report success while port 19123 remains listening.
  • After: The probe retains its elapsed-time budget, allowing gateway stop to verify and terminate the Gateway.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal owner-level repair with shipped Windows CLI evidence, focused regression coverage, and successful exact-head checks.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied Windows terminal output exercises the shipped gateway install and stop commands with native lookup disabled and a +10-second Date.now injection: the reverted build leaves port 19123 listening, while the fixed build stops the Gateway; unstepped controls succeed, and the inspected proof scripts match this scenario.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Windows process verification can stall or lose a valid probe after a system clock adjustment.
Reason: The patch restores the existing bounded-probe contract without changing defaults, configuration, persisted identity, or process ownership policy.

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
Reviewed head: 1c264fa307ba25fa62852dbe91cecfd2fa3dacd1

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway 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
Loading

Technical review

Best 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

  • Shared Windows deadline and fallback budgets keeps the original intent (97bc908: Unify process identity reads, permit slower cold PowerShell startup, and retain WMIC fallback within one caller deadline.)
  • Native lookup charged against the fallback deadline keeps the original intent (baa836b: Avoid unnecessary startup subprocesses while preserving shell fallback and sealed-helper independence.)
  • Existing consolidated identity test suite keeps the original intent (7b95dbd: Retain owner-boundary checks while removing duplicated test layers; this PR extends the retained suite.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit baa836b adds src/infra/windows-process-start.ts:143 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: baa836b031a2; files: src/infra/windows-process-start.ts)

PR surface

Source 0, Tests +48. Total +48 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 48 0 +48
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 51 3 +48

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +3/-3; tests +48/-0 The production fix stays within existing expressions; added cases protect clock-step resilience and Node's integer timeout contract.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Clock adjustments can suppress or inflate synchronous Windows identity probes, affecting a limited platform-specific fallback path.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • 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 (5 earlier review cycles)
  • reviewed 2026-10-26T03:50:43.864Z sha 3167fa4c7c60fd1378d4dad24994c5e6d164d7be :: needs real behavior proof before merge. :: [P1] Round both remaining budgets before passing them to spawnSync
  • reviewed 2026-10-26T06:06:27.641Z sha 9a0e755704c69aff59c29aec1b39d36d8bf69ceb :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-26T07:11:26.703Z sha 9a0e755704c69aff59c29aec1b39d36d8bf69ceb :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T08:16:20.115Z sha 9a0e755704c69aff59c29aec1b39d36d8bf69ceb :: needs maintainer review before merge. :: none
  • reviewed 2026-10-27T03:43:43.133Z sha 1c264fa :: needs maintainer review before merge. :: none

Reviewed October 27, 2026, 12:59 AM ET / 04:59 UTC (Revision 6).

@SunnyShu0925
SunnyShu0925 force-pushed the fix/bug-137-windows-process-start-deadline-wall-clock branch from 3167fa4 to 9a0e755 Compare October 26, 2026 04:54
@clawsweeper

clawsweeper Bot commented Oct 26, 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 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 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 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/bug-137-windows-process-start-deadline-wall-clock branch from 9a0e755 to 1c264fa Compare October 27, 2026 02:28
@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 added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawtributors PR from a clawtributor P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants