Skip to content

fix(irc): report probe latency across clock changes - #188238

Closed
chengzhichao-xydt wants to merge 1 commit into
openclaw:mainfrom
chengzhichao-xydt:fix/irc-probe-latency-clock
Closed

chengzhichao-xydt wants to merge 1 commit into
openclaw:mainfrom
chengzhichao-xydt:fix/irc-probe-latency-clock

Conversation

@chengzhichao-xydt

@chengzhichao-xydt chengzhichao-xydt commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: probeIrc reports a negative or wildly inflated latencyMs when the system clock steps while a probe connect is in flight (NTP correction, manual change, VM snapshot restore), because the elapsed reading is computed from Date.now(). Doctor/status output then shows absurd probe latencies for an otherwise healthy server.

User Impact

Probe latency stays accurate and non-negative across system-clock corrections. No configuration, public API, schema, or migration changes.

Why This Change Was Made

Latency is a duration, so it now comes from performance.now(), which is monotonic and immune to system-clock steps. This matches the shared runChannelProbe helper, which already measures elapsed time on the monotonic clock. Probe behavior, timeouts, and the result shape are unchanged. A new test file covers a real loopback success reading, a wall-clock backward step mid-connect, and the unconfigured-account path.

Evidence

node scripts/run-vitest.mjs run extensions/irc/src/probe.test.ts extensions/irc/src/send.test.ts: both suites pass (the wall-clock step case is red against the base implementation). The existing send.test.ts latency fixture now drives performance.now, preserving its timeout-forwarding and quit assertions. oxlint and oxfmt --check clean on changed files. Local tsgo lane unavailable on this host (glibc 2.28 vs binary requirement 2.33+); type gates run in hosted CI. Net test growth +51 lines (new file) is recorded in config/test-lines-allocations/chengzhichao-irc-probe-clock-20261030.txt.

Real behavior proof

Behavior addressed: IRC probe latencyMs must not follow wall-clock steps during a connect.
Real environment tested: This branch at HEAD 54c2f37d0559ebe1114bd1ffe2d42501110ad7ca, Node v24.13.1, Linux x64; production probeIrc driven against a real loopback TCP server that completes IRC registration and then steps Date.now back one hour; performance.now stays native.
Exact steps or command run after this patch: WT=$PWD OUT=/tmp/clock-proof/probe-head.json node --import tsx /tmp/clock-proof/probe.mts, then the same command with extensions/irc/src/probe.ts restored to the base revision.
Evidence after fix: HEAD: {"ok":true,"latencyMs":178.37} after a one-hour backward wall-clock step during registration. BASE: {"ok":true,"latencyMs":-3599987} under identical perturbation. Receipts: /tmp/clock-proof/probe-{head,base}.json.
Observed result after fix: Reported latency follows the monotonic clock and stays sane; base reports a negative latency of roughly the step size.
What was not tested: Live IRC networks, TLS probes, NickServ flows, and OS/NTP clock adjustment. The connect timeout path is unchanged.

Intentionally out of scope

  • Slack/Telegram probe timing, which the shared runChannelProbe helper already covers.
  • Any change to probe timeouts, registration, or the result contract.

@clawsweeper

clawsweeper Bot commented Oct 30, 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. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR measures IRC probe latency with a monotonic clock so system-clock changes cannot distort the result.

Example: The wall clock moves backward one hour during IRC registration.

  • Before: The supplied base trace reports latencyMs of -3599987.
  • After: The supplied patched trace reports latencyMs of 178.37.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful, narrowly scoped production repair with real TCP boundary evidence, but an existing consumer test demonstrably fails and one added case duplicates coverage.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): The contributor records production probeIrc registering against a real loopback TCP server on Linux with Node v24.13.1 and native performance.now; a one-hour backward Date.now step yields 178.37 ms on the reviewed head versus -3599987 ms on base, exercising the changed owner and real transport.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A healthy IRC connection can display a negative or greatly inflated probe latency after a system-clock correction.
Reason: Duration measurement belongs on a monotonic clock, and this focused repair preserves connection policy, configuration, and result shape.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR: it fixes a real IRC latency bug still present on main, but the clock change breaks an existing test and needs a focused repair.

Priority: P2
Reviewed head: ffa4dfa2f5cda1b2b37c938eab32c6797676647f

Before merge

  • Update the existing probe test to drive the monotonic clock (P2) - The success test in extensions/irc/src/send.test.ts:388 still mocks Date.now to return 100 and 145 and expects latencyMs: 45. Switching the production readings to performance.now leaves that fixture ineffective, so the exact-head extension check now fails with an actual latency of 0.07269600000290666. Change that existing fixture to mock performance.now while preserving its timeout-forwarding and quit assertions, then run both probe-related suites.

Findings

  • [P2] Update the existing probe test to drive the monotonic clock — extensions/irc/src/probe.ts:28

Tests

  • Low-value test extensions/irc/src/probe.test.ts: Remove the added unconfigured-account case at lines 52–56: send.test.ts already verifies incomplete configuration and independently checks that no connection occurs.
Agent review details

How this fits together

The IRC channel status adapter passes account configuration into probeIrc, which connects and registers through the IRC client, disconnects, and returns connectivity details and latency.

