Skip to content

fix: pr-bug-scan validated finding from #7310 - #7364

Open
buf0-bot[bot] wants to merge 1 commit into
mainfrom
bot/pr-bug-scan-7310-1783194802
Open

buf0-bot[bot] wants to merge 1 commit into
mainfrom
bot/pr-bug-scan-7310-1783194802

Conversation

@buf0-bot

@buf0-bot buf0-bot Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Automated fix-PR from pr-bug-scan for parent #7310.

Fixer status: FIXED_WITH_CODE_PROOF
Summary: Cold-restore branch now clears screen+scrollback before writing daemon scrollback B, gated on the restored-viewport marker that signals saved buffer A was written — blocking A+B duplication.
Blocked proof link: pty-connection.ts:5274 — writeReplayData(connectResult.coldRestore.scrollback) is now preceded by a marker-gated writeReplayData('\x1b[2J\x1b[3J\x1b[H') at pty-connection.ts:5278-5280, which erases buffer A (written by restoreScrollbackBuffers at use-terminal-pane-lifecycle.ts:1412) before B is written, so the newline-scroll blanking at :5300 no longer preserves both copies.
Typecheck: skipped

Proof (from validator)

  • C1 — proof_type: code_analysis
    • trigger: App restart with the daemon session lost (e.g. full machine reboot): the persisted layout has both buffersByLeafId (saved xterm scrollback) and ptyIdsByLeafId for the same leaf, and the daemon cold-restores a fresh shell for that reattach.
    • observable: The pane's scrollback contains the previous session's content twice (saved xterm buffer A followed by overlapping cold-restore scrollback B); the fresh prompt is clean in the viewport but scrolling up shows duplicated history.
    • path:
      • use-terminal-pane-lifecycle.ts:1409 — restoreScrollbackBuffers(manager, restoredBuffers, restoredPaneByLeafId, replayingPanesRef, restoredViewportBlankingPanesRef) runs during mount whenever buffersByLeafId is present, with no gating on ptyIdsByLeafId
      • layout-serialization.ts:248 — replayIntoTerminal(pane, replayingPanesRef, buf) writes the saved SerializeAddon buffer (content A) into the pane's xterm scrollback for the restored leaf
      • layout-serialization.ts:254 — restoredViewportBlankingPanesRef.current.add(pane.id) marks the same pane
      • pty-connection.ts:5159 — the deferred connect resolves into handleReattachResult for deps.restoredLeafId (== pane.leafId), the same pane restoreScrollbackBuffers wrote to
      • pty-connection.ts:5269 — connectResult.coldRestore branch is taken (daemon lost the session, spawned a fresh shell)
      • pty-connection.ts:5274 — writeReplayData(connectResult.coldRestore.scrollback) appends the daemon's disk-recorded scrollback of the same session (content B) below content A, with no preceding clear

Reproduction

pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts -t "clears restored scrollback before cold-restore"

  • before fix: No clear emitted before cold TUI scrollback; rendered scrollback contains both saved buffer A and cold-restore B (duplicated history).
  • after fix: Clear '\x1b[2J\x1b[3J\x1b[H' precedes cold-restore B; only B survives in scrollback, saved A is erased.

Generated by pr-bug-scan (proof-machine architecture). Human approval required before merge.

ELI5

Automated fix: cold-restoring a terminal could duplicate scrollback (A+B). The screen is cleared before writing daemon scrollback when a restore marker is present.

Cold-restore branch now clears screen+scrollback before writing daemon scrollback B, gated on the restored-viewport marker that signals saved buffer A was written — blocking A+B duplication.
@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 13, 2026 16:47
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:41
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026

This branch has not been deployed

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants