Skip to content

feat: persist terminal sessions on window reload#229

Merged
j4rviscmd merged 1 commit into
mainfrom
feat/terminal-reload-restore
Jul 5, 2026
Merged

feat: persist terminal sessions on window reload#229
j4rviscmd merged 1 commit into
mainfrom
feat/terminal-reload-restore

Conversation

@j4rviscmd

Copy link
Copy Markdown
Owner

Summary

Add coderm.terminal.persistSessionOnReload (default: true) to fully restore terminal sessions on window reload even when terminal.integrated.enablePersistentSessions is disabled. close/quit still discards sessions per the upstream setting.

Problem

When terminal.integrated.enablePersistentSessions: false, reload window discards all terminal state but leaves an empty pane — the terminal UI frame remains with a fresh shell inside, losing cwd, child processes, scrollback, and the pane split layout.

Solution

Wrap TerminalConfigurationService via DI override (CodermTerminalConfigurationService) to force config.enablePersistentSessions to true in reload-relevant contexts, reusing the existing VSCode persistence paths (pty host detach/reattach, layout info, editor serializer).

Behavior matrix (when the coderm setting is enabled AND the user setting is false):

  • Normal operation / reload startup: force true so processes are created with shouldPersist=true (reload detach requires this at process-creation time) and reconnection is enabled
  • Reload shutdown (reason === RELOAD): force true so processes detach and survive
  • Non-reload shutdown (CLOSE/QUIT/LOAD): pass through false so processes are disposed and buffer revival is skipped, matching the user's enablePersistentSessions: false intent

Race-free guarantee: this service IS ITerminalConfigurationService, so DI instantiates it before any consumer (e.g. TerminalService). The onBeforeShutdown listener here registers before consumers', and Emitter.fire() dispatches synchronously, so _shutdownReason is set before any consumer reads config during shutdown.

DI override: coderm.contribution.ts is imported AFTER terminal.contribution.ts in workbench.common.main.ts, and ServiceCollection.set() is last-wins, so the coderm registerSingleton replaces the upstream descriptor.

Changes

  • New src/vs/workbench/contrib/coderm/browser/terminalPersistSessionOnReload.ts: setting registration + CodermTerminalConfigurationService wrapper + registerSingleton (last-wins DI override)
  • src/vs/workbench/contrib/coderm/browser/coderm.contribution.ts: side-effect import
  • src/vs/workbench/contrib/terminal/browser/terminalEditorInput.ts: alignment fix — read enablePersistentSessions via ITerminalConfigurationService.config (was the only outlier using IConfigurationService.getValue directly, which bypassed the wrapper)
  • README.md / README.ja.md: add the setting to the Coderm settings table

Why DI override (not editing each guard site)

enablePersistentSessions is read at 8+ sites (terminalService.ts, terminalProcessManager.ts, ...). Wrapping the single config getter localizes the Coderm diff to one file and minimizes upstream-merge conflicts — consistent with the project's "localize the diff" fork policy.

Verification

Tested locally with terminal.integrated.enablePersistentSessions: false:

  • Multiple terminals (panel split panes + editor), each with cwd changes and scrollback → reload window → all fully restored (process, cwd, scrollback, pane layout)
  • Close/quit → terminals discarded (reload-only persistence confirmed)
  • coderm.terminal.persistSessionOnReload: false → restores upstream behavior

🤖 Generated with Claude Code

Add coderm.terminal.persistSessionOnReload (default: true) to fully restore terminal sessions (process, cwd, scrollback, pane layout) on reload even when terminal.integrated.enablePersistentSessions is disabled. Wraps TerminalConfigurationService via DI override (CodermTerminalConfigurationService) to force enablePersistentSessions true in reload-relevant contexts, reusing the existing pty host detach/reattach and layout info paths; close/quit still discards per the upstream setting. Also aligns terminalEditorInput.ts to read config via ITerminalConfigurationService (was the only outlier using IConfigurationService.getValue directly).

Co-Authored-By: Claude <noreply@anthropic.com>
@j4rviscmd j4rviscmd added enhancement New feature or request terminal labels Jul 5, 2026
@j4rviscmd j4rviscmd merged commit 2649872 into main Jul 5, 2026
3 checks passed
@j4rviscmd j4rviscmd deleted the feat/terminal-reload-restore branch July 5, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request terminal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant