Skip to content

Scrollback history lost when pasting large text in terminal #247

@waleedkadous

Description

@waleedkadous

Summary

When pasting a large chunk of text into the dashboard terminal and scrolling up, the beginning of the pasted text is not visible. Scrollable history is being lost.

Current Architecture

Browser (xterm.js) ←→ WebSocket ←→ Tower (node-pty) ←→ tmux session ←→ shell/claude

Current buffer sizes

  • xterm.js scrollback: 10,000 lines (Terminal.tsx:42)
  • tmux history-limit: not set (default: 2,000 lines)
  • Server RingBuffer: 1,000 lines (tower-server.ts:364)

Current tmux config (per session)

  • alternate-screen off — tmux writes to normal buffer so xterm.js native scroll works
  • mouse off — xterm.js handles selection and clipboard
  • status off — dashboard has its own tabs
  • No history-limit set

Root Cause Analysis

The most likely culprit is tmux's default history-limit of 2,000 lines. Even with alternate-screen off, tmux manages its own internal buffer. However, since alternate-screen is off, xterm.js should be receiving all output in its normal buffer (10,000 line scrollback). Possible causes:

  1. tmux history-limit too small (2,000 default) — may affect output flow
  2. RingBuffer too small (1,000 lines) — affects replay on reconnect
  3. xterm.js scrollback may need increase for heavy use
  4. Possible \x1b[3J (clear scrollback) sequences from applications inside tmux

CRITICAL: Read Before Fixing

Read codev/resources/terminal-tmux.md in its entirety before making ANY changes. This area has wasted 10+ hours on previous bugs. Rules:

  1. Never quick-fix Terminal.tsx — understand the full architecture first
  2. Intermittent = external state mutation — grep for all code touching tmux options
  3. tmux -g is GLOBAL — always use -t <session> for per-session settings
  4. Test after changes — build, install, restart Tower, verify in dashboard

Proposed Fix (Conservative)

  1. Set tmux history-limit to 50,000 on session creation (tower-server.ts ~line 572)
  2. Set tmux history-limit to 50,000 on session reconnection (~line 810)
  3. Increase RingBuffer from 1,000 to 10,000 lines (tower-server.ts:364)
  4. Increase xterm.js scrollback from 10,000 to 50,000 (Terminal.tsx:42)

Key Files

File Role
packages/codev/dashboard/src/components/Terminal.tsx xterm.js setup, scrollback config
packages/codev/src/agent-farm/servers/tower-server.ts (~line 572) tmux session creation
packages/codev/src/agent-farm/servers/tower-server.ts (~line 810) tmux session reconnection
packages/codev/src/terminal/pty-session.ts RingBuffer initialization
codev/resources/terminal-tmux.md READ THIS FIRST

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions