Skip to content

fix(irc): reset reconnect backoff across clock changes - #188237

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

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

Conversation

@chengzhichao-xydt

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

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: IRC reconnect delays stay stuck near the 30-second cap after a stable connection, or reset too early while a peer keeps flapping, when the system clock steps (NTP correction, manual change, VM snapshot restore). The reconnect backoff decides whether a connection stayed up for the 60-second stability window by comparing Date.now() readings, so a backward step erases accumulated uptime and a forward step fabricates it.

User Impact

Reconnect delays recover to the 1-second initial delay after a stable minute even if the system clock jumps, and a forward clock jump no longer lets a repeatedly dropped connection hammer the server. No configuration, public API, schema, or migration changes.

Why This Change Was Made

Uptime is a duration, not a wall-clock reading. The stability window now reads performance.now(), which is monotonic and immune to system-clock steps; backoff policy values, jitter, and the reset threshold are unchanged, and no timestamps leave the process. Existing tests now drive the monotonic clock, and two regressions pin a backward step after a stable minute and a forward step during a fresh connection.

Evidence

node scripts/run-vitest.mjs run extensions/irc/src/reconnect-backoff.test.ts: 5/5 pass (both new wall-clock regressions are red against the base implementation). 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 +30 lines is recorded in config/test-lines-allocations/chengzhichao-irc-backoff-clock-20261030.txt for the two wall-clock regressions.

Real behavior proof

Behavior addressed: IRC reconnect scheduling through the shipped monitorIrcProvider boundary must survive wall-clock steps in both directions.
Real environment tested: This branch at HEAD 5b36005a7401a32f5b70e1fe8d68b469a523122b, Node v24.13.1, Linux x64. The real monitorIrcProvider runs against a real loopback TCP server with REAL timers throughout; only Date.now is stepped (+/-120s) between a disconnect and the next scheduled reconnect while performance.now stays native. The server records each connection arrival; the reported delay is measured at the socket boundary, not read from the implementation.
Exact steps or command run after this patch: node scripts/run-vitest.mjs run extensions/irc/src/monitor-clock-step.proof.test.ts (throwaway harness driving the shipped monitor; not committed), then the identical command with extensions/irc/src/reconnect-backoff.ts restored to the base revision.
Evidence after fix: Terminal output, HEAD:

PROOF forward: scheduled reconnect delay = 2256ms (uptime 500ms)   # attempt 2, no premature reset
PROOF backward: scheduled reconnect delay = 1141ms (uptime 60000ms) # reset after a stable minute

BASE (same harness, same perturbation):

PROOF forward: scheduled reconnect delay = 1183ms (uptime 500ms)   # prematurely reset to attempt 1
PROOF backward: scheduled reconnect delay = 2039ms (uptime 60000ms) # reset lost after a stable minute

Both cases flip as required (base fails the harness assertions; head passes).
Observed result after fix: The shipped monitor's actual reconnect timer follows monotonic connection uptime: a forward wall-clock step no longer resets a fresh connection's backoff (2256ms, attempt-2 band), and a backward step no longer erases a stable minute (1141ms, reset band). Base behavior inverts both.
What was not tested: Live IRC networks, TLS registration paths, OS/NTP clock adjustment, and the gateway host process. Backoff policy values themselves are unchanged. The earlier helper-level red/green pair (driving createIrcReconnectBackoff directly, forward step 2000-vs-1000, backward step 1000-vs-2000) remains as supplementary evidence.

Intentionally out of scope

  • Other IRC timing reads that already use the monotonic clock, and channels whose probes were fixed separately.
  • Any change to reconnect policy constants or jitter.

@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. 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. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR measures IRC connection stability with a monotonic clock so wall-clock changes cannot incorrectly reset reconnect backoff.

Example: With jitter disabled, an IRC connection lasts 10 seconds while the system clock jumps forward one hour after an earlier failed connection.

  • Before: The connection appears stable for over 60 seconds, so the next reconnect delay incorrectly resets to 1,000 ms.
  • After: The connection remains classified as short-lived, so the next reconnect delay grows to 2,000 ms.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch appears correct and useful, but supplied evidence does not satisfy the required production-boundary proof gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: System clock corrections can keep IRC reconnect delays elevated after a healthy connection or prematurely reset delays while connections keep dropping.
