Skip to content

fix(irc): disconnect when an inbound line exceeds 512 bytes - #156015

Closed
SebTardif wants to merge 2 commits into
openclaw:mainfrom
SebTardif:fix/irc-inbound-line-byte-limit
Closed

SebTardif wants to merge 2 commits into
openclaw:mainfrom
SebTardif:fix/irc-inbound-line-byte-limit

Conversation

@SebTardif

@SebTardif SebTardif commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The IRC client already refuses to send a line longer than 512 bytes. Inbound bytes were different. Socket data was appended until a line feed arrived, with no maximum. A peer that never sends LF keeps that buffer until the process runs out of memory.

Complete lines and the still-pending record are now measured in UTF-8 bytes. More than 510 bytes of payload (512 including CRLF) reports IRC inbound line exceeds the 512-byte limit and destroys the socket. A legal 512-byte line, including one split across two writes, still parses, and PING still receives PONG.

Closing the socket from this limit sets the closed flag before the socket emits close. The close listener therefore never runs. After registration, the client now calls the disconnect callback once so the channel monitor can reconnect. Before registration, and on an ordinary quit, that callback stays silent.

This client does not parse IRCv3 message tags. A server that sends a tagged line over 512 bytes will be disconnected. That is the same wire cap already used for outbound PRIVMSG.

Pull request 107376 added this bound earlier and was closed by its author on 2026-07-19. The unbounded buffer is still on main. There is no open issue for this defect.

Evidence

Terminal output from production connectIrcClient against a loopback TCP server on 127.0.0.1. Node v26.9.0. The command ran in the patched tree and is not part of the diff.

Before the bound, the same unterminated 1 MiB write left the socket open for more than one second. Before the disconnect callback, a registered client closed on that write without notifying the monitor.

After the bound and the disconnect callback:

$ pnpm exec tsx proof-irc-line-limit.mts
node v26.9.0
legal line bytes 512
legal ping seen true
ready after legal line true
PONG bytes 510
disconnects after legal line 0
oversized close ms 5
oversized errors ["IRC inbound line exceeds the 512-byte limit"]
disconnects after oversized 1
ready after oversized false
open sockets 0
before ready error IRC inbound line exceeds the 512-byte limit
disconnects before ready 0
open sockets before ready 0
disconnects after quit 0
open sockets after quit 0
DONE

Real behavior proof

  • Behavior or issue addressed: Inbound IRC data with no line feed was retained with no size cap. Complete lines and the pending record now close the socket when the UTF-8 payload exceeds 510 bytes. After registration that close notifies the disconnect callback once. Before registration, and on quit, it does not.
  • Real environment tested: macOS, Node v26.9.0, production connectIrcClient from the patched tree, loopback TCP on 127.0.0.1.
  • Exact steps or command run after this patch: From the patched tree, start a loopback TCP server, call connectIrcClient, write a 510-byte PING split after 200 bytes followed by CRLF, then write 1 MiB with no line feed. Repeat with 600 bytes before the welcome numeric, and with quit after welcome. Command: pnpm exec tsx proof-irc-line-limit.mts
  • Evidence after fix: terminal output copied below.
$ pnpm exec tsx proof-irc-line-limit.mts
node v26.9.0
legal line bytes 512
legal ping seen true
ready after legal line true
PONG bytes 510
disconnects after legal line 0
oversized close ms 5
oversized errors ["IRC inbound line exceeds the 512-byte limit"]
disconnects after oversized 1
ready after oversized false
open sockets 0
before ready error IRC inbound line exceeds the 512-byte limit
disconnects before ready 0
open sockets before ready 0
disconnects after quit 0
open sockets after quit 0
DONE
  • Observed result after fix: The 512-byte PING was accepted, the client stayed ready, and the PONG line was 510 bytes. The disconnect callback stayed at 0. The unterminated 1 MiB write closed the peer in 5 ms, reported IRC inbound line exceeds the 512-byte limit, called the disconnect callback once, left isReady false, and left no peer socket open. The same oversized write before welcome rejected registration, called the callback 0 times, and closed the socket. quit after welcome also called the callback 0 times.
  • What was not tested: A public IRC network, TLS, and IRCv3 tagged lines longer than 512 bytes. Those oversized tagged lines now disconnect. The channel monitor reconnect delay was not part of this loopback run. The monitor already schedules that delay from the same disconnect callback.

