feat: persist terminal sessions on window reload#229
Merged
Conversation
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>
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.
Summary
Add
coderm.terminal.persistSessionOnReload(default:true) to fully restore terminal sessions on window reload even whenterminal.integrated.enablePersistentSessionsis 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
TerminalConfigurationServicevia DI override (CodermTerminalConfigurationService) to forceconfig.enablePersistentSessionstotruein 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):trueso processes are created withshouldPersist=true(reload detach requires this at process-creation time) and reconnection is enabledreason === RELOAD): forcetrueso processes detach and surviveCLOSE/QUIT/LOAD): pass throughfalseso processes are disposed and buffer revival is skipped, matching the user'senablePersistentSessions: falseintentRace-free guarantee: this service IS
ITerminalConfigurationService, so DI instantiates it before any consumer (e.g.TerminalService). TheonBeforeShutdownlistener here registers before consumers', andEmitter.fire()dispatches synchronously, so_shutdownReasonis set before any consumer readsconfigduring shutdown.DI override:
coderm.contribution.tsis imported AFTERterminal.contribution.tsinworkbench.common.main.ts, andServiceCollection.set()is last-wins, so the codermregisterSingletonreplaces the upstream descriptor.Changes
src/vs/workbench/contrib/coderm/browser/terminalPersistSessionOnReload.ts: setting registration +CodermTerminalConfigurationServicewrapper +registerSingleton(last-wins DI override)src/vs/workbench/contrib/coderm/browser/coderm.contribution.ts: side-effect importsrc/vs/workbench/contrib/terminal/browser/terminalEditorInput.ts: alignment fix — readenablePersistentSessionsviaITerminalConfigurationService.config(was the only outlier usingIConfigurationService.getValuedirectly, which bypassed the wrapper)README.md/README.ja.md: add the setting to the Coderm settings tableWhy DI override (not editing each guard site)
enablePersistentSessionsis read at 8+ sites (terminalService.ts,terminalProcessManager.ts, ...). Wrapping the singleconfiggetter 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:coderm.terminal.persistSessionOnReload: false→ restores upstream behavior🤖 Generated with Claude Code