Skip to content

improve(irc): reuse transient connection for chunked sends - #128487

Merged
steipete merged 3 commits into
mainfrom
codex/perf-irc-outbound-current
Aug 24, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/perf-irc-outbound-current

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Summary

  • route ordinary IRC formatted text through the channel-owned formatted-send seam
  • project all configured chunks/reply fanout first, then send them through one transient IRC connection
  • preserve single-send/media entry points and per-chunk abort, dispatch, activity, receipt, and delivery-result behavior

Root cause

Core chunks a long ordinary IRC message before transport. The prior IRC adapter called sendText once per chunk, and every call independently connected, authenticated, joined, sent, and quit. A three-chunk message therefore paid three complete connection handshakes even though the chunks belonged to one prepared outbound operation.

The fix keeps canonical IRC chunk mode, text limit, reply fanout, Markdown/table projection, and the raw client's independent 512-byte line enforcement, while batching only the already-related text chunks through one transient client.

No cache, public SDK, config, protocol, security, storage, media, or retry/idempotency behavior changes.

Why this boundary

  • A cross-send connection cache would add lifecycle, invalidation, and concurrency state.
  • Changing the raw client's 512-byte chunking would alter provider protocol behavior.
  • Channel-owned sendFormattedText already represents one prepared outbound operation and is the narrow owner that can reuse one transient connection without crossing message boundaries.

Verification

  • Current-main relevant preimage blobs exactly match the frozen proven baseline; the full-index patch applied without adaptation.
  • Exact-base regression: one intended failure before the formatted-send owner existed; candidate green.
  • Full current IRC extension: 19 files / 159 tests passed.
  • check:changed passed formatting, production/test types, type-aware Oxlint (0 findings), dead exports, boundaries, guards, and import cycles.
  • git diff --check passed.
  • TruffleHog clean; Codex gpt-5.6-sol high autoreview found no issue (0.98 correct).
  • Stable patch ID: 922d58803db12ae191b3c0b4ccd8b18ee1e99d95.

Frozen loopback proof used a 15 ms welcome delay and 12 ordinary three-chunk sends with explicit reply fanout:

  • connections: 36 → 12 (-66.67%)
  • total elapsed: 656.22 ms → 249.84 ms (-61.93%, 2.627x faster)
  • median: 52.76 ms → 19.06 ms (-63.87%)
  • recipient wire payload SHA-256 remained identical: e21d1a7b929d819735632b349721f76d1a49513bddd94bc64a4448a18c192190

No live credentialed IRC provider mutation was performed; the retained loopback server exercised the real socket/client boundary.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 24, 2026 04:17
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 24, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. 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 Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 1:34 AM ET / 05:34 UTC.

ClawSweeper review

What this changes

The PR sends all chunks from one formatted IRC outbound operation through one transient IRC connection instead of reconnecting for every chunk.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The patch is source-correct and retains the IRC plugin as the connection-lifecycle owner, but this maintainer-labeled PR needs an explicit availability-risk decision before merge.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch follows the typed plugin seam and covers cancellation and closure behavior, with one maintainer-visible availability proof tradeoff remaining.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its body nevertheless provides real loopback batching evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its body nevertheless provides real loopback batching evidence.
Evidence reviewed 6 items Current-main behavior: Current main opens, joins, sends, and quits a transient client inside each individual IRC send; that is the repeated-handshake path this PR replaces.
Changed owner boundary: The PR installs a typed formatted-send handler in the IRC plugin and batches projected chunks through one operation-local sender.
Cancellation and disconnect fencing: The new sender checks abort and client readiness before and after the per-chunk dispatch callback, then closes a transient client in finally; focused tests cover cancellation during connect and closure between chunks.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/irc/src/send.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs extensions/irc/src/send.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128487-vEMdPF/target$ node scripts/run-vitest.mjs extensions/irc/src/send.test.ts
node scripts/run-vitest.mjs extensions/irc/src/send.test.ts
[test] starting test/vitest/vitest.extension-irc.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128487-vEMdPF/target

 ✓  extension-irc  extensions/irc/src/send.test.ts (10 tests) 99ms

 Test Files  1 passed (1)
      Tests  10 passed (10)
   Start at  05:35:43
   Duration  11.39s (transform 9.00s, setup 943ms, import 10.00s, tests 99ms, environment 0ms)

[test] passed 1 Vitest shard in 17.00s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128487-vEMdPF/target$ node scripts/run-vitest.mjs extensions/irc/src/send.test.ts



































Assertions:

  • PASS expect_output: Test Files

How this fits together

Shared outbound delivery prepares formatted text and passes it to the IRC plugin. The plugin projects chunks and reply fanout, sends them through an IRC client, and returns delivery results to the shared delivery layer.

flowchart LR
  A[Prepared outbound text] --> B[IRC formatted send]
  B --> C[Chunk and reply projection]
  C --> D[Transient IRC connection]
  D --> E[IRC server]
  E --> F[Delivery results]
Loading

Decision needed

