Skip to content

fix(buzz): keep the setup verification reload wait on the monotonic clock - #184525

Closed
mikasa0818 wants to merge 1 commit into
openclaw:mainfrom
mikasa0818:fix/problem-buzz-reload-monotonic-wait
Closed

mikasa0818 wants to merge 1 commit into
openclaw:mainfrom
mikasa0818:fix/problem-buzz-reload-monotonic-wait

Conversation

@mikasa0818

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: after saving the Buzz channel config, the CLI's wait for the Gateway to apply it keeps polling far past the 15-second reload window when the system wall clock steps backward — the deadline is seeded and compared on the wall clock while the polls sleep on the monotonic clock.

User Impact

User impact: finishing Buzz setup on a machine whose clock steps backward (NTP correction, VM or laptop resume) now always reports the bounded Gateway did not apply the saved Buzz configuration within 15 seconds outcome after the real 15-second window, instead of hanging the setup command on a wall-clock-inflated polling loop.

Why This Change Was Made

verifyBuzzAfterSetup seeds reloadDeadline = Date.now() + GATEWAY_RELOAD_WAIT_MS and computes remainingMs = reloadDeadline - Date.now() between config.get round trips that sleep on monotonic timers. A backward wall-clock step stretches the budget by the step, so the loop keeps issuing real config.get requests for 15s + step.

