GeezerVison is showing github.com — chat: per-session message history is never trimmed — every message re-joins the full history into the 5-line viewport, so a long-lived session grows unbounded and rendering is quadratic · Issue #3268 · developing-today/code
chat: per-session message history is never trimmed — every message re-joins the full history into the 5-line viewport, so a long-lived session grows unbounded and rendering is quadratic #3268DescriptionProblem
In pkgs/chat (main.go, main 4b0f9ceb), every client's model keeps its entire chat history forever and rebuilds the whole viewport content on every message:
case chatMsg:
m.messages = append(m.messages, m.senderStyle.Render(msg.id)+": "+msg.text)
m.viewport.SetContent(strings.Join(m.messages, "\n"))
m.viewport.GotoBottom()
(main.go:177-180; the field is declared at :113 and initialised at :144.)
Those are the only three references to messages in the file: nothing ever caps, trims, or windows the slice. The viewport is 5 lines tall (viewport.New(30, 5), :141-143), so nearly everything retained is invisible — yet a long-lived session's model grows without bound, and each new message costs a strings.Join over the full history: total rendering work is quadratic in the number of messages the session has seen, and the joined string is re-allocated whole every time.
This is the per-session sibling of #3201 (the server-side progs registry in the same file, which is never pruned either): #3201 covers the server retaining dead programs; this issue covers a single live session's own history and render cost, which grows even while the session is healthy and connected.
Evidence (verified this run)
- Code:
grep -n messages pkgs/chat/main.go returns exactly three sites — field :113, init :144, append+Join :178-179. No cap, trim, or ring buffer anywhere in the package (the package is the single main.go, 197 lines).
- Laptop probe (
~/git/fleet/probe-2026-10-31-laneB-chathistory/, plain Go replicating the append + full strings.Join performed per chatMsg; pkgs/chat/main.go sha256 70e8215c5d13db1fb… identical on the sandbox clone at 4b0f9ceb and the laptop clone ~/git/code):
n= 1000 total append+Join time=8ms retained messages=1000
n= 5000 total append+Join time=135ms retained messages=5000
n=10000 total append+Join time=480ms retained messages=10000
n=20000 total append+Join time=1.898s retained messages=20000
Doubling the history roughly quadruples the total work — the per-message Join dominates, exactly as the code shape predicts.
Dedup: open + closed search for chat message history / viewport returns only #3201 (server progs registry: fan-out to dead programs + data race). No existing issue covers the per-model messages slice.
Why it matters
The chat server is a long-running SSH service: a busy room or a client left connected for days steadily eats more memory per session and gets visibly laggier with every message, because each keystroke-era message re-renders history the 5-line viewport will never show. It degrades exactly in the long-lived-session case the service exists for, and there is no operator-visible bound to tune.
Acceptance criteria
- A session's retained history is bounded by a named cap (sized relative to what the viewport can show / scroll back, and documented in the code), or the viewport content is built incrementally without re-joining the full history per message.
- After the cap is reached, older messages are dropped from the model (the visible behaviour — latest messages shown,
GotoBottom — is unchanged).
- Per-message render work no longer grows with total history length once the cap is reached.
- A test or benchmark pins the behaviour: feeding more messages than the cap leaves the retained count at the cap and the newest message visible.
Activitydezren39 commented on Nov 1, 2026 🤖 Agent note · filed
- Agent: new-issue-creator-code-b
- Session / ID: new-issue-creator-code-b cron run 2026-10-31 19:20 CDT
- Found via: filed this run — read
pkgs/chat/main.go on main 4b0f9ce while sweeping packages Lane B had not covered this cycle; grep shows messages has exactly three references (field :113, init :144, append+Join :178-179) and no cap anywhere, then measured the cost with a laptop Go probe.
- Task: Filed this issue: a chat session's model retains every message forever and re-joins the full history into its 5-line viewport per message — unbounded per-session growth, quadratic total render work. Laptop probe (~/git/fleet/probe-2026-10-31-laneB-chathistory/, main.go sha256 70e8215c5d13db1fb… matched on both clones): append+Join totals 8ms @1k, 480ms @10k, 1.898s @20k messages.
- Expectation: effort s; done when retained history is bounded by a named cap (or rendering is incremental), visible behaviour is unchanged, and a test/benchmark pins the cap — see the issue's acceptance criteria.
- Links: server-side sibling chat: session program registry never pruned — unbounded growth, per-message fan-out to dead programs, and a data race on the shared slice #3201
dezren39 commented on Nov 1, 2026 dezren39 commented on Nov 8, 2026 🤖 Agent note · handed off
dezren39 commented on Nov 8, 2026 🤖 Agent note · handed off
developing-today commented on Nov 8, 2026 dezren39 commented on Nov 9, 2026 🤖 Agent note · done (already done)
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|