A peer that never sends LF could grow the IRC client buffer without
bound. Complete lines and the pending record now use the same 512-byte
wire limit as outbound PRIVMSG, then the socket closes.

Signed-off-by: Sebastien Tardif <[email protected]>
@clawsweeper

clawsweeper Bot commented Sep 22, 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 P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. labels Sep 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 29, 2026, 1:38 PM ET / 17:38 UTC (Revision 4).

ClawSweeper review

What this changes

The IRC plugin closes connections on oversized inbound lines, notifies its reconnect monitor after registration, and adds loopback socket regression tests.

Merge readiness

⛔ Blocked before merge - 3 items remain

The current main branch still has an unbounded IRC receive buffer, and this PR addresses it with credible production-path proof. The remaining merge choice is whether disconnecting on every line over 512 bytes is acceptable for existing IRC connections.

Priority: P2
Reviewed head: beefebe34dba295e36f180538b56d9e55419f15a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused production-path proof and socket tests support a small repair, with the connection-policy tradeoff awaiting owner acceptance.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The contributor’s macOS loopback TCP trace exercises the patched production IRC client: a legal split line receives PONG, an oversized unterminated record closes the socket, and a registered client notifies disconnect once. 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 (terminal): The contributor’s macOS loopback TCP trace exercises the patched production IRC client: a legal split line receives PONG, an oversized unterminated record closes the socket, and a registered client notifies disconnect once. No stored-data contract changes.
Evidence reviewed 7 items Introduced receive bound: The pinned PR head checks complete and pending lines against a 510-byte payload limit and closes on an oversized record.
Current main remains unbounded: The fetched main revision appends socket data and parses newline-delimited records without the proposed inbound limit.
Reconnect behavior: The monitor pauses ingress and schedules a reconnect when the client calls its disconnect callback.
Findings None None.
Security None None.

How this fits together

OpenClaw’s IRC plugin reads server data from a TCP or TLS socket, parses lines, and passes accepted messages to the channel monitor. The monitor manages reconnects and subsequent message delivery.

flowchart LR
  A[IRC server bytes] --> B[IRC client buffer]
  B --> C{Line within limit?}
  C -->|Yes| D[Parse IRC message]
  D --> E[Channel monitor]
  C -->|No| F[Close socket]
  F --> G[Reconnect monitor]
Loading

Decision needed

Question Recommendation
Should the IRC plugin disconnect and retry whenever a server sends an inbound line over 512 bytes, including long tagged lines it does not parse? Accept the 512-byte bound: Approve the documented disconnect behavior to protect the IRC client from unbounded inbound records.

Why: The bound prevents unbounded memory retention but intentionally changes connection behavior for servers that send longer lines; the contributor’s disclosure is not an owner decision.

Before merge

  • Resolve merge risk (P1) - An existing server that sends lines over 512 bytes, including unsupported long tagged lines, will now make the IRC account disconnect and potentially reconnect repeatedly; the IRC owner has not accepted that compatibility and availability tradeoff.
  • Complete next step (P2) - Obtain the IRC owner’s decision on disconnecting for all inbound lines over 512 bytes, and record the focused test wall time and available CI seconds in the PR body.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +21, Tests +191. Total +212 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 21 0 +21
Tests 1 191 0 +191
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 212 0 +212

Review metrics

Metric Value Why it matters
Production versus test growth production +21, tests +191 The production growth is focused on receive bounds and reconnect notification; four socket tests exercise the affected boundary.

Root-cause cluster

Relationship: canonical
Canonical: #156015
Summary: The earlier closed, unmerged PR addressed the same unbounded IRC inbound record; this open PR is the active candidate.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept bounded disconnects (recommended)
    The IRC owner can accept repeated disconnects on oversized server lines as the cost of enforcing the receive bound.
  2. Pause for a different policy
    Keep the PR open while the IRC owner specifies how longer server lines should be bounded and handled.

