Skip to content

fix(irc): bound pending inbound line length - #165018

Merged
eleqtrizit merged 2 commits into
openclaw:mainfrom
eleqtrizit:1092
Oct 5, 2026
Merged

eleqtrizit merged 2 commits into
openclaw:mainfrom
eleqtrizit:1092

Conversation

@eleqtrizit

@eleqtrizit eleqtrizit commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: an IRC server that never terminates a line can make the Gateway process retain inbound data without limit, which can end the whole process and every channel it hosts, and a peer that is dropped on every connection can keep the account reconnecting about once a second.

The IRC client appended each decoded socket chunk to a string and released it only when a newline arrived (extensions/irc/src/client.ts, socket.on("data")). IRC_MAX_LINE_BYTES (512) bounded outbound PRIVMSG chunking only, and the readiness timeout stops applying once registration completes. The monitor, the status probe (probe.ts) and transient sends (send.ts) all share this client, so every caller had the same unbounded sink. Separately, the monitor reconnected on a fixed one-second delay with no attempt counter (extensions/irc/src/monitor.ts).

User Impact

User impact: an IRC peer that sends an over-long or never-terminated line is now disconnected instead of the Gateway retaining memory until the process ends. Reconnects after repeated short-lived connections back off from 1s up to 30s instead of repeating every second. Compliant servers are unaffected, including ones that send long IRCv3 tagged lines.

Risk: this is not fully backward compatible. A peer that sends a line over 16,384 UTF-16 code units is now dropped, and there is no configuration override. After several quick failures a server that genuinely went down and came back can wait up to 30 seconds for the bot to return instead of 1 second; a connection that stays up for 60 seconds resets the delay. Nothing is migrated and no setting changes.

Why This Change Was Made

  • Cap the pending line at 16,384 UTF-16 code units, well above the IRCv3 maximum of 8191 bytes of tags plus a 512-byte body, so no compliant server reaches it. This is a deliberate choice of a higher limit than the 512-byte bound proposed in fix(irc): disconnect when an inbound line exceeds 512 bytes #156015, to tolerate longer server records.
  • Check both a terminated line that is already too long and the unterminated remainder after the parse loop, so a single large chunk cannot slip past.
  • Fail closed: report the error, clear the buffer, destroy the socket, and ignore any later data event.
  • Destroy the socket directly, because close() is a no-op after quit(), which only half-closes.
  • Reuse the socket close listener so onDisconnect fires and the monitor's existing reconnect path runs. No new callback, option or config key.
  • Throttle that path with the shared computeBackoff helper from openclaw/plugin-sdk/runtime-env, which Buzz, Signal, Slack, Telegram and WhatsApp already use. The policy is copied from Buzz (extensions/buzz/src/gateway.ts): 1s initial, 30s cap, factor 2, 0.2 jitter, with the attempt counter reset only after a connection stays up for 60s. Other channels use the same helper with their own values (Signal 1s to 10s; Slack 2s to 30s, factor 1.8, jitter 0.25), so the numbers here follow Buzz rather than a repo-wide default.
  • Reset the backoff only after a connection has stayed up for 60 seconds. A peer that registers successfully and is dropped immediately must keep growing the delay, so a reset on every successful connect would defeat the throttle.
PR Governed layer Relation to this PR
#100799 Reconnect after post-ready close; close on registration timeout Reuses the same onDisconnect signal; adds no new lifecycle state
#110914 Durable ingress of accepted PRIVMSG lines Operates before a line is accepted; durable queue behavior is unchanged
#156015 Same inbound bound with a 512-byte ceiling Same memory protection; this PR accepts a strict superset of lines; both edit client.ts and client.test.ts, so one must rebase on the other

Evidence

Peer behavior Before After
Welcome then 256 KiB with no newline Retained indefinitely; no error, peer stays connected Error line longer than 16384, socket destroyed, disconnect reported
64 KiB terminated line Delivered to the line handler Dropped before onLine; disconnect reported
Line at the IRCv3 tag plus body maximum, then PING Accepted Accepted; client stays ready
20 normal lines in small chunks Accepted Accepted; no error
Peer registers then is dropped, four times in a row Reconnect every 1s Delays 1s, 2s, 4s, 8s (jitter off in the test)
Connection stays up 60s, then drops Reconnect after 1s Delay resets to 1s