The deadline now lives on performance.now() — seed and remaining computation — which is monotonic and unaffected by wall-clock adjustments. This continues the cross-clock-domain series (#174151, #181335, and the merged fleet: #155846 slack auth retries, #182180 Feishu registration poll, #182778 provider local service budgets, #182859 scheduled-task fallback waits, #183742 X media processing wait); the Buzz reload wait is an unclaimed channel-setup site in the same family.

The regression test keeps everything on injected clocks (the series' two-clock separation): the gateway transport seam reports a persistently unapplied saved revision, fake timers advance the monotonic deadline, and the wall-clock reading stays frozen at a rewound instant; the bounded failure is asserted through the runtime log the verify call reports when it resolves.

No setup flow, gateway RPC, or recovery semantics change; behavior on a clock that never steps is identical.

Evidence

Pre-fix RED — stock main (d18177d60f9), regression test only: config.get keeps reporting appliedConfigHash !== configRevisionHash, and the wall clock is frozen 10 minutes behind once the wait starts. Stock main never resolves within the whole (fake-advanced) 16-second observation:

$ node scripts/run-vitest.mjs run extensions/buzz/src/setup-verify.monotonic.test.ts
 × fails the reload wait at its monotonic deadline when the wall clock rewinds
   → expected 'still-waiting' to be 'completed'

Post-fix GREEN — the same scenario resolves with the bounded report, and the module's suites pass:

$ node scripts/run-vitest.mjs run extensions/buzz/src/setup-verify.monotonic.test.ts
      Tests  1 passed
$ node scripts/run-vitest.mjs run extensions/buzz/src/setup-verify.test.ts
      Tests  4 passed (4)

Real runtime proof (real Gateway WebSocket transport, in-process wall-clock rewind)

A real local WebSocket gateway fixture speaks the real Gateway wire protocol (server connect.challenge → client connect → hello-ok → config.get responses). The production callGatewayFromCli runs its full client stack — event-loop readiness, device identity bootstrap, challenge connect — against that fixture, which answers every config.get with a persistently unapplied saved revision. Only Date.now is rewound in-process; performance.now() reports all real elapsed times. The budget is the module's real 15-second window. (Captured in a standalone Node process so no vitest worker keeps the event loop busy; the handshake takes ~21s of real bootstrap before the first poll.)

TRACE[buzz] t=15ms   real gateway WebSocket fixture listening on ws://127.0.0.1:<port>
TRACE[buzz] t=21311ms wall clock rewound by -600000ms (in-process Date.now injection) after the first real config.get
TRACE[buzz] t=21312ms RPC config.get -> {configRevisionHash:"saved", appliedConfigHash:"older"} (poll #1)
TRACE[buzz] t=21838ms RPC config.get -> ... (poll #2)
TRACE[buzz] t=31095ms RPC config.get -> ... (poll #20)
TRACE[buzz] t=36078ms RPC config.get -> ... (poll #30)
PROOF[buzz] variant=fixed budget=15000ms wall_rewind=-600000ms -> state=completed config_get_polls=30 bounded_report=true settled_by_cap=true cap_elapsed_real_ms=36080

TRACE[buzz] t=22121ms wall clock rewound by -600000ms (in-process Date.now injection) after the first real config.get
TRACE[buzz] t=36998ms RPC config.get -> ... (poll #30, still polling past the whole budget)
PROOF[buzz] variant=old budget=15000ms wall_rewind=-600000ms -> state=still-waiting-at-cap config_get_polls=35 settled_by_cap=false cap_elapsed_real_ms=39561

Stock main is still issuing real config.get polls at the 18-second cap (35 polls, past the whole budget — it would continue for the length of the rewind); with this PR the verify call resolves with the bounded "did not apply" report after exactly the real 15-second budget (30 polls).

Behavior matrix (config.get always unapplied, wall clock rewound 10min at poll #1):

clock during wait           => verify resolves              => result
normal (no step)            => after 15s window             => bounded report
wall rewind 10min (pre-fix) => still polling at 18s cap     => unbounded by the step
wall rewind 10min (post-fix) => after 15s window            => bounded report

Also verified on the changed tree: pnpm format:check and the changed-file lint lane from pnpm check:changed (one oxlint finding on the first draft was fixed and re-verified; the pnpm/corepack-shelling lanes fail on this Windows contributor box for the environmental reasons documented on #182778/#182859/#183742, unrelated to this diff). CI runs those lanes authoritatively.

@clawsweeper

clawsweeper Bot commented Oct 26, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR measures Buzz’s post-setup Gateway reload deadline with performance.now() and adds a regression test.

Example: The system clock moves backward 10 minutes while the saved Buzz configuration remains unapplied.

  • Before: Wall-clock deadline calculations extend polling by the clock adjustment.
  • After: The reload budget advances independently of wall-clock changes and reports the existing timeout outcome.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with useful regression coverage and sufficient real-transport fault evidence; proof uses an in-process fixture rather than the full setup CLI.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied terminal traces exercise the changed verification owner through production callGatewayFromCli and a real WebSocket transport client against a local protocol fixture, showing timeout recovery after a wall-clock rewind versus continued polling before the fix; this satisfies the production-transport fault-proof exception.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Buzz setup verification can continue polling well beyond its intended reload window after a backward system-clock adjustment.
Reason: The patch restores the existing bounded-wait intent while preserving setup outputs, defaults, and recovery behavior.

Merge readiness

✅ Ready for maintainer review

Keep this PR: current main retains the clock-sensitive wait, and this focused repair introduces no actionable defects.

Priority: P2
Reviewed head: c4a4968da7155afc998c57bb5dc6fdb75145ef3c

Before merge

None.

Findings

None.

Agent review details

How this fits together

Buzz’s setup wizard invokes verification after saving configuration; verification polls Gateway config.get until the saved revision is applied, then probes room membership or reports recovery guidance.

flowchart TD
  A[Buzz setup wizard] --> B[Save configuration]
  B --> C[Post-write verification]
  C --> D[Gateway config polling]
  D --> E[Monotonic reload deadline]
  D --> F[Room membership probe]
  E --> G[Recovery guidance]
Loading

Technical review

Best possible solution:

Keep the deadline in the existing verification owner and use the same monotonic clock for its start and remaining-budget calculation.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes the failure mechanism, and the contributor supplies matching before/after real-transport traces; this read-only review ran no target code.

Is this the best way to solve the issue?

Changing both clock reads is the smallest complete repair: it restores elapsed-time accounting without introducing another owner, changing persisted configuration, or altering reload recovery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 62a2e746eb04.

Provenance checked

  • Buzz post-setup reload deadline keeps the original intent (3cba004: Wait for asynchronous Gateway reload after saving Buzz setup.)
  • Remaining reload budget after config revision polling keeps the original intent (439de55: Synchronize membership verification with the Gateway applying its saved configuration.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced production hunks replace both wall-clock reads with performance.now(); polling, configuration checks, membership verification, and recovery messages remain intact. (extensions/buzz/src/setup-verify.ts:47, c4a4968da715)
  • Current-main defect remains: Current main seeds reloadDeadline with Date.now() and subtracts Date.now() after config.get requests; a backward clock adjustment therefore increases the remaining budget. (extensions/buzz/src/setup-verify.ts:44, 62a2e746eb04)
  • Original behavior and intent: The reload wait originated in 3cba004 and revision synchronization followed in 439de55, both associated with merged feat: add Buzz channel plugin #113419; its stated intent includes verification without posting test messages. (extensions/buzz/src/setup-verify.ts:44, 439de5577e62)
  • Supplied production-transport proof: The PR body supplies before/after terminal traces of verifyBuzzAfterSetup using the production callGatewayFromCli client against a real local WebSocket protocol fixture, with a 600000 ms wall-clock rewind and persistently unapplied configuration; the fixed variant reports timeout while the old variant continues polling. (c4a4968da715)
  • Regression and mock policy: The added test observes verification settlement and its timeout report under independently advancing monotonic timers and frozen wall time; the closed Gateway mock carries the isolation annotation permitted by the repository’s fixture policy. (extensions/buzz/src/setup-verify.monotonic.test.ts:10, c4a4968da715)
  • Review and CI state: GitHub confirms the reviewed head, no submitted human reviews or requested reviewers, unknown mergeability, and an exact-head CI gate still pending; no diff-caused check failure was observed. (c4a4968da715)

Likely related people:

  • Patrick Erichsen: Raw commit aa0d319 adds extensions/buzz/src/setup-verify.ts:47 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: aa0d3192d270; files: extensions/buzz/src/setup-verify.ts)

PR surface

Source +3, Tests +62. Total +65 across 2 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 5 2 +3
Tests 1 62 0 +62
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 67 2 +65

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A clock adjustment can prolong Buzz’s CLI setup verification, with impact limited to this post-save polling path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 (2 earlier review cycles)
  • reviewed 2026-10-26T10:58:18.943Z sha b2ff0d8ddadc79ae451fea3e0bc13642afe1bb7e :: needs changes before merge. :: [P2] Make the test logger satisfy RuntimeEnv.log | [P2] Preserve real exports in the new Gateway runtime mock
  • reviewed 2026-10-26T12:17:48.102Z sha 4e6217539fb6ff03bfe5e90fe934b5d753bfd125 :: needs maintainer review before merge. :: none

Reviewed October 26, 2026, 9:23 AM ET / 13:23 UTC (Revision 3).

@mikasa0818
mikasa0818 force-pushed the fix/problem-buzz-reload-monotonic-wait branch from b2ff0d8 to 4e62175 Compare October 26, 2026 12:11
@mikasa0818

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 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: 🐚 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@mikasa0818
mikasa0818 force-pushed the fix/problem-buzz-reload-monotonic-wait branch from 4e62175 to c4a4968 Compare October 26, 2026 13:18
@mikasa0818

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. label Oct 26, 2026
obviyus added a commit that referenced this pull request Oct 28, 2026
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]>
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks @mikasa0818. This is now fixed at the root in #186484 (bf10fbe): process-local deadlines and budgets go through one monotonic clock owner, src/shared/monotonic-time.ts (bundled extensions use performance.now()). Your commit from this PR is kept in that merge and you're credited as co-author, so I'm closing this one as covered. For new deadline code, please use that owner rather than a per-site change.

@obviyus obviyus closed this Oct 28, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: buzz P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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