Technical review

Best possible solution:

Keep the bounded IRC receive path and reconnect notification, then document the line-limit behavior once the IRC owner confirms the tradeoff.

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

Yes, from source: current main appends unterminated IRC data without a bound. The contributor also supplied before-and-after loopback observations; this review did not execute the PR code.

Is this the best way to solve the issue?

Yes for the memory-retention defect: bounding the client’s receive buffer and notifying its existing reconnect owner is a narrow repair. The disconnect policy for longer server lines still needs owner acceptance.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded IRC reliability and memory-use repair with a channel-specific blast radius.
  • merge-risk: 🚨 compatibility: Connections that previously tolerated server lines over 512 bytes will now close.
  • merge-risk: 🚨 availability: A server that repeatedly sends oversized lines can keep the IRC account in a reconnect cycle.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The contributor’s macOS loopback TCP trace exercises the patched production IRC client: a legal split line receives PONG, an oversized unterminated record closes the socket, and a registered client notifies disconnect once. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The contributor’s macOS loopback TCP trace exercises the patched production IRC client: a legal split line receives PONG, an oversized unterminated record closes the socket, and a registered client notifies disconnect once. No stored-data contract changes.

Evidence

What I checked:

  • Introduced receive bound: The pinned PR head checks complete and pending lines against a 510-byte payload limit and closes on an oversized record. (extensions/irc/src/client.ts:304, beefebe34dba)
  • Current main remains unbounded: The fetched main revision appends socket data and parses newline-delimited records without the proposed inbound limit. (extensions/irc/src/client.ts:290, 16b17b22ebc1)
  • Reconnect behavior: The monitor pauses ingress and schedules a reconnect when the client calls its disconnect callback. (extensions/irc/src/monitor.ts:176, beefebe34dba)
  • Real behavior proof: The PR body records a patched production IRC client against a macOS loopback TCP server: a split legal line received PONG, an unterminated 1 MiB record closed the socket in 5 ms, and the registered client invoked disconnect once. This is contributor-supplied terminal evidence. (beefebe34dba)
  • Earlier related attempt: The provided GitHub context identifies fix(irc): disconnect on oversized inbound lines #107376 as a closed, unmerged attempt at the same inbound bound; it does not replace this PR.
  • Feature history: IRC client history includes the reconnect repair by xingzhou and several later IRC changes by Peter Steinberger. Partial-clone parent blobs were unavailable for source-line introduction verification. (extensions/irc/src/client.ts, 16b17b22ebc1)

Likely related people:

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

Rank-up moves

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

  • Record the focused client-test wall time and available CI seconds in the PR body.

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 (3 earlier review cycles)
  • reviewed 2026-09-22T23:39:22.515Z sha 5290dfe :: blocked before merge. :: [P1] [P1] Notify the monitor when rejecting an oversized inbound line
  • reviewed 2026-09-23T01:44:02.270Z sha beefebe :: needs changes before merge. :: none
  • reviewed 2026-09-27T02:02:08.231Z sha beefebe :: blocked before merge. :: none

…ient

failAndClose marks the socket closed before destroy, so the close
listener never runs. After registration, report that disconnect once
so the channel monitor can reconnect. Before registration, and on
quit, leave the callback silent.

Signed-off-by: Sebastien Tardif <[email protected]>
@clawsweeper clawsweeper Bot added 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. clawsweeper-recovery-stuck 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper-recovery-stuck labels Sep 23, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 14, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @SebTardif for identifying the unbounded receive buffer and adding socket regression coverage. This is already addressed on main by #165018, merged as 0ac81cf6ec1a93acad4abe7e57bd8fe7537afa23.

I verified that current main still bounds both complete and unterminated records, clears the buffer and destroys the socket on overflow, and reports disconnect through the existing reconnect path. Its 16,384-code-unit framing ceiling leaves room for IRCv3 tags instead of applying the outbound 512-byte limit to the entire inbound record. Closing as already fixed; thank you for the report and tests.

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 stale Marked as stale due to inactivity 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