Repository navigation
fix(update-repair): use monotonic clock for repair turn budgets - #186818
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 changesUses the existing monotonic clock helpers for repair deadlines and elapsed attempt durations. Example: The host clock advances 610 seconds during a repair with a 600-second overall budget.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a concrete clock-domain bug still present on current main, with no introduced defects found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherInstallation triage passes validation results, configured inference routes, cancellation, and time budgets through the repair loop to embedded agent execution; Doctor validation determines the final repair outcome. flowchart TD
A[CLI triage] --> B[Repair loop]
C[Delegated worker] --> D[Inference selection]
B --> D
D --> E[Embedded repair turn]
E --> F[Doctor validation]
F --> G[Repair result]
Technical reviewBest possible solution: Land the focused monotonic-clock correction through the existing repair owners and reconcile the overlapping runtime-only PR afterward. Do we have a high-confidence way to reproduce the issue? Current-main deadline arithmetic directly reproduces the budget collapse under a forward Date.now() step, and the contributor supplies a matching CLI before/after trace; this review ran no target code. Is this the best way to solve the issue? This is the smallest complete fix: repair budgets must measure elapsed time, and replacing each independent wall-clock seed and read with the shared monotonic owner restores that invariant without adding machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ee888504a371. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +10, Tests +118. Total +128 across 8 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 (4 earlier review cycles)
Reviewed October 29, 2026, 8:19 AM ET / 12:19 UTC (Revision 5). |
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
e51ddfd to
9be65d5
Compare
Repair turn budgets were seeded from Date.now() and read back as `deadline - Date.now()`, but every consumer of those numbers is monotonic: setTimeout, the undici route-probe timeouts, and the embedded turn timer. A host clock correction therefore rewrote the remaining budget without any time passing: a forward step collapsed it to `Math.max(1, ...)` = 1 ms, aborting a healthy repair with the reason an expired budget produces, and a backward step let the turn keep running past the granted budget. Seed and read every repair deadline through the canonical owner, src/shared/monotonic-time.ts, in the delegated worker (update-repair-turn-worker.ts), the route-probe selector (update-repair-inference.ts), the CLI repair loop (update-repair-agent.ts), and the per-candidate embedded turn timeout in update-repair-agent.runtime.ts. Each of those re-seeded downstream of the previous one, so a single remaining Date.now() read collapsed the budget no matter how correct the others were. Remaining time is floored to whole milliseconds where it feeds a `<= 0` guard, so the abort reason keeps the boundary it had on integer wall time. Attempt durations move to the same clock because a backward step made `Date.now() - started` negative, which the non-negative wire schema rejects. Budget values, clamping, the IPC contract, and the abort reasons are unchanged.
9be65d5 to
fba4151
Compare
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…#190298) Complete the repair clock-domain correction after #190064: use the existing shared monotonic clock for loop, inference-probe, and delegated-worker budgets and elapsed attempt durations. Preserve budget defaults, cancellation, live authority checks, IPC durations, and absolute timestamps. Adapted from SunnyShu0925's #186818 after reviewing its complete diff and reviews. Forward/backward clock-jump regressions fail on the original owners and pass with the fix. Allocate 106 regression lines because the three owners independently seed and consume their budgets and need distinct boundary proof. Focused repair and consumer tests pass, and local autoreview found no P0-P2 issues. Live Gateway and stable-upgrade execution were outside the task's production-host constraint. Also remove two redundant default void type arguments in an unchanged test to repair the inherited core-lint failure exposed by this PR's CI. Focused lint, all 19 tests in that file, and independent review pass. Co-authored-by: SunnyShu0925 <[email protected]> Co-authored-by: steipete <[email protected]>
|
Thanks @SunnyShu0925 for the complete monotonic-budget fix and the clock-step investigation. The remaining repair-loop, inference-selection, and delegated-worker conversion has landed in #190298 as ed052ccb0612, completing the runtime fix from #190064. Your coauthor credit is included in the squash commit. Forward/backward clock-jump regressions pass in all three owners, and exact-head CI is green. Closing this as superseded by the landed replacement. |
…openclaw#190298) Complete the repair clock-domain correction after openclaw#190064: use the existing shared monotonic clock for loop, inference-probe, and delegated-worker budgets and elapsed attempt durations. Preserve budget defaults, cancellation, live authority checks, IPC durations, and absolute timestamps. Adapted from SunnyShu0925's openclaw#186818 after reviewing its complete diff and reviews. Forward/backward clock-jump regressions fail on the original owners and pass with the fix. Allocate 106 regression lines because the three owners independently seed and consume their budgets and need distinct boundary proof. Focused repair and consumer tests pass, and local autoreview found no P0-P2 issues. Live Gateway and stable-upgrade execution were outside the task's production-host constraint. Also remove two redundant default void type arguments in an unchanged test to repair the inherited core-lint failure exposed by this PR's CI. Focused lint, all 19 tests in that file, and independent review pass. Co-authored-by: SunnyShu0925 <[email protected]> Co-authored-by: steipete <[email protected]>
What Problem This Solves
When
openclaw updatefails, repair runs against a budget seeded from the wall clock but consumed by monotonic timers, so a clock step during the repair either aborts a healthy repair or lets it run past the budget the operator granted.update-repair-turn-worker.ts(delegated worker deadline),update-repair-inference.ts(route-probe deadline),update-repair-agent.ts(CLI repair loop: wall deadline, route-prep budget, per-turn budget, attempt duration), andupdate-repair-agent.runtime.ts(per-candidate embedded turn timeout). The consumers are monotonic:setTimeout, the undici probe timeouts, the embedded turn timer. A forward step collapses the remaining budget —Math.max(1, …)reduces it to 1 ms and a healthy repair dies with the reason an expired budget produces — and a backward step inflates it.Date.now()read collapsed the budget no matter how correct the others were: the loop hands the runtime atimeoutMs, and the runtime turned that back into its own wall-clock deadline.src/shared/monotonic-time.ts(monotonicDeadlineAfter/remainingMonotonicMs/monotonicNow), which the repository already uses for this invariant. Remaining time is floored to whole milliseconds where it feeds a<= 0guard, so the abort reason keeps its exact boundary.Math.max(1, …)/Math.min(…)clamping, thewall-clock-budgetandper-turn-budgetabort reasons, and the fixed-durationsetTimeoutarms. Attempt durations move to the same clock because a backward step madeDate.now() - startednegative, which the non-negative wire schema rejects.User Impact
A repair that can clear the failure now finishes and reports
repairedwhatever the host clock does mid-repair: no 1 ms abort after a clock correction, and no overrun after a rewind. Invisible when the two clocks agree, which is the normal case.Evidence
End to end, shipped CLI, real repair, real Doctor oracle.
openclaw triage --rununder a pty on an isolated state dir whose config lists an unreachable MCP server, so Doctor lint fails withcore/doctor/runtime-tool-schemasand the loop has a real error to clear. The repair model is a deterministic local OpenAI-compatible endpoint: the model is not under test, while the repair loop, tool dispatch,writetool and Doctor validation are the shipped paths. The clock step is an--importpreload that adds 610 s toDate.now()once the route probe is in flight, whileperformance.now()keeps running from boot. Both builds come from one tree, differing only in the eight files this PR touches (grep -c remainingMonotonicMs dist/update-repair-agent-*.mjs→ 0 before, 3 here).The preload sidecar that arms the step logged
[clock-step] armed at 2026-10-29T11:57:59.995Z offset=610000msfor the last run.Loop and turn deadlines, unit level. New cases, red on the pre-fix sources and green here (same test files, only the source reverted). Reverting just the route-prep read makes the first case fail on
expect.closeTo(600_000, -2)against a received1; reverting the whole source makes it fail earlier,{ status: 'aborted' }vs{ status: 'repaired' }:Route probe and route prep, ±5 s steps. New cases added here, existing source reverted for the pre-fix column:
Targeted suites
update-repair-agent,.runtime,-turn-worker,-inference: 39 tests green. Gates:oxlintclean,oxfmt --checkclean,check:test-lines-ratchetOK,check-plugin-sdk-exportsOK on the build of this tree. A repo-widetsgorun does not work in this checkout (Declaration input escapes checkoutthrough the worktree'snode_modulessymlink); the change adds no exported type and only same-type substitutions.Not tested. The end-to-end run exercises the in-process loop: the parent-to-worker
turnIPC path has no in-repo producer outside the Windows repair probe, so the worker's deadline is covered by its unit cases only, and the runtime's per-candidate deadline is unit-only as well because the injected step lands before that site seeds its own deadline. The clock step is an injectedDate.now()offset, not a real NTP correction, and the model was the stub endpoint described above.