Repository navigation
Checkpoint terminal scrollback so a crash no longer loses it #14852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cb26ff7
Checkpoint terminal scrollback so a crash no longer loses it
teamleaderleo 3651270
Bound checkpoint capture cost and keep restored scrollback across cra…
teamleaderleo 63c50f5
Discard checkpoint exports on quit and seed only after a crash
teamleaderleo 04d3538
Fix overlapping access in the scrollback checkpoint merge
teamleaderleo 2922051
Merge main (6431ac28335) into feat/crash-safe-scrollback-autosave
teamleaderleo 425d2c5
Discard checkpoints after a clean exit so a later crash cannot restor…
teamleaderleo 18723c9
Merge remote-tracking branch 'mf/main' into feat/crash-safe-scrollbac…
teamleaderleo 997cb90
Inject one scrollback checkpoint activity owner and delete removals b…
teamleaderleo 6be7f71
Merge main into crash-safe scrollback autosave
teamleaderleo 43c4095
Test scrollback checkpoint output interleaving
teamleaderleo 4fc69a9
Make scrollback checkpoints generation-safe
teamleaderleo 42a3d32
Preserve scrollback for idle agent sessions
teamleaderleo b52e97b
Match checkpoint agent liveness policy
teamleaderleo 3520795
Merge main (57fd5ac4df76) into feat/crash-safe-scrollback-autosave
teamleaderleo 80bf39e
Merge main (34caf6723814) into feat/crash-safe-scrollback-autosave
teamleaderleo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import AppKit | ||
| import CmuxTerminal | ||
| import CmuxWorkspaces | ||
| import Foundation | ||
|
|
||
| extension AppDelegate { | ||
| /// Live terminals a scrollback checkpoint may capture: the same panels the | ||
| /// session snapshot walks (registered windows, their docks, and windowless | ||
| /// routes that still fit the persisted window budget). | ||
| func sessionScrollbackCheckpointCandidates() -> [SessionScrollbackCheckpointCoordinator.Candidate] { | ||
| var candidates: [SessionScrollbackCheckpointCoordinator.Candidate] = [] | ||
| var seen = Set<UUID>() | ||
| let restorePolicy = Workspace.makeSessionRestorePolicyService() | ||
|
|
||
| func append( | ||
| panelId: UUID, | ||
| terminal: TerminalPanel, | ||
| shellActivityState: PanelShellActivityState? | ||
| ) { | ||
| guard seen.insert(panelId).inserted else { return } | ||
| // Mirrors the snapshot gates: a running command or a hibernated | ||
| // agent does not persist scrollback (see `sessionPanelSnapshot`). | ||
| // `snapshotNeedsConfirmClose` is the lock-free variant (#6381). | ||
| let closeConfirmationRequired = Workspace.resolveCloseConfirmation( | ||
| shellActivityState: shellActivityState, | ||
| fallbackNeedsConfirmClose: terminal.surface.snapshotNeedsConfirmClose() | ||
| ) | ||
| let isEligible = restorePolicy | ||
| .shouldPersistSessionScrollback(closeConfirmationRequired: closeConfirmationRequired) | ||
| && terminal.agentHibernationState == nil | ||
| candidates.append(SessionScrollbackCheckpointCoordinator.Candidate( | ||
| panelId: panelId, | ||
| surfaceId: terminal.surface.id, | ||
| isEligible: isEligible, | ||
| capture: { [weak terminal] in | ||
| guard let terminal else { return nil } | ||
| // Same capture the quit path uses for each terminal. | ||
| return TerminalController.shared.readTerminalTextForSnapshot( | ||
| terminalPanel: terminal, | ||
| includeScrollback: true, | ||
| lineLimit: SessionPersistencePolicy.maxScrollbackLinesPerTerminal | ||
| ) | ||
| } | ||
| )) | ||
| } | ||
| func appendTerminals(from dock: DockSplitStore) { | ||
| for (panelId, panel) in dock.panels { | ||
| guard let terminal = panel as? TerminalPanel else { continue } | ||
| append(panelId: panelId, terminal: terminal, shellActivityState: terminal.shellActivity.state) | ||
| } | ||
| } | ||
| func appendTerminals(from manager: TabManager) { | ||
| for workspace in manager.tabs { | ||
| let shellActivityStates = workspace.panelShellActivityStates | ||
| for (panelId, panel) in workspace.panels { | ||
| guard let terminal = panel as? TerminalPanel else { continue } | ||
| append(panelId: panelId, terminal: terminal, shellActivityState: shellActivityStates[panelId]) | ||
| } | ||
| if let dock = workspace._dockSplit { | ||
| appendTerminals(from: dock) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for context in mainWindowContexts.values { | ||
| appendTerminals(from: context.tabManager) | ||
| if let dock = context.existingWindowDock() { | ||
| appendTerminals(from: dock) | ||
| } | ||
| } | ||
| for route in mainWindowLifecycleCoordinator.eligibleOrphanedRoutesForPersistence() { | ||
| guard let manager = route.tabManager else { continue } | ||
| appendTerminals(from: manager) | ||
| if case .live(let dock)? = route.windowDock { | ||
| appendTerminals(from: dock) | ||
| } | ||
| } | ||
| return candidates | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.