Skip to content

fix(update-repair): use monotonic clock for repair turn budgets - #186818

Closed
SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/update-repair-turn-budget-monotonic
Closed

SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/update-repair-turn-budget-monotonic

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When openclaw update fails, 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.

  • Four places did it: 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), and update-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.
  • Each site re-seeded downstream of the previous one, so one remaining Date.now() read collapsed the budget no matter how correct the others were: the loop hands the runtime a timeoutMs, and the runtime turned that back into its own wall-clock deadline.
  • Fix: seed and read every repair deadline through the canonical owner 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 <= 0 guard, so the abort reason keeps its exact boundary.
  • Not changed: budget values and defaults, the IPC contract, the Math.max(1, …) / Math.min(…) clamping, the wall-clock-budget and per-turn-budget abort reasons, and the fixed-duration setTimeout arms. Attempt durations move to the same clock because a backward step made Date.now() - started negative, which the non-negative wire schema rejects.

User Impact

A repair that can clear the failure now finishes and reports repaired whatever 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 --run under a pty on an isolated state dir whose config lists an unreachable MCP server, so Doctor lint fails with core/doctor/runtime-tool-schemas and 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, write tool and Doctor validation are the shipped paths. The clock step is an --import preload that adds 610 s to Date.now() once the route probe is in flight, while performance.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).

# control: build before this commit, no clock step
Embedded repair repaired: Doctor lint reports no errors.        # exit 0

# build before this commit, +610 s step inside the inference window
Embedded repair aborted: 1 Doctor lint error(s): Configured MCP server "broken" could not
expose runtime tools for schema validation.
wall-clock-budget                                               # exit 2, config untouched

# this commit, same +610 s step
Embedded repair repaired: Doctor lint reports no errors.        # exit 0, mcp entry removed

The preload sidecar that arms the step logged [clock-step] armed at 2026-10-29T11:57:59.995Z offset=610000ms for 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 received 1; reverting the whole source makes it fail earlier, { status: 'aborted' } vs { status: 'repaired' }:

 × keeps the turn budget when the wall clock steps inside the inference window
 × keeps the remaining turn budget when the wall clock steps between candidates
   expected 1 to be greater than 9000

Route probe and route prep, ±5 s steps. New cases added here, existing source reverted for the pre-fix column:

step        pre-fix route-probe => post-fix    pre-fix route-prep => post-fix
-5000ms     15000ms (inflated)   10000ms       35000ms (inflated)  30000ms
+5000ms     5000ms  (collapsed)  10000ms       25000ms (collapsed) 30000ms

Targeted suites update-repair-agent, .runtime, -turn-worker, -inference: 39 tests green. Gates: oxlint clean, oxfmt --check clean, check:test-lines-ratchet OK, check-plugin-sdk-exports OK on the build of this tree. A repo-wide tsgo run does not work in this checkout (Declaration input escapes checkout through the worktree's node_modules symlink); 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 turn IPC 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 injected Date.now() offset, not a real NTP correction, and the model was the stub endpoint described above.

@clawsweeper

clawsweeper Bot commented Oct 28, 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. P2 Normal backlog priority with limited blast radius. 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. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: The repair aborts with wall-clock-budget despite little elapsed time.
  • After: The repair retains its elapsed-time budget and can finish successfully.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused correction with shipped-entry-point before/after evidence, distinct regression coverage, and successful exact-head gates.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied isolated shipped-CLI trace exercises the repair loop, real tool dispatch, and Doctor oracle against a local deterministic provider under an injected +610-second clock step, changing an aborted repair into a successful repair; delegated IPC and a clock step between runtime candidates have supporting unit coverage only.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A host clock correction can abort a repair that still has elapsed-time budget remaining.
Reason: The patch restores existing bounded-repair behavior while retaining budget defaults, execution policy, IPC shape, and validation ownership.

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
Reviewed head: fba4151e4bb849c4c43d86d9947287917a61c3fb

Before merge

None.

Findings

None.

Agent review details

How this fits together

Installation 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]
Loading

Technical review

Best 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

  • Repair-loop deadlines and attempt durations keeps the original intent (d12357e: Provide bounded configured-inference repair with caller-owned validation; later specialization retains one-turn execution.)
  • Embedded candidate deadline keeps the original intent (545089c: Keep inference outside update admission while preserving optional post-failure repair budgets and cancellation.)
  • Inference route-probe deadline keeps the original intent (d12357e: Select configured authenticated inference within the repair budget; subsequent refactoring preserves the explicit remaining timeout.)
  • Delegated worker deadline keeps the original intent (df15ee3: Execute a bounded owner-delegated turn while retaining live requester and update-run authority.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d12357e adds src/infra/update-repair-agent.ts:188 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d12357eaa4b6; files: src/infra/update-repair-agent.ts)
  • Dallin Romney: Raw commit df15ee3 adds src/infra/update-repair-turn-worker.ts:33 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: df15ee3a68a0; files: src/infra/update-repair-turn-worker.ts)

PR surface

Source +10, Tests +118. Total +128 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 22 12 +10
Tests 4 119 1 +118
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 141 13 +128

Review metrics

Metric Value Why it matters
Production versus regression tests Production +22/-12; tests +119/-1 Small substitutions reuse the existing clock owner; the tests protect separately seeded loop, probe, worker, and fallback-candidate deadlines.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Clock corrections can prematurely abort optional installation repair, with a limited trigger and no demonstrated core-runtime outage.
  • 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 (4 earlier review cycles)
  • reviewed 2026-10-28T14:53:28.302Z sha e51ddfd3ed9238fd8da094e37034740d04ed6177 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-29T07:01:28.452Z sha e51ddfd3ed9238fd8da094e37034740d04ed6177 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-29T08:49:19.045Z sha e51ddfd3ed9238fd8da094e37034740d04ed6177 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-29T12:05:27.820Z sha fba4151 :: needs maintainer review before merge. :: none

Reviewed October 29, 2026, 8:19 AM ET / 12:19 UTC (Revision 5).

@clawsweeper

clawsweeper Bot commented Oct 29, 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: 🦪 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 29, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/update-repair-turn-budget-monotonic branch from e51ddfd to 9be65d5 Compare October 29, 2026 11:28
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.
@SunnyShu0925
SunnyShu0925 force-pushed the fix/update-repair-turn-budget-monotonic branch from 9be65d5 to fba4151 Compare October 29, 2026 11:37
@clawsweeper

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

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 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 29, 2026
roboclaw-bot added a commit that referenced this pull request Nov 1, 2026
…#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]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

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.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 2, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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