Skip to content

fix: preserve operation budgets across wall-clock changes - #186484

Merged
obviyus merged 18 commits into
mainfrom
fix/monotonic-deadlines
Oct 28, 2026
Merged

obviyus merged 18 commits into
mainfrom
fix/monotonic-deadlines

Conversation

@obviyus

@obviyus obviyus commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes premature timeouts, extended waits, and delayed node-stat checkpoints when the wall clock changes during an operation.

User Impact

Selected browser, media, agent, Gateway, and CLI operations keep their original elapsed-time budgets across NTP corrections or manual clock changes. Persisted timestamps and user-facing dates keep their existing meaning. This is a bounded first cutover, not a claim that every wall-clock elapsed measurement in OpenClaw is fixed.

Why This Change Was Made

src/shared/monotonic-time.ts owns core process-local clock readings and primitive deadline arithmetic. Bundled extensions use the platform's performance.now() directly, without adding plugin SDK exports. The supervisor-local allocating deadline helper is removed. Existing operation owners still control normalization, polling, pause/resume, cancellation, and rounding; no timeout ceiling changes.

The shipped provider-operation DTO remains epoch-valued and serializable. Its
owner keeps private monotonic anchors across bundled SDK chunks; legacy/frozen
or deserialized DTOs are translated on admission, and public epoch edits are
honored. MCP normalizes fractional remaining time at its native integer-only
timeout boundary. Neither change adds a public field or changes a timeout ceiling.

Original contributor fix commits are preserved before the owner cutover. Credit to SunnyShu0925 and mikasa0818.

Absorbed sites

Original PR Site
#186039 Browser request pause/resume accounting
#186134 Media provider operation creation, requests, and polling; matching fal queue reader
#186412 Native subagent dispatch reconciliation
#184716 Node host-stat checkpoint cadence, separate from durable sample timestamps
#184613 Embedded runner abort/drain settlement
#184576 CLI Gateway suspend wait
#184525 Buzz setup reload verification
#182064 Discord Gateway READY wait

Source-PR audit: the five Sunny PRs are now closed externally, unmerged. The
three mikasa PRs remain open and are covered for closure after this lands.
None had assignees or maintainer-authored commits; original authorship is retained.

The same owner also replaces local clock reads from the already-merged fixes #182778, #169360, #184212, #184293, #184116, #185704, #185753, #186037, #186388, #186390, #185290, #185327, #184711, and #185146. Their existing epoch/reporting conversions remain intact.

Additional mechanical local waits: browser launch/navigation/tab discovery/action/download budgets; MCP initialization; Claw agent availability and plugin reload clients; Control UI document/onboarding observation; Gateway CI-detail request and node dispatch drain budgets; ClawHub skill download, APNs tunnel, and Tailscale readiness; meeting audio/speech prerequisites; node-worker exit; setup recommendation search; FaceTime helper authentication, Google Meet browser creation, Slack startup authentication, and shared transport/QA health waits.

Not fixed here

Evidence

Sanitized clock-step captures and detailed boundaries.

CI fixture repairs and inherited-blocker comparisons.

Runtime builds and focused checks run in secretless node:24.22.1 Docker isolation. Clock steps are injected by overriding Date.now() inside only the process under test; native timers, performance.now(), and the host/system clock are unchanged.

Boundary Main under a clock step Candidate and no-step control
Built CLI gateway suspend --wait 1 against a busy Gateway fixture Forward: one prepare, exits early. Backward: 21 prepares spanning 5.017s. Control/forward/backward remain within the original window; prepare spans 0.804–0.913s.
Built Gateway + browser open against synthetic CDP Forward: returns the requested URL before a delayed redirect commits. Control and stepped candidate return the committed redirected URL.
Built Gateway Discord adapter, synthetic REST/WS Forward: reconnects after 0.258s. Backward: still no READY timeout after 17.5s. Control/forward/backward reconnect at 15.10–15.26s, retaining the 15s budget. Not live Discord-service proof.
Built Gateway node telemetry and durable device.pair.list Retained baseline: forward checkpoints early; backward remains stale past the 5-minute cadence. Two paired nodes per mode: control/forward/backward retain 512 at 285s and checkpoint 300 by 305s. Original 300000ms interval unchanged.
Built public provider-http SDK / shared clock A 100ms operation expires immediately after +60s; −60s inflates its remaining budget to 60100ms. All modes retain approximately 100ms and expire with elapsed time. SDK boundary regression, not Gateway media E2E.