Reason: Monotonic duration measurement restores the existing stability contract without changing configuration, public APIs, or intended reconnect policy.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it fixes a concrete current-main bug with a focused change that preserves the existing reconnect policy; no introduced correctness defect was found.

Priority: P2
Reviewed head: 5b36005a7401a32f5b70e1fe8d68b469a523122b

Before merge

  • Add real behavior proof - The body reports Node v24.13.1/Linux subprocess results for the production backoff helper, including expected base/head differences, but bypasses monitorIrcProvider and its real transport client and links no viewable receipts. The contributor should provide redacted logs or terminal output showing actual reconnect scheduling across both clock-step directions through that production boundary, removing credentials and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Supply an IRC monitor and real TCP-client reconnect trace covering forward and backward wall-clock steps; the reported helper-level red/green results do not exercise that boundary.
Agent review details

How this fits together

The IRC monitor records successful connections and asks the plugin-local backoff owner for a delay after disconnects; that delay schedules the next real IRC connection attempt.

flowchart LR
  A[IRC socket connects] --> B[IRC monitor]
  B --> C[Record monotonic connection time]
  D[Socket disconnects] --> B
  B --> E[Backoff stability decision]
  C --> E
  E --> F[Reconnect timer]
  F --> A
Loading

Technical review

Best possible solution:

Use performance.now in the existing reconnect-backoff owner while retaining the current stability threshold, jitter, and attempt lifecycle.

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

Current-main source establishes both failures directly: wall-clock steps alter the elapsed-time comparison independently of actual connection uptime; no target code or tests were executed during this review.

Is this the best way to solve the issue?

The patch is the smallest complete production fix: replace both clock readings in the existing duration owner, preserving policy and callers, with regressions for the two distinct failure directions.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • IRC reconnect stability and throttling keeps the original intent (0ac81cf: Throttle repeated short-lived IRC connections while restoring the historical initial delay after 60 seconds of healthy uptime.)
  • Native clock ownership and test fixtures keeps the original intent (3ecfdb7: Remove a test-only clock injection seam without redesigning the reconnect algorithm.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Agustin Rivera: Raw commit 0ac81cf adds extensions/irc/src/reconnect-backoff.ts:22 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0ac81cf6ec1a; files: extensions/irc/src/reconnect-backoff.ts)
  • Peter Steinberger: Raw commit 3ecfdb7 adds extensions/irc/src/reconnect-backoff.ts:16 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3ecfdb717de6; files: extensions/irc/src/reconnect-backoff.ts)

PR surface

Source +2, Tests +30, Other +2. Total +34 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 2 +2
Tests 1 31 1 +30
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 3 37 3 +34

Review metrics

Metric Value Why it matters
Production versus test LOC Production +4/-2; tests +31/-1 The production growth is explanatory comments; test growth covers distinct backward and forward clock-step failures without adding production test seams.

Labels

Label changes:

  • add P2: Clock corrections can distort IRC reconnect delays, but recovery remains bounded and the affected surface is limited to IRC connection stability.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: Clock corrections can distort IRC reconnect delays, but recovery remains bounded and the affected surface is limited to IRC connection stability.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach the production monitor/socket evidence described in the proof assessment.

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:23 AM ET / 10:23 UTC.

@chengzhichao-xydt

Copy link
Copy Markdown
Contributor Author

Added the requested monitor-boundary proof: the shipped monitorIrcProvider runs against a real loopback TCP server with real timers, stepping only Date.now (+/-120s) between a disconnect and the next scheduled reconnect. Server-observed reconnect delays — HEAD: forward 2256ms (attempt 2, no premature reset), backward 1141ms (reset after a stable minute); BASE under identical perturbation: forward 1183ms (premature reset), backward 2039ms (reset lost). Full terminal output and harness description are in the updated body. @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-reconnect-backoff-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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants