Skip to content

fix(channels): keep status deadline on the monotonic clock across wall-clock jumps - #177155

Merged
roboclaw-bot merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/channels-status-deadline-wall-clock-178
Oct 19, 2026
Merged

roboclaw-bot merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/channels-status-deadline-wall-clock-178

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

channels.status can mis-report a healthy channel as timed out when the host wall clock jumps forward, and can inflate the remaining budget passed to plugin hooks when the wall clock rolls back. In src/gateway/server-methods/channels.ts, the per-plugin status deadline was seeded and read with Date.now() (wall clock) while the outer status call is bounded by raceWithTimeout using setTimeout. A wall-clock jump forward shrinks deadline - Date.now() (a healthy channel gets fenced as status timed out), while a rollback inflates it (a plugin hook receives an inflated remaining budget; the outer timeout still bounds asynchronous status work).

  • Problem: const deadline = Date.now() + timeoutMs seeds the deadline with the wall clock; remainingBudget = () => deadline - Date.now() reads it with the wall clock; the resulting remaining is passed as timeoutMs to plugin hooks, while the outer raceWithTimeout uses the original bounded duration. A wall-clock correction (NTP, manual, or container clock adjustment) between the seed and each read shifts the budget.
  • Solution: seed and read the deadline from the monotonic performance.now(), and Math.floor the returned budget so downstream AbortSignal.timeout/setTimeout consumers never receive a float. This matches the repo's canonical wall-clock-to-monotonic pattern (BUG-092/098/102/122 family).
  • What changed: channels.ts channelsHandlers["channels.status"] — 1 deadline seed, 1 budget read, 2 deadline comparisons, 1 Math.floor on the returned budget. Plus a regression test and two fixture adaptations in channels.status.test.ts / channels.status.test-helpers.ts.
  • What did NOT change: no parser/policy branch, no config surface, no public signature, no persistence layer. The three remaining Date.now() sites in this handler (lastProbeAt, now, ts) are wall-clock timestamps for display/recording, not deadline arithmetic.

Why This Change Was Made

The channel status deadline is entirely in-process — it never persists, never crosses a process boundary, and is never compared against a wall-clock epoch by another process (0 sqlite/kysely/bridge/worker hits). So the monotonic clock is the only correct clock for it. This matches the repo convention for the same wall-clock-vs-monotonic class (#155603, #155648, #155323, and the merged BUG-092/098/102/122 family).

  • Best fix: Yes. Seeding and reading from performance.now() is the minimal absorbed change; the single remainingBudget() closure is the canonical owner of the budget, and Math.floor there covers every downstream consumer (plugin hooks may pass the value to AbortSignal.timeout, which rejects floats).
  • Alternative: Re-reading the wall clock right before each check stays vulnerable to a jump between two reads; only a monotonic clock removes the skew.
  • Risk: Untested under real NTP step changes; the proof uses a deterministic ±60_000 ms wall-clock jump model over the real handler and fake monotonic clock.

User Impact

channels.status now fences status probes at their configured budget regardless of wall-clock correction mid-check, instead of discarding healthy probe results after a forward jump or inflating hook budgets after a rollback. Behavior is otherwise identical.

Evidence

Before / after — real channels.status handler, fake monotonic clock

The regression test drives the real channelsHandlers["channels.status"] handler through createChannelsStatusHarness with a 1000ms probe budget. It uses Vitest fake timers, lets the probe start, jumps the wall clock by ±60,000 ms (vi.setSystemTime, which changes wall time without advancing the fake monotonic clock), then advances the monotonic clock 600 ms. Only the deadline clock source differs between the runs.

same-input probe (timeout 1000ms, healthy hook resolves in 500ms, wall clock jumps ±60s) pre-fix Date.now() post-fix performance.now()
wall clock +60s (forward) healthy probe fenced as status timed out → probe: undefined healthy probe preserved → probe: { ok: true }
wall clock −60s (rollback) probe completes (no mis-report) probe completes (no mis-report)

Pre-fix: a forward wall-clock jump of 60s makes deadline - Date.now() negative, so the healthy channel's probe result is discarded and the channel is reported running with no probe. Post-fix: the monotonic deadline is unaffected by the wall-clock jump, and the healthy probe is preserved.

Regression test RED / GREEN

The regression test arms a 1000ms probe deadline, lets the 500ms probe start, jumps the wall clock +60s, and advances the monotonic clock 600ms.

$ node scripts/run-vitest.mjs src/gateway/server-methods/channels.status.test.ts -t "keeps the live probe deadline on the monotonic clock"   # pre-fix (Date.now)
 × keeps the live probe deadline on the monotonic clock when wall time jumps by 60000 ms
   AssertionError: expected { lastStartAt: null, …(10) } to match object { probe: { ok: true, …(1) } }
   -   "probe": {
   +   "probe": undefined,
 FAIL  (1 failed | 49 passed)

$ node scripts/run-vitest.mjs src/gateway/server-methods/channels.status.test.ts   # post-fix (performance.now)
 ✓ keeps the live probe deadline on the monotonic clock when wall time jumps by -60000 ms
 ✓ keeps the live probe deadline on the monotonic clock when wall time jumps by 60000 ms
 Test Files  1 passed (1)   Tests  50 passed (50)

The RED assertion shows exactly the budget-collapse symptom: after a +60s wall jump, the healthy channel's probe is dropped (probe: undefined) instead of { ok: true }.

What was not tested

  • Real NTP step changes on a live host (proof uses a deterministic fake-timer jump over the real handler and fake monotonic clock).
  • Third-party channel plugins that interpret the injected timeoutMs as a wall-clock deadline; the fix keeps the value an integer number of remaining milliseconds, matching the pre-existing contract.

Open PR collision check

Searched open PR topics and changed-file lists for src/gateway/server-methods/channels.ts. No open PR touches this file or the channels.status deadline path; the existing channels PRs (e.g. #172139, #161466, #172959) are unrelated refactors of other channel surfaces.

…l-clock jumps

Ref: BUG-178-channels-status-deadline-wall-clock (local finding)
@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review blocked

Automated review did not run, so no review verdict was produced.

Reason: The input-safety check rejected material in this revision. No detected value, path, or scanner output is reproduced here.

Automatic review is on hold, including after source changes. Request a fresh re-review after resolving the failure; maintainers can also release the hold through an intentional scanner-policy update.

Next step: If this is a genuine credential, remove and rotate it. If it is an intentional test fixture, a maintainer must review and qualify it.

View the workflow run.

@SunnyShu0925 SunnyShu0925 changed the title fix(channels): keep status deadline on the monotonic clock across wal… fix(channels): keep status deadline on the monotonic clock across wall-clock jumps Oct 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Oct 19, 2026
@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 19, 2026
@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@SunnyShu0925
SunnyShu0925 force-pushed the fix/channels-status-deadline-wall-clock-178 branch from 2e0eccc to 300c24d Compare October 19, 2026 11:30
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@steipete — ClawSweeper input scan blocks review on a pre-existing redaction test fixture

Could you take a look? ClawSweeper keeps refusing this review with literal_not_reviewed on a pre-existing, deliberate redaction test fixture — the same class of false positive tracked in clawsweeper#1350 and clawsweeper#1744.

What is flagged

The scanner flags the base blob of src/gateway/server-methods/channels.status.test-helpers.ts (revision 7c2eb6c3, scannerLine 145):

baseUrl: "https://runtime-user:[email protected]/?token=runtime-token"

This line lives inside createRecordedAccountSnapshots()'s recovered snapshot — a test fixture that deliberately asserts the credential is redacted to undefined / *** (see the assertion in channels.status.test.ts). It predates this PR and is unchanged on OpenClaw main. The scanner only catches it because this PR touches that file, and the input scan feeds the complete base blob (the exact scenario described in #1744).

Why this PR is otherwise ready

The actual change here is unrelated: it switches the channels.status deadline from Date.now() to performance.now() so deadline enforcement survives wall-clock jumps. The two-line fixture updates in test-helpers.ts (from vi.setSystemTime(Date.now() + 1000) to vi.advanceTimersByTime(1000)) are required to keep those tests meaningful under the monotonic clock, and they are the only reason this file enters the scan.

Request

Per the precedent in #1356 / #1745, this deliberate fixture needs to be qualified into the ClawSweeper allowlist so the review can proceed. I can prepare the exact native before/after proof (TruffleHog value digests, source line, committed base/head attribution) mirroring #1745, or open a qualify PR against clawsweeper if that helps.

Thanks!

@Patrick-Erichsen Patrick-Erichsen self-assigned this Oct 19, 2026
@roboclaw-bot
roboclaw-bot merged commit 99733ff into openclaw:main Oct 19, 2026
255 of 258 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash.

@Patrick-Erichsen

Patrick-Erichsen commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer landing review for exact head 300c24d3d1898a7f557956c306ed45a0078b395e:

  • The production change consistently uses performance.now() for the request deadline, remaining hook budgets, and both expiration checks. Published timestamps retain Date.now(). The outer raceWithTimeout still receives the original request timeout; the backward-clock failure is an inflated hook budget, while a forward jump can discard a healthy result.
  • A fresh independent Codex review of the full patch, all three changed modules, and the relevant caller/timer/concurrency context found no actionable P0–P2 findings. I also traced the snapshot builder, timeout wrapper, and fake-timer regression flow.
  • Exact-head CI run 39245163570 passed. I inspected the changed gateway-methods shard logs: all 50 channels.status cases passed, including both ±60-second wall-clock jumps and all 12 deadline-overrun combinations. The required openclaw/ci-gate passed.
  • Before/after evidence: the contributor reports both new wall-clock-jump cases failing against the original Date.now() deadline implementation; the exact-head hosted run independently confirms both pass with this patch. These are fake-timer tests; no real NTP adjustment or live-channel test was performed. I did not execute contributor code locally.
  • ClawSweeper's literal_not_reviewed refusal is on the unchanged deliberate credential-redaction fixture, not an introduced credential. A separate narrow qualification has paired native TruffleHog proof: identical staged inputs refuse before qualification and admit afterward, with both findings still detected; five changed-value/path/mode/source-line negative controls continue to refuse. Current maintainer policy treats ClawSweeper as advisory; this landing uses independent review and GitHub's enforced gates.

The PR body now describes the timeout and fake-timer evidence accurately. Source commits are unchanged. Credit to @SunnyShu0925 for the fix and regression coverage.

Completion: RoboClaw merged this exact reviewed head concurrently at 2026-10-19 23:30:50 UTC as 99733ff274ea7f85b9642e5b91f153fc901e3cc4, before our native prepare/merge step. Verified the landed commit is reachable from current origin/main; no second merge was submitted.

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

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants