Skip to content

[#418] Replay terminal scrollback on WebSocket reconnect - #434

Merged
realproject7 merged 1 commit into
mainfrom
task/418-terminal-scrollback-replay
Apr 11, 2026
Merged

[#418] Replay terminal scrollback on WebSocket reconnect#434
realproject7 merged 1 commit into
mainfrom
task/418-terminal-scrollback-replay

Conversation

@realproject7

Copy link
Copy Markdown
Owner

Summary

Fixes #418

Agent terminals went blank after navigating away and back because the WebSocket handler only forwarded live PTY output going forward. Now each session keeps a 64KB ring buffer of recent output, and new WebSocket connections receive the buffer replay before live streaming begins.

Changes

  • server/index.js — added scrollback buffer to session object, term.onData handler captures into ring buffer, WS connection handler replays buffer on connect (+21 lines)
  • No client-side changes — xterm.js processes replayed ANSI data identically to live data

Test plan

  • Navigate to Home, wait 10s, navigate back → all 4 agent terminals show recent output
  • Active agent (mid-task) shows full context on reconnect
  • Idle agents show last prompt/status line, not blank
  • No duplicate output on reconnect (replay once, then live)
  • Long-running sessions stay bounded (64KB ring buffer, no memory growth)

🤖 Generated with Claude Code

Agent terminals went blank after navigating away and back because
the WS handler only forwarded live PTY output. Now each session
keeps a 64KB ring buffer of recent output, and new WS connections
receive the buffer before live streaming begins. xterm.js processes
the replayed ANSI data identically to live data.

No client-side changes needed — the terminal component already
handles the data stream correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@realproject7

Copy link
Copy Markdown
Owner Author

RE2 Review — APPROVE

Clean implementation, matches the issue spec exactly:

  1. Ring buffer — 64KB Buffer, appended on every term.onData, sliced when exceeding limit. Runs independently of WS connections so it accumulates even when no client is connected.

  2. Replay on connectws.send(session.scrollback) fires after WS attachment but before the live onData handler is registered. Correct ordering — no gap, no duplicate output.

  3. No client changes — xterm.js handles replayed ANSI data identically to live data. Right call.

  4. Memory bounded — 64KB per session, sliced with Buffer.slice(-SCROLLBACK_SIZE). No growth risk for long-running sessions.

  5. +21 lines, 0 deletions — additive only, no risk to existing behavior.

No issues found.

@project7-interns project7-interns left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

Summary

The PR is tightly scoped to #418 and fixes the blank-terminal reconnect problem by replaying bounded PTY scrollback before resuming live streaming. The replay path fits the existing session model cleanly and keeps memory bounded with the 64KB ring buffer.

Findings

  • None.

Decision

Approving because the implementation matches the issue acceptance criteria without introducing client-side churn or obvious PTY/WS lifecycle regressions.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Agent terminals go blank after navigating away and back — scrollback not replayed on reconnect

2 participants