Observed by running the new loopback-socket tests against the unmodified client (2 fail, 21 pass) and against this branch (23 pass), and by unit tests of the backoff schedule with an injected clock.

Focused test time, measured locally on the rebased head: the IRC client, probe, send and reconnect-backoff suites together ran 46 tests in 34.11s reported duration, of which transform was 82%; extensions/irc/src/client.test.ts alone took 1.86s for 23 tests earlier. The monitor suite (11 tests) took 26.14s. Hosted CI seconds are not available yet: the PR is a draft and the hosted test lanes were skipped.

Boundary decisions requested from maintainers

  1. Accept the 16,384-code-unit inbound ceiling. It was chosen deliberately as a higher limit than fix(irc): disconnect when an inbound line exceeds 512 bytes #156015's 512 bytes; no maintainer acceptance is recorded yet.
  2. Accept the capped reconnect backoff (1s to 30s, reset after a 60s stable connection) as recovery for an overflowing peer.
  3. Choose one shared ceiling if fix(irc): disconnect when an inbound line exceeds 512 bytes #156015 and this PR are to be consolidated.

Testing

  • node --import ./scripts/tsx.mjs scripts/test-projects.mts extensions/irc/src/client.test.ts: 23 passed, including 4 new tests against a loopback server.
  • extensions/irc/src/reconnect-backoff.test.ts: 6 new tests covering the schedule, cap, jitter bounds, repeated short-lived connections, the 60s reset and its boundary.
  • IRC client, monitor, probe and send suites: all passed. The existing monitor reconnect test's wait was widened from 3s to 10s because the first reconnect now carries jitter.
  • pnpm run check:changed --base upstream/main: exit 0 (typecheck, dead-export scan, lint).

@clawsweeper

clawsweeper Bot commented Oct 4, 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.

@eleqtrizit eleqtrizit self-assigned this Oct 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 3:09 PM ET / 19:09 UTC (Revision 7).

ClawSweeper review

What this changes

The IRC plugin disconnects peers sending oversized incoming lines and progressively delays reconnects after repeated short-lived connections.

Merge readiness

✅ Ready for maintainer review

This remains a useful, unmerged repair: current main and the latest release retain the unbounded input buffer. No blocking introduced defect was found, and verified maintainer acceptance covers the compatibility and recovery tradeoffs.

Priority: P2
Reviewed head: f736f668d165f8f4b5f30e807fb3550d66adaabe

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused reliability patch with meaningful socket-boundary evidence, accepted tradeoffs, and no blocking introduced finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Captured after-fix observations and inspected real TCP tests exercise connectIrcClient through oversized input, socket teardown, disconnect notification, and continued legal traffic; the production monitor socket case demonstrates recovery after a failed reconnect. Schedule/reset unit tests supplement that evidence. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured after-fix observations and inspected real TCP tests exercise connectIrcClient through oversized input, socket teardown, disconnect notification, and continued legal traffic; the production monitor socket case demonstrates recovery after a failed reconnect. Schedule/reset unit tests supplement that evidence. No stored-data contract changes.
Evidence reviewed 11 items Pinned introduction: The merge-base-to-head patch introduces only the IRC framing bound, reconnect policy, and their tests; unrelated endpoint drift is not attributed to this PR.
Current main still needs the repair: Current main appends decoded socket chunks until a newline arrives without bounding the pending string. The existing 512-byte constant controls outbound messages.
Latest-release check: The client blob at latest release v2026.9.8 also appends socket chunks without an inbound ceiling; the requested protection is not already shipped there.
Findings None None.
Security None None.

How this fits together

The IRC client receives server data for channel monitoring, status probes, and transient sends. Accepted messages enter the existing message-processing path; unexpected disconnects trigger the monitor’s reconnect lifecycle.

flowchart TD
  A[IRC server data] --> B[Shared IRC client]
  B --> C{Line within ceiling?}
  C -->|Yes| D[Parse and deliver messages]
  C -->|No| E[Report error and destroy socket]
  E --> F[Monitor reconnect backoff]
  F --> B
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +68, Tests +205. Total +273 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 77 9 +68
Tests 3 206 1 +205
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 283 10 +273

Review metrics

Metric Value Why it matters
Connection policy 16,384-code-unit ceiling; reconnects start at 1–1.2s and cap at 30s; reset after 60s These operator-visible limits are explicitly accepted and add no configuration option.
Production versus test growth Production +68 net lines; tests +205 net lines Production growth implements bounded framing and connection-stability tracking, with socket and schedule coverage supporting those responsibilities.