Question Recommendation
Is mock-based mid-batch disconnect coverage sufficient for this shared IRC connection change, or should merge require a loopback peer-disconnect trace? Require loopback disconnect proof: Capture a real IRC socket/client loopback run that closes the peer connection between chunks and confirms later chunks are not written.

Why: The PR changes an availability boundary and carries the protected maintainer label, so a human should weigh the measured performance gain against the remaining fault-injection evidence gap.

Before merge

  • Resolve merge risk (P1) - The latest regression test simulates a client closing between chunks, while the supplied real loopback proof measures only successful connection reuse; a peer-disconnect trace remains the unproven availability case.
  • Complete next step (P2) - The protected maintainer label and availability-proof tradeoff require human merge judgment rather than an automated repair.
Agent review details

Security

None.

PR surface

Source +111, Tests +142. Total +253 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 156 45 +111
Tests 2 144 2 +142
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 300 47 +253

Review metrics

Metric Value Why it matters
Production versus test LOC production +156/-45; tests +144/-2 The added production code establishes the operation-local batching and lifecycle boundary; the test growth covers its chunk, cancellation, and closed-connection cases.

Merge-risk options

Maintainer options:

  1. Require loopback disconnect proof (recommended)
    Capture a peer disconnect between chunks through the real IRC socket/client boundary before landing.
  2. Accept focused regression coverage
    Land with the current cancellation and closed-client tests if the maintainer accepts the remaining fault-injection evidence gap.

Technical review

Best possible solution:

Keep the plugin-owned, operation-local connection design and either capture a real loopback peer-disconnect trace or explicitly accept the focused mock coverage before merge.

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

Yes in source: current main reconnects once per IRC chunk send, while this PR supplies one formatted operation that reuses its client.

Is this the best way to solve the issue?

Yes: the IRC plugin owns the prepared outbound operation, avoiding a core special case, raw-client behavior change, or cross-operation cache.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1ece62a4d807.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦐 gold shrimp.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded IRC delivery performance and lifecycle change without evidence of an urgent user-facing outage.
  • merge-risk: 🚨 availability: One transient client now carries multiple chunks, so a failed shared connection can affect the remainder of one outbound operation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its body nevertheless provides real loopback batching evidence.

Evidence

What I checked:

  • Current-main behavior: Current main opens, joins, sends, and quits a transient client inside each individual IRC send; that is the repeated-handshake path this PR replaces. (extensions/irc/src/send.ts:91, 1ece62a4d807)
  • Changed owner boundary: The PR installs a typed formatted-send handler in the IRC plugin and batches projected chunks through one operation-local sender. (extensions/irc/src/message-adapter.ts:53, 93f1e1b88f3d)
  • Cancellation and disconnect fencing: The new sender checks abort and client readiness before and after the per-chunk dispatch callback, then closes a transient client in finally; focused tests cover cancellation during connect and closure between chunks. (extensions/irc/src/send.ts:115, 93f1e1b88f3d)
  • Caller and contract: Shared delivery uses a channel-provided formatted-text handler for text payloads, and the plugin SDK defines it as returning one result per delivery. (src/infra/outbound/deliver-core.ts:407, 1ece62a4d807)
  • Feature history: Available history attributes the current IRC send implementation to the recent message-adapter work, while the original IRC channel implementation dates to the initial IRC feature commit. (extensions/irc/src/send.ts:58, c8514ed20a3b)
  • Current-main and release status: The PR head is distinct from current main and from the provided latest release v2026.7.1-2, so its batching behavior is neither implemented on main nor shipped. (extensions/irc/src/send.ts:91, 93f1e1b88f3d)

Likely related people:

  • Peter Steinberger: Current-main history includes the IRC message-adapter refactor and the latest adjacent outbound change. (role: recent IRC outbound contributor; confidence: high; commits: 83307f6bc7ec, c8514ed20a3b; files: extensions/irc/src/channel.ts, extensions/irc/src/message-adapter.ts, extensions/irc/src/send.ts)
  • Vignesh: The initial first-class IRC channel commit introduced the transport surface later refined here. (role: original IRC feature contributor; confidence: medium; commits: fa906b26add7; files: extensions/irc/src/send.ts)

Rank-up moves

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

  • For stronger merge confidence, add a real loopback peer-disconnect trace showing later chunks are not written.

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 (2 earlier review cycles)
  • reviewed 2026-08-24T04:25:20.383Z sha d2a64ae :: needs changes before merge. :: [P1] Propagate cancellation before the transient JOIN
  • reviewed 2026-08-24T05:03:44.597Z sha d2de917 :: needs maintainer review before merge. :: none

Copy link
Copy Markdown
Contributor Author

Land-ready disposition for exact head d2de91705d17eb00459faed32002ba0b61aeb4ff.

Root cause and best fix

Core prepared a long IRC text as N chunks, while each adapter call independently opened, authenticated, joined, sent, and quit a transient IRC connection. The channel-owned formatted-send seam is the narrow owner that knows those chunks are one outbound operation, so it now projects canonical chunk/reply fanout once and sends all chunks through one operation-local client. A cross-send cache was rejected because it adds connection lifetime/concurrency/invalidation state; raw-client batching was rejected because that layer owns IRC protocol line limits rather than outbound operation semantics; a core IRC special case was rejected because provider transport ownership belongs in the plugin.

