Repository navigation
fix(irc): bound pending inbound line length - #165018
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 3:09 PM ET / 19:09 UTC (Revision 7). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +68, Tests +205. Total +273 across 6 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
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 |
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
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. |
|
Maintainer decision (@eleqtrizit): I accept the conditions described in this thread.
This covers the three "Before merge" items in the latest review. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Merge recordSummary: 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. |
* fix(irc): bound pending inbound line length * fix(irc): back off reconnects after repeated short-lived connections
|
#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:
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. |
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
close()is a no-op afterquit(), which only half-closes.closelistener soonDisconnectfires and the monitor's existing reconnect path runs. No new callback, option or config key.computeBackoffhelper fromopenclaw/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.onDisconnectsignal; adds no new lifecycle stateclient.tsandclient.test.ts, so one must rebase on the otherEvidence
line longer than 16384, socket destroyed, disconnect reportedonLine; disconnect reportedObserved 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.tsalone 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
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.pnpm run check:changed --base upstream/main: exit 0 (typecheck, dead-export scan, lint).