Skip to content

fix(terminal): restore panel sessions after refresh - #830

Open
dawNotPoi wants to merge 2 commits into
xintaofei:mainfrom
dawNotPoi:fix/terminal-refresh-recovery
Open

dawNotPoi wants to merge 2 commits into
xintaofei:mainfrom
dawNotPoi:fix/terminal-refresh-recovery

Conversation

@dawNotPoi

@dawNotPoi dawNotPoi commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Preserve terminal panel tab IDs and minimal display metadata for the same browser page/window across refresh. Recovery is scoped by the Tauri window label and active remote connection. A page ID in window.name rejects opener-cloned sessionStorage; neither is treated as backend authorization. Initial commands are never stored or replayed.
  • Reattach by subscribing before the snapshot, then deduplicate output with the backend sequence and PTY generation. Refresh, the first Web connection after an offline load, and later Web/remote reconnects can recover a running PTY and its input queue.
  • Retain recent output and exit status for completed PTYs in a bounded backend cache (64 entries, 10 minutes; existing scrollback cap is 128K characters). Explicit tab close still kills/clears the PTY. Reserve IDs during spawn and honor a close that overtakes spawn, so concurrent mounts do not run a command twice. A canvas restart ignores an old completed snapshot during duplicate-spawn retries and reports genuine launch errors.

Verification

  • vitest run --silent: 520 files, 7,756 tests passed.
  • eslint . and tsc --noEmit: passed.
  • next build --webpack: passed. Local Turbopack cannot follow this worktree's symlinked node_modules outside its root; CI uses a normal install.
  • cargo clippy --all-targets --features test-utils -- -D warnings: passed.
  • cargo clippy --no-default-features --bin codeg-server --lib -- -D warnings: passed.
  • cargo test --no-default-features --bin codeg-server --lib: 4,274 passed, 1 ignored.
  • cargo test --features test-utils terminal::manager::tests:: --lib: 13 passed, including real PTY output/exit, EOF ordering, duplicate spawn, and close-before-spawn.
  • Focused frontend tests cover same-page refresh, remote/opener isolation, no command replay, completed output, transient offline recovery and input, reconnect output deduplication, generation filtering, and canvas same-ID races with old completed output, a failed initial snapshot, and launch failures.

Scope

Recovery requires the same backend process; a backend restart cannot restore its lost PTY. A real browser tab close is not a reliable signal to kill a live PTY, so automatic cleanup after permanent browser closure would require a backend lease/grace mechanism. Cached exit status becomes available after reader EOF or a list/count reconciliation; on Windows, delayed ConPTY EOF can temporarily make a snapshot report an exited process as live after refresh. Session storage only discovers opaque IDs under the existing server access model. No physical mobile device or remote host was manually exercised.

Fixes #749

@dawNotPoi
dawNotPoi marked this pull request as ready for review September 24, 2026 10:07
@dawNotPoi

Copy link
Copy Markdown
Contributor Author

@xintaofei 这个 PR 已完成独立 review:刷新后可重新接管同一后端进程中的终端,断线后补取输出,并修复并发启动、显式关闭和画布重启的竞态。最新提交的 7 项 CI 全部通过,现已转为 Ready;具体验证结果和已知边界写在 PR 描述中。请审阅。

@xintaofei

Copy link
Copy Markdown
Owner

感谢PR,最近版本就会处理

@dawNotPoi
dawNotPoi force-pushed the fix/terminal-refresh-recovery branch from 50d0fdc to 49161b6 Compare September 28, 2026 07:04
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.

执行命令后,刷新丢失控制台

2 participants