flowchart LR
  A[Channel status request] --> B[IRC status adapter]
  B --> C[Account resolution]
  C --> D[IRC probe]
  D --> E[TCP or TLS registration]
  E --> D
  D --> F[Status and latency result]
Loading

Technical review

Best possible solution:

Keep the local monotonic-clock fix, update the existing probe test's clock fixture, and retain only distinct regression coverage.

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

Current-main source directly shows wall-clock subtraction across an awaited registration, and the contributor supplies a matching base-versus-head TCP trace; this review executed no target code.

Is this the best way to solve the issue?

Replacing the two clock readings in the existing probe owner is the smallest complete fix; the shared-helper parity claim is inaccurate, but does not undermine this local repair.

Full review comments:

  • [P2] Update the existing probe test to drive the monotonic clock — extensions/irc/src/probe.ts:28
    The success test in extensions/irc/src/send.test.ts:388 still mocks Date.now to return 100 and 145 and expects latencyMs: 45. Switching the production readings to performance.now leaves that fixture ineffective, so the exact-head extension check now fails with an actual latency of 0.07269600000290666. Change that existing fixture to mock performance.now while preserving its timeout-forwarding and quit assertions, then run both probe-related suites.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • IRC probe elapsed-time measurement changes intended behavior with a stated reason (fa906b2: The merged first-class IRC feature added connectivity probing and status integration; its description establishes no requirement to measure durations with the wall clock.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test extensions/irc/src/send.test.ts extensions/irc/src/probe.test.ts --maxWorkers=1
  • pnpm exec oxfmt --check extensions/irc/src/send.test.ts extensions/irc/src/probe.test.ts extensions/irc/src/probe.ts
  • git diff --check
  • Verify checks-node-changed-extensions-bundle-1 passes on the repaired head.

What I checked:

PR surface

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

View PR surface stats
Area Files Added Removed Net
Source 1 4 2 +2
Tests 1 58 0 +58
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 3 64 2 +62

Labels

Label changes:

  • add P2: Clock corrections can corrupt diagnostic probe latency, but this change does not affect IRC message delivery or connectivity.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Clock corrections can corrupt diagnostic probe latency, but this change does not affect IRC message delivery or connectivity.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • 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.

Reviewed October 30, 2026, 6:24 AM ET / 10:24 UTC.

@chengzhichao-xydt
chengzhichao-xydt force-pushed the fix/irc-probe-latency-clock branch from ffa4dfa to 54c2f37 Compare October 30, 2026 10:29
@chengzhichao-xydt

Copy link
Copy Markdown
Contributor Author

Updated per review: the existing send.test.ts latency fixture now drives performance.now (timeout-forwarding and quit assertions preserved), and the duplicated unconfigured-account case was dropped from probe.test.ts in favor of the existing send.test.ts coverage. Both probe.test.ts and send.test.ts suites pass locally. @clawsweeper re-review

obviyus added a commit that referenced this pull request Oct 30, 2026
…nges (#188293)

fix(irc,msteams): measure in-process durations with a monotonic clock

IRC and Microsoft Teams measured some in-process durations with wall-clock time, so a system clock jump changed them:
- the IRC probe latency could be wrong;
- IRC reconnect backoff reset too early or not at all;
- a fresh Teams file-consent upload could expire too early.

These durations now use `performance.now()`. Persisted dates and public `createdAt` timestamps are unchanged, and so are the budgets.

Evidence: built Gateway, main twice and candidate twice, with `Date.now` stepped inside the process only. Main reproduced the wrong probe latency, the wrong reconnect resets and the early expiry of a fresh Teams upload; the candidate corrected all three. The Teams path ran authenticated consent invokes, exact-byte uploads and the original card update. Controls passed: normal timing and expiry, invalid JWT, conversation mismatch and decline. Details: #188293 (comment).

Includes the fixes from #188237, #188238 and #188239, with their commits kept.

Co-authored-by: chengzhichao-xydt <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks @chengzhichao-xydt. Your fix landed in #188293 (9b5c4e8), which keeps your commit. I'm closing this one as included.

@obviyus obviyus closed this Oct 30, 2026
@chengzhichao-xydt
chengzhichao-xydt deleted the fix/irc-probe-latency-clock branch October 30, 2026 12:03
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…nges (openclaw#188293)

fix(irc,msteams): measure in-process durations with a monotonic clock

IRC and Microsoft Teams measured some in-process durations with wall-clock time, so a system clock jump changed them:
- the IRC probe latency could be wrong;
- IRC reconnect backoff reset too early or not at all;
- a fresh Teams file-consent upload could expire too early.

These durations now use `performance.now()`. Persisted dates and public `createdAt` timestamps are unchanged, and so are the budgets.

Evidence: built Gateway, main twice and candidate twice, with `Date.now` stepped inside the process only. Main reproduced the wrong probe latency, the wrong reconnect resets and the early expiry of a fresh Teams upload; the candidate corrected all three. The Teams path ran authenticated consent invokes, exact-byte uploads and the original card update. Controls passed: normal timing and expiry, invalid JWT, conversation mismatch and decline. Details: openclaw#188293 (comment).

Includes the fixes from openclaw#188237, openclaw#188238 and openclaw#188239, with their commits kept.

Co-authored-by: chengzhichao-xydt <[email protected]>
Co-authored-by: Claude Code <[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: irc P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants