Repository navigation
feat: support multi-tab OSC 7577 terminal program resume - #5065
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved resume-reporting defects can prevent updates, erase records during shutdown, or restore the wrong workspace, while nonportable test fixtures fail blocking Windows CI.
6 open issues
Resolve working-directory symlinks before reporting cwd · New Use portable paths in successful-report fixtures · New Use portable absolute paths in report validation tests · New Allow inherited directory flags in resume command validation · New Preserve resume record when shutdown cancels the store read · New Avoid reloading full conversation in the synchronous TUI callback · New
What changed in this PR
Adds terminal-driven resume for supported standalone interactive sessions using authenticated OSC 7577 reports, building on existing session persistence.
Changes:
- Reports the active persisted session and validates its working directory and saved safety policy on resume.
- Isolates resume tokens from child processes and connects reporting and clearing to TUI lifecycle events.
- Adds protocol and lifecycle tests, plus documentation of supported runs, trust requirements, and limitations.
| File | Description |
|---|---|
pkg/tui/tui.go |
Connects resume callbacks to TUI updates and intentional exits. |
pkg/tui/tabs.go |
Gives explicit sessions precedence over saved tabs. |
pkg/tui/program_resume.go |
Coordinates active-session reporting and clearing. |
pkg/tui/program_resume_test.go |
Tests lifecycle callbacks and explicit-session behavior. |
pkg/programresume/report.go |
Encodes and authenticates OSC 7577 reports. |
pkg/programresume/report_test.go |
Tests protocol encoding and input validation. |
docs/features/sessions/index.md |
Documents resume support, trust, and limitations. |
cmd/root/run.go |
Integrates reporting and existing-session resume checks. |
cmd/root/root.go |
Removes the token from the environment and skips self-update. |
cmd/root/program_resume.go |
Selects supported runs and validates reportable sessions. |
cmd/root/program_resume_test.go |
Tests persistence checks, token isolation, and supported flags. |
Review effort: Balanced
|
👋 This PR has merge conflicts with the base branch. Please rebase or merge the latest base branch and resolve them. I've added |
8a8393c to
a6c42c4
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Resume can load a different agent configuration than the validated file and bypass required sandboxing, allowing tools to execute directly on the host.
7 open issues
Bypass aliases when resolving a validated resume path · New Reject sandbox-required agents before resuming · New Reject alias and built-in names for resumed local agents · New Move persistence and terminal I/O off the UI mutex · New Clear inherited reporter state on exit or invalidation · New Restore the recall coordinator for resumed runtimes · New Replay pending attention after a failed tab switch · New
6 resolved since last review
Use portable absolute paths in report validation tests Use portable paths in successful-report fixtures Resolve working-directory symlinks before reporting cwd Avoid reloading full conversation in the synchronous TUI callback Preserve resume record when shutdown cancels the store read Allow inherited directory flags in resume command validation
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Confirmed quit can hang before the shutdown timeout is armed, while throttled resume snapshots can go unreported and provider validation can wrongly reject runs using a saved config directory.
3 open issues
7 resolved since last review
Reject sandbox-required agents before resuming Bypass aliases when resolving a validated resume path Replay pending attention after a failed tab switch Restore the recall coordinator for resumed runtimes Clear inherited reporter state on exit or invalidation Move persistence and terminal I/O off the UI mutex Reject alias and built-in names for resumed local agents
Review effort: Balanced
aheritier
left a comment
There was a problem hiding this comment.
Review from reading the diff and surrounding code (nothing was run). Two issues worth fixing before merge, three minor ones.
Also: the PR description still says the terminal restores "the active session, not the tab layout", while the code and docs now restore all tabs.
There was a problem hiding this comment.
🟡 Changes recommended
Startup self-update loses captured resume tokens during re-exec, while age-based pruning can delete live instance files, both breaking terminal-resume support.
3 open issues
2 resolved since last review
Review effort: Balanced
99408b8 to
4cad44c
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved bugs can deny files explicitly re-included by .agentsignore, leave resume disabled, stop instance refreshes, and prevent saved-state deletion during forced shutdown.
4 open issues
3 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
NFSv4 ACL inspection errors can bypass the security check, and the first tab can remain uninitialized, leaving its saved conversation and sidebar state unloaded.
2 open issues
2 resolved since last review
Review effort: Balanced
f93b031 to
3bbf1d1
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved resume flaws can accept changed workspace symlink targets, silently lose global permissions and hooks when the saved config directory is unavailable, and leave intentionally exited instances restorable without a valid OSC token.
3 open issues
2 resolved since last review
Review effort: Balanced
…nce store Implement authenticated OSC 7577 report/clear encoding (`Report`, `Clear`, `ValidToken`) and private per-process instance storage under `<data-dir>/resume-instances/<id>.json`. Instance storage walks every path component via open directory descriptors, verifies ownership, modes, symlinks (allowing only root-owned `/private/*` system links on macOS), and ACLs (macOS extended ACLs via cgo and Linux POSIX/NFSv4 ACLs + local filesystem checks), confines file operations to a verified `os.Root`, fails closed on Windows and non-cgo macOS, and supports pruning abandoned files older than 30 days. Signed-off-by: Arnaud Héritier <arnaud.heritier@docker.com>
…env handoff Add the runtime plumbing needed for safe, low-overhead terminal resume: - `session.ResumeMetadataStore` to query only session identity, working directory, safety policy, and permissions without decoding conversation history. - `config.LoadHookDropInsStrict` to fail closed on unreadable or invalid `hooks.d` drop-ins instead of skipping them silently. - `selfupdate.Updater.ReExecEnv` so startup can strip `OSC7577_TOKEN` from `os.Environ()` immediately while handing a valid standalone token across a verified self-update `re-exec` without exposing it to child processes. Signed-off-by: Arnaud Héritier <arnaud.heritier@docker.com>
3bbf1d1 to
49fd6e7
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The permissions dialog can claim files are blocked while runtime access remains allowed, and starring a fresh session can leave it unavailable for terminal restoration.
2 open issues
3 resolved since last review
Review effort: Balanced
…me hooks Add TUI options and lifecycle wiring for per-process terminal resume: - `WithProgramResume` to emit filtered UI tab snapshots on relevant state changes, re-report on `tea.ResumeMsg`, and clear only on intentional exit (`/exit` on the last tab or confirmed quit) while preserving state on shutdown. - `WithInstanceTabs` to restore a resumed instance's ordered tabs and active tab without reading or mutating shared `restore_tabs` (`tuistate.db`) state. - `WithExplicitSession` to give explicit `--session` precedence over `restore_tabs` without overwriting saved tab layouts, and clear failed pending restores cleanly (replaying parked attention dialogs on rollback). Signed-off-by: Arnaud Héritier <arnaud.heritier@docker.com>
…/permissions Stop merging lossy permissions.FromAgentsIgnore deny patterns into live Team.SetPermissions, which previously blocked gitignore negation rules such as "*.key" followed by "!public.key". Instead, preserve the raw patterns captured on fsx.AgentsIgnoreMatcher when the filesystem toolset is constructed and expose them through LocalRuntime.PermissionsInfo() as advisory deny rules for /permissions, keeping the displayed rules aligned with the runtime's enforced snapshot even if .agentsignore changes on disk later. Signed-off-by: Arnaud Héritier <arnaud.heritier@docker.com>
49fd6e7 to
5745071
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Resume rejects a missing saved config directory even though a normal run can advertise an instance without creating it, leaving that instance unable to resume despite unchanged settings.
1 open issue
2 resolved since last review
Review effort: Balanced
Wire per-process OSC 7577 reporting and `docker-agent run --resume-instance <id>` restoration into the standalone CLI: - Strip `OSC7577_TOKEN` at startup before child processes or self-update run, passing valid standalone tokens only via verified `selfupdate` re-exec and skipping self-update on `--resume-instance`. - Report eligible standalone interactive TUI runs on a background worker off the UI loop with 1s trailing throttle coalescing, 12h periodic mtime refresh, and bounded shutdown/clear deletion safe against wedged terminals or forced exit. - Preflight and restore all persisted tabs in their validated working directories using the instance's saved config directory, strict hook checks, alias-free local agent loading, `runtime.sandbox` rejection, and `.agentsignore` fail-closed policy before starting any runtime. Signed-off-by: Arnaud Héritier <arnaud.heritier@docker.com>
Document explicit `--session` precedence over `restore_tabs` and the OSC 7577 terminal program resume behavior, Rex trust rules, supported runs, security preflight checks, lifecycle, and platform boundaries. Signed-off-by: Arnaud Héritier <arnaud.heritier@docker.com>
5745071 to
5182152
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Security-sensitive ACL checks and authenticated terminal restoration require human validation on supported Linux and cgo macOS builds with a real OSC 7577 terminal, as live Rex restart/resume remains unverified.
No open issues 🎉
1 resolved since last review
Review effort: Balanced


Summary
Add per-process, instance-based terminal program resume via OSC 7577 (
docker-agent run --resume-instance <id>) so compatible terminals (such as Rex) can restore an interactive standalonedocker-agentTUI process with its ordered persisted session tabs and active tab after a terminal restart.Closes #5062
Reference Resources
Reviewers can use these references to evaluate protocol compliance, threat model, and terminal integration:
Support terminal program resume with OSC 7577)OSC 7577)docs/features/sessions/index.mdDesign & Architecture
Protocol & Verified Private Instance Storage (
pkg/programresume)\x1b]7577;...mac=<sha256>\x1b\\) with strict token, path, control-character, and 2048-byte validation.OSC7577_TOKEN, credentials, or conversation messages) in versioned files under<data-dir>/resume-instances/<id>.json./private/*links on macOS), and ACLs (macOS extended ACLs via cgo; Linuxsystem.posix_acl_access/system.nfs4_acl+ local filesystem magic checks), confines file operations to a verifiedos.Root, fails closed on Windows and non-cgo macOS, and prunes abandoned files older than 30 days.Startup Isolation & Background Lifecycle Reporting (
cmd/root/root.go,cmd/root/program_resume.go,pkg/selfupdate,pkg/session)OSC7577_TOKENfromos.Environ()immediately at startup before any child process or updater runs; passes a valid standalone token exclusively across a verifiedselfupdatere-execand skips self-update on--resume-instance.session.ResumeMetadataStore), disk writes, and OSC stdout writes off the Bubble Tea UI loop with 1s trailing throttle coalescing, 12h periodic mtime refresh, and bounded cleanup safe against wedged terminals or forced TUI shutdown./exiton the last tab or confirmed quit); preserves both on shutdown/hangup and re-reports after resume.Fail-Closed Preflight & Isolated Multi-Tab Restore (
cmd/root/resume_instance.go,cmd/root/instance_preflight.go,cmd/root/resume_hooks.go,pkg/config/hooks_dropin.go,pkg/tui)runtime.sandbox: false, saved config directory, strictsettings.hooks+hooks.ddrop-ins,.agentsignoreabsence/inspectability, and every tab's session ID, working directory, symlink target, safety policy, and permissions fingerprint before starting any runtime.tui.WithInstanceTabs) without reading or mutating sharedrestore_tabs(tuistate.db), and keeps explicit--sessionruns from overwriting savedrestore_tabslayouts..agentsignoredeny rules advisory inLocalRuntime.PermissionsInfo()(reading from the active filesystem toolset's capturedAgentsIgnoreMatchersnapshot) rather than merging them into liveTeam.SetPermissions, preserving.agentsignorenegation rules (*.key+!public.key) at runtime and keeping/permissionsdisplay in sync with startup enforcement.Commit Breakdown
feat(programresume): add OSC 7577 protocol and verified private instance storefeat(resume): add metadata reader, strict hook drop-ins, and re-exec env handofffeat(tui): support isolated instance tab restoration and program resume hooksfix(permissions): keep derived .agentsignore deny rules advisory for /permissionsfeat(cli): wire OSC 7577 reporting and --resume-instance restorationdocs(sessions): document OSC 7577 terminal program resumeHow to Evaluate & Verify
go test -race -shuffle=on ./pkg/programresume/... ./pkg/session/... ./pkg/config/... ./pkg/selfupdate/... ./pkg/app/... ./pkg/tui/... ./cmd/root/...linux/amd64), Windows (windows/amd64), and non-cgo macOS (CGO_ENABLED=0 darwin/arm64)go run ./lint .andgolangci-lintacross macOS, Linux, and Windows targetsdocker-agentbinary andrun --resume-instance.docker-agent run ./agent.yaml, create/persist messages across one or more tabs, and restart the terminal (or sendSIGHUP/SIGTERM) — verify the process resumes with its persisted tabs and active tab intact./exit(last tab) or confirmedCtrl+C, and restart the terminal — verify the instance is cleared and does not auto-resume.