Description
Problem
The shellper's replay buffer is bounded by line count (10,000 lines) plus an unbounded whole-kept partial. A full-screen TUI (Claude sessions) redraws in place via cursor addressing and emits almost no newlines, so an entire multi-day session accumulates as one line that never ends: the line cap never triggers and the buffer grows monotonically for the life of the session.
Measured impact (from the #1198 incident, 2026-07-19):
- Two six-day-old architect sessions reached 17.6MB / 17.7MB replay buffers — past the 16MB
MAX_FRAME_SIZEwire cap. The resulting oversized REPLAY frame deterministically errored Tower's parser on every reconnect. On pre-Shellper reconnect error is swallowed: terminal becomes a silent zombie (no input/output, 'Message sent' logged for dropped frames) until next Tower restart #1198 code that swallowed error minted the original silent-zombie terminals; during the Shellper reconnect error is swallowed: terminal becomes a silent zombie (no input/output, 'Message sent' logged for dropped frames) until next Tower restart #1198 rollout it escalated to two killed sessions before the tolerant-parser fix landed. - A third live session is at 14MB and climbing (
Terminal partial monitor: max partial 14081 KB). - Of those megabytes, only roughly the final screenful (a few KB) is information a reconnecting viewer needs. The rest is every superseded repaint frame the TUI ever painted: spinner ticks, token-stream updates, status-bar refreshes.
Byte-trimming the buffer from the front was deliberately rejected previously (#1047): a trim can cut mid-escape-sequence or drop the alt-screen-enter, corrupting replay rendering. So the buffer is whole-by-design, and its growth is unbounded-by-design — but the wire (16MB frame cap) and the UI (xterm parse cost per attach) are not.
Containment already in place (PR #1204)
These make the current design safe, not right:
- Tower's frame parser discards oversized frames (
'frame-skipped') instead of treating them as fatal stream errors. - New shellpers truncate the replay they send to an 8MB tail (
REPLAY_PAYLOAD_MAX). - Adoption seeds at most a 1MB tail into the ring buffer (
RING_SEED_MAX_BYTES); viewers rely on the post-connect resize nudge to repaint TUIs.
Every cap is a lossy tail-cut that can transiently render rough until the nudge repaints. The buffer itself still grows without bound in shellper memory.
Proposed direction
Make replay O(screen), not O(session lifetime): store something screen-shaped rather than stream-shaped.
- Preferred: run PTY output through a headless terminal-state emulator inside the shellper and serve reconnecting clients the current screen state (plus bounded recent scrollback). Replay size becomes a few hundred KB at any session age, with no escape-sequence corruption risk, and the resize-nudge crutch becomes unnecessary.
- Cheaper alternative: reset the buffer at detectable full-frame boundaries (clear-screen / cursor-home redraw sequences), keeping only bytes since the last full repaint.
Wire-compat constraint: running shellpers are old binaries that survive Tower upgrades, so Tower must keep tolerating old-style (potentially oversized) replays regardless.
Acceptance criteria
- A session's replay payload stays bounded (well under
MAX_FRAME_SIZE) regardless of session age. - Reconnect replay renders the current screen correctly for alt-screen TUIs without relying on the post-connect resize nudge.
- Shellper memory for replay is bounded.
- The Shellper reconnect error is swallowed: terminal becomes a silent zombie (no input/output, 'Message sent' logged for dropped frames) until next Tower restart #1198 containment caps remain as defense-in-depth for old shellper binaries.
Activity
[PIR #1198] Thread: follow-up issue #1205 filed
waleedkadous commentedon Jul 19, 2026
amrmelsayed commentedon Jul 25, 2026
Escalation + new findings folded in from #1253 (closing that as duplicate of this)
Field escalation (2026-07-26 user report): the growth this issue predicted has reached multi-GB scale — opening an existing session was observed allocating several GB (up to ~10GB), causing memory pressure and sometimes process termination. This issue's 17MB data points were the early trajectory; heavy long-lived builder sessions (weeks of streamed test/tool output) are now the worst case.
New mechanism finding — the open-time allocation spike is the user-facing event:
getReplayData()runsBuffer.concat(this.chunks)over the ENTIRE accumulated history on every client connect (WELCOME path), transiently doubling the shellper's own footprint at exactly the moment a user opens the terminal. A ~5GB buffer → ~10GB peak → jetsam. The #1204/#1218 containment caps bound the WIRE (subarray applied after the concat) but not this allocation. This is why the symptom presents as 'opening a session consumes GBs' rather than gradual growth.Interim fix directions to consider alongside the preferred O(screen) emulator (which remains the right structural end-state):
chunksfrom the tail collecting only up toREPLAY_PAYLOAD_MAX, concat just those — O(cap) allocation per connect instead of O(history).maxBytes~16-32MB alongsidemaxLines): bounds the buffer itself. The mid-escape-corruption objection this issue cites from tower + vscode: terminal freeze from oversized-replay reconnect storm (unbounded no-newline buffers + client backpressure loop) #1047 is already de-facto accepted at the wire — every existing containment cap is a lossy tail-cut relying on the post-connect resize nudge — so extending the same lossy-tail-plus-nudge contract to the buffer is consistent, as defense-in-depth until the emulator lands.RingBuffer's whole-kept partial has the same no-newline growth (live monitor: ~2.6MB and +1MB/h on the busiest session at time of writing) and is copied per attach bygetAll()/getSince(); same cap-plus-nudge treatment applies.Deployment note: fixes 1/2 land in the shellper binary — per the detached-shellper design, only shellpers spawned after the upgrade benefit; long-lived pre-upgrade shellpers keep their accumulated buffers until restarted (or reaped by #1227's husk sweep if they qualify). Release notes should recommend restarting heavy long-lived sessions after upgrading.
Full elimination trail for the 10GB report (claude
--resumetranscripts: 570MB total on disk, none >50MB; disk logs: nothing reads them whole) is in #1253's body.amrmelsayed commentedon Jul 26, 2026
On it! Working on this with the PIR protocol (plan + dev-approval gates before PR).
[PIR #1205] Plan draft
[PIR #1205] Plan revised: drop misleading xterm citation from the emu…
[PIR #1205] Plan revised: emulator deferral now argued on resource-tr…
[PIR #1205] Plan revised: byte cap fixed at 8MB per architect decision
[PIR #1205] Cap the replay tail before concatenating it
[PIR #1205] Bound the replay buffer by bytes, not just lines
[PIR #1205] Cap the ring buffer's incomplete-line partial
[PIR #1205] Thread: implement-phase notes
[PIR #1205] Thread: record measured pre-existing test baseline
[PIR #1205] Thread: main merge clears the pre-existing test red
9 remaining items
[PIR #1205] Cap the ring buffer's incomplete-line partial
[PIR #1205] Thread: implement-phase notes
[PIR #1205] Thread: record measured pre-existing test baseline
[PIR #1205] Thread: main merge clears the pre-existing test red
[PIR #1205] Plan: name the attach path that actually triggers the rep…
[PIR #1205] Move REPLAY_BUFFER_MAX_BYTES to the buffer it configures
[PIR #1205] Plan: correct the emulator-placement and Phase-3 framing
[PIR #1205] Review + retrospective
[PIR #1205] Address both consultation REQUEST_CHANGES verdicts
[PIR #1205] Consultation response: both verdicts accepted, none rebutted
Merge pull request #1353 from cluesmith/builder/pir-1205
amrmelsayed commentedon Aug 5, 2026
Closing with PR #1353 merged (7b0eb1b): 3 of 4 acceptance criteria met — bounded retention (byte-cap eviction, ESC-aligned cuts), bounded connect-time allocation (capped tail-walk with the contiguity property test), containment caps retained as defense-in-depth. The field-escalated failure (multi-GB allocation spikes opening aged sessions, up to ~10GB → memory-pressure kills) is resolved for shellpers spawned on the fixed binary.
AC#2 (correct screen without the resize nudge) moves to #1354 — deliberately unmet here, and this issue's own proposal for it ('emulator inside the shellper') is now known-wrong on placement: clients read Tower's RingBuffer and never see the shellper REPLAY frame (arch.md corrected in the PR). #1354 carries the corrected Tower-side framing rather than leaving this body's misleading proposal as the tracker.
Deployment caveat for release notes (recorded, will ship with the release entry): only shellpers spawned AFTER the upgrade benefit — long-lived pre-upgrade shellpers keep their accumulated buffers until restarted or husk-swept. The heavy long-lived sessions most affected by this bug are exactly the ones an upgrade alone does not fix; restart them after upgrading.
changelog: bounded terminal replay memory (#1205, PR #1353) with upgr…
[Spec 1313][Phase: review] fix: reconcile render gate with #1205 capp…