The media Gateway attempt reached video_generate, but fal's SSRF policy rejected
the loopback fixture and then its explicit proxy endpoint, including with HTTPS
and a task-owned CA. No guard was bypassed. Media therefore uses the shared-owner
regression above plus the provider consumer suite. Subagent reconciliation has
an owning spawn-seam regression that fails on main and passes here; it was not
independently triggered through a shipped command. Buzz's authenticated
post-write setup hook and embedded stuck-recovery phase likewise use the shared
clock regression and focused consumer suites, not an unobserved E2E claim.
No daemon paths are changed.

Latest no-export cutover rerun: 430 passed across 28 files, including browser, Buzz, Discord, memory, Slack, FaceTime, and internal QA consumers. Earlier timing-consumer checks passed 570 cases across 35 files, retaining 1 existing platform/root-dependent skip.
The nested browser pause and ambiguous subagent dispatch regressions fail on
the original implementation for their intended timeout/acceptance assertions.
Both runtime builds, targeted Oxfmt/Oxlint (including the repaired browser test's type-aware lint), and git diff --check passed.

Against the merge base: production +291/−188 (479 changed, net +103), tests
+121/−121 (net 0), docs +10. Growth is primarily core shared imports,
private provider anchors, and separate node receipt/deadline state; the old
allocating helper is removed. No code/test/timeout ceiling or baseline is
increased. The time-runtime facade is byte-identical to base; internal QA and
transport-ready facade edits preserve their exported signatures byte-for-byte.

Changed-test wall durations with one worker: browser 0.47s, spawn 9.27s,
onboarding 4.86s, fal 6.69s, provider deadlines 0.72s, node checkpoints 0.65s,
suspend CLI 0.46s, supervisor subprocess 15.52s. The supervisor case exercises
the real native process-group retirement grace. Hosted CI timings are reported
by the checks on this PR.

The first completed CI run
found Date-controlled consumer fixtures and a typed Promise-rejection issue;
those are repaired and passed focused checks without production changes.
Two unrelated failures also reproduce on both the pristine base and candidate:

Neither unrelated path is changed or suppressed here. The completed run has
zero cancelled jobs; a green aggregate CI gate is not claimed.

The next completed run, 40630944182
at 74422ea, confirms the repaired fixture/lint jobs pass. Its aggregate is red
with zero cancelled jobs: the same broker and reply failures, plus
plugin capture custody
(plugin-source-capture-directory.test.ts, missing legacy index.cjs).
The latter is in an untouched path and has no established base attribution;
it is not silently classified as inherited or patched here.

For that third red, pristine-base attribution checks pass: 34/34 complete-suite
cases and ten independent custody runs (30/30 cases). The hosted ENOENT therefore
remains un-attributed, not proven inherited and not override-ready on that basis.

Final-head run 40634354654
at f706ffd5892d9fa1ca6d12c67ea5c5e9e36d34a8 is completed. Its only two
failing test jobs exactly match the proven base/candidate broker and QA reply
receipts; zero jobs were cancelled. The legacy capture ENOENT does not fail
this final run. The raw aggregate gate remains red; the maintainer owns any
override. Exact final-job matches.
The final head has been reviewed ready at 4/6.

Revert is a two-way door: no stored-data or config migration. Blast radius is local timeout/cadence enforcement in the listed callers plus plugins using the shared provider-operation deadline contract; an incorrect clock-domain conversion can cause premature or extended waits.

SunnyShu and others added 15 commits October 28, 2026 08:07
…otonic clock

Seed and consume the provider-operation deadline with performance.now()
instead of the wall clock, so a host clock jump (NTP correction, VM
pause/resume) no longer corrupts the remaining-time budget. This is the
canonical owner of the deadline, so it heals all 30+ media-understanding
providers at once. Keeps the deadline payload, timeout policy, and
downstream provider helpers unchanged.
…onic clock

reconcileSubagentAgentDispatch anchored its reconciliation deadline and the
remaining-budget reads to Date.now() (wall clock), then fed the result into
two monotonic consumers: the Gateway RPC timeout (callGateway timeoutMs) and
the inter-iteration delay (node:timers/promises setTimeout). A wall-clock step
(NTP sync) landing between two loop iterations distorts remainingMs: a forward
step shrinks it below zero and prematurely kills a healthy reconciliation,
while a backward step stretches the Gateway timeout and the delay well past the
intended budget.

The deadline is a pure in-process closure variable (never serialized, persisted,
or reported across processes), so it is safe to anchor to performance.now(). All
three reads now use the monotonic clock, keeping the budget stable across wall
steps.

Regression test drives the reconcile loop through callNativeSubagentGateway and
steps Date.now() forward 10s between two iterations; pre-fix it aborts with
"gateway timeout after 5000ms", post-fix the run is admitted and the per-call
Gateway RPC timeout stays at the 800ms interval cap.
…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.
…ttle deadline

abortAndDrainCapturedEmbeddedAgentRun seeded its settle deadline from
Date.now() and computed the remaining budget with Date.now(), but the
budget is consumed by monotonic setTimeout/AbortSignal.timeout paths
(waitForCapturedSessionNativeAttemptEnd / waitForReplyOperationOwnerSettlement).
A wall-clock rollback between the seed and the read inflates the budget,
stretching stuck-recovery owner settlement far past its configured window.

Use performance.now() for both the seed and the remaining-budget read so the
deadline stays in the monotonic clock domain of its consumers.
…onic clock

reconcileSubagentAgentDispatch anchored its reconciliation deadline and the
remaining-budget reads to Date.now() (wall clock), then fed the result into
two monotonic consumers: the Gateway RPC timeout (callGateway timeoutMs) and
the inter-iteration delay (node:timers/promises setTimeout). A wall-clock step
(NTP sync) landing between two loop iterations distorts remainingMs: a forward
step shrinks it below zero and prematurely kills a healthy reconciliation,
while a backward step stretches the Gateway timeout and the delay well past the
intended budget.

The deadline is a pure in-process closure variable (never serialized, persisted,
or reported across processes), so it is safe to anchor to performance.now(). All
three reads now use the monotonic clock, keeping the budget stable across wall
steps.

The regression folds into the existing ambiguous-dispatch reconcile case: its
pending replay steps Date.now() forward 10s and the case still requires the
admitted run plus the 800ms per-call Gateway RPC cap, so the suite keeps its
real 800ms interval wait and adds no test lines.
@obviyus obviyus self-assigned this Oct 28, 2026
@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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: slack Channel integration: slack channel: telegram Channel integration: telegram gateway Gateway runtime extensions: memory-core Extension: memory-core extensions: memory-lancedb Extension: memory-lancedb cli CLI command changes commands Command implementations agents Agent runtime and tooling extensions: fal plugin: google-meet plugin: file-transfer labels Oct 28, 2026
obviyus added a commit that referenced this pull request Oct 28, 2026
…lock (#186531)

fix(team-reports): keep the report worker's reply budget on the monotonic clock

The Team Reports runner measured the time left for a worker reply with Date.now, so a forward wall-clock step made a healthy report worker time out. The budget now uses performance.now, as the other extension budgets have since the #186484 sweep.

Evidence: real built Gateway with the Team Reports plugin enabled, native report and SQLite workers, and a local HTTP summary provider. With Date.now stepped forward 2 hours inside the process only, main failed with "worker task timed out" (twice); with this change the reports succeeded (twice). No-step controls succeeded twice on each ref, and all successful runs stored valid summaries. Details: #186531 (comment).

Thanks @SunnyShu0925.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 29, 2026
…6829)

fix(memory-core): keep the session-index deadline on the monotonic clock

The memory session-index pass recomputed its pending publication deadline with Date.now, so a forward wall-clock step made the index publish early (or a backward step delayed it). The three memory-core deadline sites now use performance.now(), as the other extension budgets do since #186484.

Evidence: built Gateway with real transcript appends and SQLite FTS publication. At 280 s on the monotonic clock, Date.now was stepped forward 120 s inside the process only, followed by another real append. Main rearmed for 0 ms and published at once (twice); with this change it rearmed for 20,000 ms, was still unpublished at 299,999 ms and published at 300 s (twice). No-step controls published at 300 s on both refs, and memory search found the marker in every run. Details: #186829 (comment).

Thanks @SunnyShu0925.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 29, 2026
…lock (#186850)

fix(browser): keep the download quiet window on the monotonic clock

The browser plugin measured the download quiet window with Date.now, so a forward wall-clock step while a download was in progress ended the window early and a following download was missed. The window now uses performance.now(), as the other extension budgets do since #186484.

Evidence: built Gateway with real Chromium over the browser HTTP bridge. A process-local +10 s Date.now step was placed between the window's timestamp write and its elapsed-time read, and logs confirm the order. Main missed the second download (twice); with this change both files were captured (twice). No-step controls captured both on each ref, and the system clock was not touched. Details: #186850 (comment).

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…186679)

test(deepgram): fake the monotonic clock in the audio-flux deadline test

openclaw#186484 (f4034e1) moved provider operation budgets onto the monotonic clock. The Deepgram audio-flux deadline test faked Date and timers but not performance, so its fake-time advances no longer used up the budget, and the "keeps decoding" case hung until the 120 s test timeout. It failed on every pull request whose CI selected the Deepgram lane. The fixture now also fakes performance. Production code is unchanged.

Evidence: the full test file passed 5 of 5 runs on 4996b42 (before the sweep), failed 5 of 5 on f4034e1 and on main 20badbb, and passed 3 of 3 with this change. The hosted Deepgram lane passed 10 tests, with the deadline case in 1176 ms. The other files the sweep touched were checked, and none fail the same way. Details: openclaw#186679 (comment).

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…penclaw#177179)

fix(gateway): keep queued RPC deadlines on the monotonic clock

Queued work from RPC sources measured its deadline with Date.now, so a wall-clock step made queued items expire early (clock moved forward) or run after they should have expired (clock moved back). The deadline now uses the shared monotonic owner, src/shared/monotonic-time.ts, from the openclaw#186484 sweep.

Evidence: built Gateway differential with Date.now stepped inside the process only. On main, queued work that had expired still ran after a backward step, and work expired early after a forward step (twice each); with this change the elapsed budgets held, and the no-step control behaves the same on both refs. Details: openclaw#177179 (comment).

Thanks @SunnyShu0925.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…lock (openclaw#186531)

fix(team-reports): keep the report worker's reply budget on the monotonic clock

The Team Reports runner measured the time left for a worker reply with Date.now, so a forward wall-clock step made a healthy report worker time out. The budget now uses performance.now, as the other extension budgets have since the openclaw#186484 sweep.

Evidence: real built Gateway with the Team Reports plugin enabled, native report and SQLite workers, and a local HTTP summary provider. With Date.now stepped forward 2 hours inside the process only, main failed with "worker task timed out" (twice); with this change the reports succeeded (twice). No-step controls succeeded twice on each ref, and all successful runs stored valid summaries. Details: openclaw#186531 (comment).

Thanks @SunnyShu0925.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…nclaw#186829)

fix(memory-core): keep the session-index deadline on the monotonic clock

The memory session-index pass recomputed its pending publication deadline with Date.now, so a forward wall-clock step made the index publish early (or a backward step delayed it). The three memory-core deadline sites now use performance.now(), as the other extension budgets do since openclaw#186484.

Evidence: built Gateway with real transcript appends and SQLite FTS publication. At 280 s on the monotonic clock, Date.now was stepped forward 120 s inside the process only, followed by another real append. Main rearmed for 0 ms and published at once (twice); with this change it rearmed for 20,000 ms, was still unpublished at 299,999 ms and published at 300 s (twice). No-step controls published at 300 s on both refs, and memory search found the marker in every run. Details: openclaw#186829 (comment).

Thanks @SunnyShu0925.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…lock (openclaw#186850)

fix(browser): keep the download quiet window on the monotonic clock

The browser plugin measured the download quiet window with Date.now, so a forward wall-clock step while a download was in progress ended the window early and a following download was missed. The window now uses performance.now(), as the other extension budgets do since openclaw#186484.

Evidence: built Gateway with real Chromium over the browser HTTP bridge. A process-local +10 s Date.now step was placed between the window's timestamp write and its elapsed-time read, and logs confirm the order. Main missed the second download (twice); with this change both files were captured (twice). No-step controls captured both on each ref, and the system clock was not touched. Details: openclaw#186850 (comment).

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: buzz channel: discord Channel integration: discord channel: slack Channel integration: slack cli CLI command changes commands Command implementations docs Improvements or additions to documentation extensions: browser extensions: fal extensions: litellm gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: facetime FaceTime plugin plugin: file-transfer plugin: google-meet proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: L 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.

3 participants