Fix/panel scrollback leak 457 - #471
Open
ilijachrchev wants to merge 8 commits into
Open
Conversation
…ngled repaint dumps
… stop mangled context dumps
…ToolPanelState changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #457 — new Claude Code tab receives another panel's mangled screen buffer as its first prompt.
Panel-scrollback readers sourced text from the raw PTY append log (
terminal.scrollbackBuffer) and merely ANSI-stripped it. The append log accumulates every repaint frame — agents and tools update in place via cursor-motion escapes (\x1b[nD,\x1b[K, column addressing), not carriage returns.sanitizeTerminalOutputonly collapses\r-based overwrites, so cursor-motion fragments concatenate into the reported garbage ("Workingorking•rking•king•ingngg"). The default 500-line copy preset ≈ the reported 9–12 KB.The codebase already knew the raw log is unreliable —
getTerminalStateand agent-status detection both use the screen emulator instead. Three consumers shared the defective raw-log path:runpane panels output→getPanelScrollback(main/src/ipc/runpane.ts) — the context-capture path; its output flows into--initial-input-file, prepended to the typed "continue"terminal:getScrollbackClean(main/src/ipc/panels.ts) — the UI @-terminal raw-copy featureterminal:save-scrollback(main/src/ipc/panels.ts) — the @-terminal embed-copy featureThe fix routes all three through a new
getScrollbackText()method on the screen emulator, which renders clean plain text from the already-correct rendered buffer.Changes:
TerminalStateEmulator.getScrollbackText(maxLines?): clean plain text from the rendered buffer (scrollback history + viewport), trimming trailing blanks before applying the line limitTerminalPanelManager.getCleanTerminalScrollback(panelId, maxLines): awaits emulator idle, returns clean text or null (no live emulator → caller falls back to persisted state)panels.tsIPC handlers through the emulator, keeping the sanitized persisted-state fallback for lazy/inactive terminalsrunpane panels outputthrough the emulator (madepanelScrollbackOutputasync)Type of Change
Checklist
pnpm typecheckandpnpm lintlocallypnpm electron-devCritical Areas Modified
Screenshots (if applicable)
N/A — the bug produces no visible UI change; the symptom is in the agent's session JSONL (first
usermessage contains another panel's screen dump). The fix changes what text the scrollback readers return internally.Additional Notes
pnpm run typecheckpasses. OxLint exit 0, ESLint 0 errors in touched files.terminalStateEmulator.test.ts(9),runpane.test.ts(60),terminalPanelManager.test.ts— all pass.runpane.ts:475 PaneCommandValue) was fixed as part of the rebase cleanup (castrequest as PaneCommandValue).