Technical review

Best possible solution:

Keep the shared client’s bounded framing and the monitor’s capped reconnect policy, preserving the existing ingress and connection-safety owners.

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

Yes, source establishes the current-main failure path: a registered IRC peer can keep appending data without a newline indefinitely. This read-only review did not execute it; the captured contributor evidence reports failing baseline socket cases.

Is this the best way to solve the issue?

Yes, the patch fixes framing in the shared socket client and retains the existing reconnect owner, using the supported backoff helper. The ceiling and slower recovery have explicit, verified acceptance.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a focused IRC reliability repair without evidence of an active widespread outage.
  • merge-risk: 🚨 compatibility: Previously accepted records above the ceiling now disconnect; the verified maintainer explicitly accepted this limitation without an override.
  • merge-risk: 🚨 availability: Repeated failures can postpone reconnection for up to 30 seconds; the verified maintainer accepted this recovery tradeoff.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Captured after-fix observations and inspected real TCP tests exercise connectIrcClient through oversized input, socket teardown, disconnect notification, and continued legal traffic; the production monitor socket case demonstrates recovery after a failed reconnect. Schedule/reset unit tests supplement that evidence. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured after-fix observations and inspected real TCP tests exercise connectIrcClient through oversized input, socket teardown, disconnect notification, and continued legal traffic; the production monitor socket case demonstrates recovery after a failed reconnect. Schedule/reset unit tests supplement that evidence. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction: The merge-base-to-head patch introduces only the IRC framing bound, reconnect policy, and their tests; unrelated endpoint drift is not attributed to this PR. (extensions/irc/src/client.ts:290, f736f668d165)
  • Current main still needs the repair: Current main appends decoded socket chunks until a newline arrives without bounding the pending string. The existing 512-byte constant controls outbound messages. (extensions/irc/src/client.ts:284, 11d3d04a1279)
  • Latest-release check: The client blob at latest release v2026.9.8 also appends socket chunks without an inbound ceiling; the requested protection is not already shipped there. (extensions/irc/src/client.ts:284, fc23bc864e45)
  • Overflow lifecycle: Both complete oversized lines and pending unterminated input clear the buffer and destroy the socket. Subsequent data is ignored, while the existing close listener supplies post-registration disconnect notification. (extensions/irc/src/client.ts:292, f736f668d165)
  • Reconnect ownership and shared contract: The monitor remains the reconnect owner. Its private policy uses the existing runtime-env SDK export of computeBackoff, whose implementation applies positive jitter and clamps the result to maxMs. Connection uptime is cleared when scheduling a retry, preventing failed registrations from inheriting earlier uptime. (extensions/irc/src/reconnect-backoff.ts:28, f736f668d165)
  • Accepted compatibility and recovery tradeoffs: The decision comment at fix(irc): bound pending inbound line length #165018 (comment) explicitly accepts the 16,384-code-unit ceiling without an override, recovery delays up to 30 seconds, and the 60-second stability reset. GitHub’s permission endpoint independently confirms eleqtrizit has role maintain and write permission, resolving the conflicting association metadata. These accepted limitations are not outstanding blockers.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • zhangguiping-xydt: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-10-04T16:58:51.514Z sha d20994d810efd31ba6f6f96a36fb4c4c70da7fb3 :: blocked before merge. :: none
  • reviewed 2026-10-04T17:58:36.387Z sha d20994d810efd31ba6f6f96a36fb4c4c70da7fb3 :: blocked before merge. :: none
  • reviewed 2026-10-04T22:00:36.095Z sha e668c7d911f3d37654cca67437c958dc2961ddc3 :: blocked before merge. :: none
  • reviewed 2026-10-04T23:04:59.284Z sha 7716582a6372e44d741790999f02da12df3b2116 :: blocked before merge. :: none
  • reviewed 2026-10-05T01:12:48.141Z sha 7716582a6372e44d741790999f02da12df3b2116 :: needs changes before merge. :: none
  • reviewed 2026-10-05T18:31:15.972Z sha 7716582a6372e44d741790999f02da12df3b2116 :: needs maintainer review before merge. :: none

@eleqtrizit

eleqtrizit commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Design note on the inbound ceiling.

