Skip to content

fix(terminal): preserve remote pane output after host restart - #13158

Merged
Jinwoo-H merged 2 commits into
mainfrom
fix/paired-terminal-park-handoff
Aug 8, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
fix/paired-terminal-park-handoff

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix preserved remote terminal panes that stop updating after a paired host runtime restarts while its PTY daemon survives.

The subscriber-driven daemon attach path now forwards the daemon's atomic output sequence to the runtime's existing sequence synchronizer. This keeps snapshot deduplication and subsequent live stream chunks in the same sequence domain.

No reconnect timing, retry policy, subscription lifecycle, renderer recovery, PTY recreation, terminal resize, or wire protocol behavior changes.

Root cause and reproduction

Live instrumentation on the affected pinned milkfish / Setup pane proved:

  1. The surviving Windows daemon's authoritative snapshot sequence was 204.
  2. The relaunched host runtime began its local sequence at 0.
  3. New input advanced the daemon snapshot from 204 to 209 to 214.
  4. The corresponding live chunks reached the multiplex stream and pane callback with runtime sequences 5 and 10.
  5. Renderer reconciliation dropped those chunks as snapshot-covered duplicates because its restored baseline was still 204.
  6. Clearing only that baseline allowed the next live chunk to reach xterm and render immediately.

The existing provider spawn/reattach path already synchronizes this sequence. The subscriber-driven attach path used after a paired viewer reconnects called the same atomic daemon createOrAttach operation but discarded its snapshot sequence.

The E2E regression now creates pane demand before reconnect and avoids terminal.show, which previously exercised the already-correct ordinary reattach path and masked this failure.

Screenshots

No visual change.

Testing

  • pnpm lint — full lint is left to CI; changed-code quality and oxlint pre-commit checks pass
  • pnpm typecheck — pnpm run typecheck:node passes
  • pnpm test — focused suites pass: 619 tests
  • pnpm build — the Electron E2E build and bundled CLI build pass
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Additional validation:

  • Red before the fix: attach-only adoption returned no provider sequence and the subscriber-driven attach made zero synchronization calls.
  • Green after the fix: adapter and IPC sequence-handoff contracts pass.
  • Paired Electron host-restart E2E: 10/10 repeated runs pass, plus one pass after rebasing onto current main.
  • pnpm run check:code-quality:changed passes with zero findings.
  • pnpm exec oxfmt --check passes for all changed files.
  • git diff --check passes.

AI Review Report

The review traced renderer input/output through the paired runtime, multiplex stream, host runtime, daemon adapter, and surviving PTY. It checked the main regression risks: duplicate or missing bytes around the attach boundary, daemon generations, older daemon compatibility, unrelated PTY lifecycle changes, reconnect policy changes, broad fanout, and local/SSH provider behavior.

The implementation uses the daemon's existing atomic snapshot boundary and the runtime's existing synchronization function. It does not introduce polling or timers. The attach result is consumed only by the durable daemon provider; local and SSH providers continue returning no sequence.

Cross-platform compatibility was reviewed for macOS, Linux, and Windows. The change is platform-neutral TypeScript and touches no shortcuts, labels, paths, shell invocation, native module, or Electron platform branch. The reported failure was instrumented on the physical Windows paired host, and the deterministic paired Electron regression runs on the standard test topology.

Security Audit

No new external input, command execution, path handling, authentication, secrets, dependency, or renderer IPC surface is introduced. The returned value is an existing daemon-produced numeric snapshot sequence, validated by the existing synchronizer as finite and non-negative before use. No follow-up security work is needed.

Notes

  • This is an internal provider contract change, not a remote wire-format change.
  • Older daemons that do not publish outputSequence return no sequence and preserve existing behavior.
  • The downside is a small increase in the internal attach contract surface and reliance on the daemon snapshot sequence being authoritative. That sequence is already the authority used by the ordinary reattach path, and the synchronizer rejects invalid values.
  • There are no expected end-user changes beyond preserved remote panes continuing to update after host restart/reconnect.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7fc3e927-1b5c-440b-a542-dd6d6e3fbc27

📥 Commits

Reviewing files that changed from the base of the PR and between 595553e and 8dfcce7.

📒 Files selected for processing (5)
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/main/daemon/degraded-daemon-session-routing.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/daemon/daemon-pty-adapter.test.ts

📝 Walkthrough

Walkthrough

PTY attachment now returns provider sequence data through the provider contract, daemon adapters, routers, and degraded-provider routing. The runtime attach path records the current output sequence and synchronizes it when the provider returns a sequence. Tests cover sequence adoption, legacy attach behavior, runtime synchronization, forwarding through daemon layers, and host-restart reconnection.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes preserving remote pane output after a host restart, which matches the primary change.
Description check ✅ Passed The description covers the summary, visual impact, testing, AI review, security audit, and notes with specific implementation and validation details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jinwoo-H

Jinwoo-H commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up path audit after review:

  • Found one additional sequence-dropping wrapper in DegradedDaemonPtyProvider, used when preserved daemon sessions coexist with an in-process fresh-spawn fallback.
  • Added a red-before contract: the owning legacy daemon returned sequence 204, while the degraded wrapper resolved undefined.
  • Updated only the wrapper return path; fallback refusal, owner routing, attach behavior, and reconnect behavior are unchanged.
  • Added direct contracts for both the normal legacy-daemon router and degraded legacy-daemon router preserving the sequence.
  • Added mixed-version coverage proving a legacy daemon with no output sequence still resolves undefined and preserves existing behavior.

Fresh source audit found only three production PTY provider attach calls:

  1. DaemonPtyRouter now returns its owning adapter result.
  2. DegradedDaemonPtyProvider now returns its owning adapter result.
  3. The IPC subscriber attach captures the result and calls the existing sequence synchronizer.

The daemon adapter is the only producer of attach sequence metadata. Local and SSH provider attach implementations remain void and are excluded from subscriber-driven daemon attach.

Validation after the follow-up:

  • Red-before degraded sequence contract reproduced the omission exactly.
  • 849 cross-provider tests pass across adapter, normal router, degraded router, subscriber-driven attach, local, and SSH suites.
  • Paired Electron host-restart E2E passes after the follow-up.
  • Node typecheck, changed-code quality, formatting, reliability manifest, max-lines ratchet, and git diff --check pass.

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.

1 participant