Repository navigation
fix(gateway): keep node host-stats checkpoint deadline on the monotonic clock - #184716
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 schedules node telemetry checkpoints using retained monotonic deadlines while preserving persisted wall-clock timestamps. Example: The Gateway clock moves backward by 30 seconds while a node continues reporting memory statistics.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current-main checkpoint scheduling bug, addresses the earlier findings, and has no actionable review findings; the CI gate remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherNode telemetry enters the Gateway through node.host.stats events; NodeRegistry updates live views immediately and checkpoints samples through the existing pairing writer for durable device listings. flowchart LR
A[Node telemetry] --> B[Gateway event handler]
B --> C[NodeRegistry]
C --> D[Live catalog and broadcasts]
C --> E[Monotonic checkpoints]
E --> F[Pairing worker]
F --> G[Durable device listings]
Technical reviewBest possible solution: Retain receipt-time monotonic deadlines in the existing checkpoint owner and merge this focused fix after the normal CI gate passes. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the clock-sensitive path, and contributor-supplied Gateway traces demonstrate both clock directions; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch is the smallest complete repair using the existing owner: capture deadlines at receipt, associate them with the written sample, and retain them across rescheduling. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9969b7cc1025. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +33, Tests +68. Total +101 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel 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 (3 earlier review cycles)
Reviewed October 26, 2026, 1:03 PM ET / 17:03 UTC (Revision 4). |
f5085d8 to
3887047
Compare
3887047 to
663e15c
Compare
|
🦞👀 Re-review progress:
|
…ic clock NodeHostStatsCheckpoints throttles host-telemetry persistence to one write per node every five minutes, and that deadline was read from the wall clock both when arming the timer and again in the callback. A backward system-clock correction therefore left the checkpoint slipping by the size of the correction. Pair each received sample's persisted receipt with the monotonic clock while the two are still in sync (record), snapshot that deadline with the sample being written, and promote it once the write succeeds. The timer delay, the fire-time check, and every later schedule reuse the stored deadline instead of re-reading the wall clock. Capturing at receipt (rather than at write time) matters because the timer writes a buffered sample: converting when that write completes would fold a clock step that happened since the sample was received into the following budget. Later schedules must also not re-derive the deadline, or a report arriving after a jump (the normal 60s telemetry cadence) or a timer firing a millisecond early would push an armed deadline out. updatedAtMs stays a persisted wall-clock epoch; the monotonic deadline is in-memory only and the public API (record / forget / close) is unchanged. Regression coverage folds three cases into the existing host stats checkpoints suite: a backward jump with the node going quiet, with telemetry still arriving, and a write that follows the jump, each asserting nothing persists before the armed deadline and the next checkpoint stays anchored to its receipt.
663e15c to
f1cdec4
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Closing: this change has been absorbed into maintainer PR #186484 (monotonic deadlines cutover). My original commit is preserved there with credit. Thanks! |
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]>
…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
When a node reports host telemetry (CPU/memory) to the Gateway,
NodeHostStatsCheckpointsthrottles disk persistence to one write every 5 minutes per node. That deadline lived on the wall clock: the timer delay wasMath.max(0, deadline - Date.now())and the callback re-readDate.now()to decide whether the budget had elapsed. A clock correction therefore moved the budget: a backward jump slipped the checkpoint by the jump size, and a forward jump fired it early.record), snapshot that deadline with the sample being written, and promote it once the write succeeds. Both thesetTimeoutdelay and the fire-time check then run onperformance.now(), and later schedules reuse the stored deadline instead of re-reading the wall clock.src/gateway/node-registry.host-stats.ts(NodeHostStatsCheckpointsand its private checkpoint type) plus three cases folded into the existinghost stats checkpointssuite insrc/gateway/node-registry-pairing.test.ts.updatedAtMsremains a persisted wall-clock epoch (compared across restarts/processes), and the public API (record/forget/close) is untouched.Why This Change Was Made
updatedAtMsis a persisted epoch written byupdateHostStats(params.observedAtMs ?? Date.now()) and stored throughpersistHostStats, so its seed cannot becomeperformance.now()without breaking the cross-restart contract. The fix keeps the epoch as the source of truth and derives a parallel monotonic deadline (savedAtMonotonicMs) at the receipt boundary, likesrc/infra/update-doctor-deadline.ts.Deriving it once is what makes the budget stable. A live node publishes telemetry every 60s, so deriving on each
schedule()would re-read the corrected wall clock on the next report and move an armed deadline again; asetTimeoutfiring a millisecond early would do the same through the re-arm path. The timer also writes a buffered sample, so converting at write time would fold a clock step since that sample's receipt into the following budget — hence the receipt-time capture and the per-write snapshot.NodeHostStatsCheckpointsis the only owner that arms the timer, so the fix lives there: no new parser, policy branch, configuration surface, or persisted state.User Impact
Gateway operators get reliable node host-telemetry persistence: after a clock correction in either direction, CPU/memory stats still land in the store inside the 5-minute window anchored to the saved receipt instead of slipping or firing early.
Evidence
Runtime capture through the shipped entry points:
startGatewayServer(), a node-roleGatewayClientover loopback, thenode.event/node.host.statsframe, anddevice.pair.listfor the persisted node surface. Each row below is the same script with the checkpoint owner's wall clock stepped once while telemetry keeps arriving; the step is owner-scoped because this capture runs the Gateway and its clients in one process.origin/main(before)f1cdec(after)512(slipped)300(latest, on time)300(fired early)512(still waiting)300300(on time)Raw terminal output (backward step, current head / origin/main)
Raw terminal output (forward step, current head / origin/main)
Regression (folded into the existing
host stats checkpointssuite)origin/mainf5085d8(earlier revision)663e15c(earlier revision)All three assert that nothing persists before the armed deadline and that the next checkpoint stays anchored to its receipt.
Scope: all five node-registry test files pass (112 tests);
oxfmt/oxlintclean; no lockfile changes; no open PR touches this file.