Production LOC: +149/-45 (net +104) | Tests: +101/-2. The positive production delta implements the formatted-operation owner, canonical chunk/reply/lifecycle parity, and abort-aware transient connection setup without public/config/protocol/storage state.

ClawSweeper disposition

The review finding on prior head d2a64ae2de219d7a16e77de1eb918e981ca0c3cf is resolved exactly:

  • abortSignal is forwarded into transient connection setup.
  • Cancellation is rechecked immediately after the await, before JOIN or PRIVMSG, inside owned try/finally cleanup.
  • A delayed-connect regression proves cancellation causes no JOIN/PRIVMSG and still quits the returned transient client (focused 9/9).
  • The stated merge risk and next-step item are therefore complete.
  • Both rank-up moves—abort-aware fencing/cleanup and delayed-connect cancellation coverage—are present.

The current-head follow-up is limited to that finding and its focused test. Final changed-file gates passed, and fresh TruffleHog plus Codex gpt-5.6-sol/high autoreview found no issue (0.99 confidence).

Proof

  • Exact-base batching regression: intended red, then green.
  • Full IRC extension: 19 files / 159 tests passed before the finding-only follow-up; focused current-head cancellation suite: 9/9 passed.
  • Loopback provider boundary: 36 → 12 connections (-66.67%); 656.22 → 249.84 ms total (-61.93%); recipient wire bytes remained identical (e21d1a7b929d819735632b349721f76d1a49513bddd94bc64a4448a18c192190).
  • Exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/32691904907
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128487 passed at the exact head with hosted exact-head gates.
  • Latest origin/main has no commits touching the five PR paths since the merge base; git merge-tree --write-tree origin/main HEAD completed without conflict.

Provenance

fa906b26add7148114c894eac53f6f73d9c06b36 (Vignesh, 2026-02-10) introduced one transient connection per sendMessageIrc; 83307f6bc7ec7caca9fc45bb9f0add16c182eeea later delegated each outbound send to that adapter. Core chunk fanout made the per-call lifecycle N handshakes for one ordinary message.

Remaining proof gap: no credentialed external IRC send was performed. The retained deterministic loopback exercised the real socket/client boundary, including connection count, ordered wire payloads, and cancellation cleanup.

Copy link
Copy Markdown
Contributor Author

Final maintainer disposition for exact head 93f1e1b88f3d4f3430fd20bedfa2790d1213366e: land ready.

ClawSweeper's recommended availability option—require a real loopback peer-disconnect proof—was selected and completed. The alternative to accept mock-only coverage was not used.

Real peer-disconnect trace

A temporary, source-hash-recorded Vitest proof used the actual Node TCP boundary, actual connectIrcClient, and actual sendIrcMessages:

  1. A loopback IRC peer accepted exactly one TCP connection and completed registration.
  2. The operation supplied two prepared chunks.
  3. The peer recorded PRIVMSG #room :first, immediately destroyed the socket, and the first delivery callback waited until the real client's isReady() became false.
  4. The operation rejected with IRC connection closed before send before the second chunk.
  5. Final assertions: connectionCount === 1, wire PRIVMSGs exactly ["PRIVMSG #room :first"], and deliveryCount === 1.

node scripts/run-vitest.mjs extensions/irc/src/send.loopback-proof.test.ts passed 1 file / 1 test. Proof-source SHA-256: d1b7b2e76d33a09382a9c3a8b8a955f430c628d14f2ac5b297861e31c1dd6153. The temporary proof file was removed after the run; the task branch is clean.

This closes the exact merge-risk question without adding reconnect/resend behavior: a prior socket.write has ambiguous IRC delivery and no idempotency key, so only definitely unattempted suffix chunks are stopped. No fabricated suffix receipt is emitted.

Final evidence

  • ClawSweeper exact-head source review: patch correct, no review findings, security cleared; the sole maintainer decision was the now-completed loopback trace.
  • Exact-head CI green: https://github.com/openclaw/openclaw/actions/runs/32693646750
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128487 passed at the exact head.
  • Full IRC extension: 19 files / 161 tests passed.
  • Final changed-file gate passed formatting, production/test types, Oxlint 0/0, dead exports, boundaries, guards, and cycles.
  • Fresh local TruffleHog plus Codex gpt-5.6-sol/high autoreview: no P0 findings, patch correct at 0.99 confidence.
  • Successful batching loopback remains byte-identical and reduced connections 36 → 12 and elapsed time 656.22 → 249.84 ms.
  • Production LOC: +156/-45 (net +111) | Tests: +144/-2.
  • Latest origin/main has no commits touching the five PR paths since the merge base; git merge-tree --write-tree origin/main HEAD completed without conflict.

No credentialed external IRC mutation was performed. The deterministic real socket/client loopback now covers both successful batching and peer-disconnect suffix suppression at the transport boundary.

@steipete
steipete merged commit c34b97f into main Aug 24, 2026
99 checks passed
@steipete
steipete deleted the codex/perf-irc-outbound-current branch August 24, 2026 05:44

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

channel: irc maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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