This PR deliberately uses a higher limit, 16,384 UTF-16 code units, than the stricter 512-byte bound proposed in #156015. The choice is to tolerate longer server records as a precaution: the ceiling sits above the IRCv3 maximum of 8191 bytes of message tags plus a 512-byte body, so a compliant server, including one that sends long tagged lines, never reaches it.

The memory protection is effectively the same. Either bound stops a peer from making the Gateway process retain an unterminated line without limit. The difference is compatibility: every line accepted under the 512-byte bound is also accepted here, and only non-spec lines over 16 KiB are dropped.

This is not fully backward compatible. A peer that sends a line over the ceiling is disconnected and goes through the existing reconnect path, and there is no configuration override. That should OK, as no server running a real spec should do that, and 16,384 is more than enough "buffer" over the spec of 8191

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@eleqtrizit

Copy link
Copy Markdown
Contributor Author

Maintainer decision (@eleqtrizit): accepting the recovery tradeoff of the capped reconnect backoff.

Repeated outages can delay recovery by up to 30 seconds, extending the interval when IRC messages cannot reach OpenClaw. That is accepted in exchange for bounding reconnect churn against a peer that is dropped on every connection. The first reconnect stays at 1 second, and a connection that stays up for 60 seconds resets the delay to 1 second. There is no configuration override.

This records acceptance of the reconnect backoff only. The inbound ceiling and any consolidation with #156015 are covered separately in the design note above.

@eleqtrizit

Copy link
Copy Markdown
Contributor Author

Maintainer decision (@eleqtrizit): I accept the conditions described in this thread.

  • Inbound ceiling: lines over 16,384 UTF-16 code units are disconnected, with no configuration override. This is a deliberate, higher limit than the 512-byte bound in fix(irc): disconnect when an inbound line exceeds 512 bytes #156015, and this PR's ceiling is the policy I am choosing for the overlapping fix.
  • Recovery: the capped reconnect backoff (1s initial, 30s cap, reset after a 60s stable connection), including that repeated outages can delay recovery by up to 30 seconds, as recorded in the earlier decision comment.
  • Compatibility: this is not fully backward compatible, and I accept that for peers that send lines above the ceiling.

This covers the three "Before merge" items in the latest review.

@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@eleqtrizit
eleqtrizit marked this pull request as ready for review October 5, 2026 18:27
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

Merge record

Summary: Bounds the IRC client's pending inbound line at 16,384 UTF-16 code units, so a peer that never terminates a line can no longer make the Gateway retain memory without limit; an overflowing peer is disconnected through the existing monitor path. Adds a capped reconnect backoff (1s initial, 30s cap, reset after a 60s stable connection) so a repeatedly dropped peer cannot drive one-second reconnect cycles. Compliant servers, including those sending long IRCv3 tagged lines, are unaffected.

Decision Reason for Merge: Merged because the maintainer recorded acceptance of the inbound ceiling and the reconnect-backoff tradeoffs in this thread and requested the merge; openclaw/ci-gate and check-guards were still pending at merge time, with 37 checks passing and none failing.

Compatibility Checks Done: IRC client, monitor, probe, send and reconnect-backoff suites pass on the reviewed head f736f66, including tests that fail against the unmodified client; check:changed passed locally (the dead-export stage was skipped because that guard fails identically on a clean upstream/main checkout, in files this PR does not touch). No config, default, SDK signature, or wire-format change. Not fully backward compatible: lines over 16,384 code units now disconnect, which the maintainer explicitly accepted in this thread. Hosted CI: 37 passing, 0 failing at merge time.

@eleqtrizit
eleqtrizit merged commit 0ac81cf into openclaw:main Oct 5, 2026
94 checks passed
@eleqtrizit
eleqtrizit deleted the 1092 branch October 5, 2026 20:31
@SebTardif

Copy link
Copy Markdown
Contributor

@eleqtrizit

#156015 was already open when this pull was filed. It covered the same unbounded inbound buffer.

Two tests from that pull still fit this 16,384 code-unit ceiling, and they are not in this tree:

  • A legal line split across two socket writes is parsed. A PING in that line gets a PONG, the client stays ready, and onDisconnect is not called.
  • An oversized line before welcome rejects connectIrcClient and does not call onDisconnect.

The third test in #156015 measured a 512-byte UTF-8 cap, including a multibyte NOTICE. That is a different limit from the one that landed, so that test should not be copied as-is.

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

Labels

channel: irc merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: M 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