Skip to content

fix(ai-vault): resume sessions whose worktree was deleted - #24236

Merged
nwparker merged 3 commits into
stablyai:mainfrom
AmoabaKelvin:fix/resume-after-worktree-removed
Oct 5, 2026
Merged

nwparker merged 3 commits into
stablyai:mainfrom
AmoabaKelvin:fix/resume-after-worktree-removed

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​175 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​160
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48

ELI5

You can reopen an old agent chat from Agent Session History. If the folder that chat ran in has since been deleted, Orca should reopen the chat in the workspace you're in now. On a remote (SSH) machine it failed outright instead: Orca tried to step into the deleted folder first, the shell said "no such file or directory", and the agent never started. Codex made it worse by stopping to ask which folder to use, with the deleted one already picked.

Now Orca asks the remote machine whether that folder is still there. Only a clear "it's gone" makes Orca skip it and open the chat in your current workspace instead; if the machine can't be reached, Orca changes nothing, because an unreachable machine is not proof that a folder was deleted. And it tells Codex to stay in the folder Orca opened rather than ask.

What Changed

Where Before After
SSH workspace, any agent Orca typed cd '<deleted folder>' && codex resume … into the new terminal. The shell printed No such file or directory and the agent never started. Orca asks the SSH host whether the folder still exists. When the host says it doesn't, the terminal opens at the workspace root and the agent resumes there.
Codex, local or SSH When the terminal opened anywhere other than the recorded folder, Codex stopped at "Working directory · resume" with the deleted folder pre-selected. Pressing Enter resumed into a folder that no longer exists. Agent Session History resumes pass -c tui.resume_cwd=current, so Codex stays in the folder Orca opened.

How it works:

  • Before a Resume from Agent Session History for a session recorded on an SSH host, Orca runs the existing fs.pathExists check on that host. Only a definite "not found" drops the recorded folder and the command the remote scanner built (the one with the cd). The resume is then rebuilt with no cd and no start folder. If the host can't answer, for example because the connection dropped, nothing changes.
  • buildAgentResumeStartupPlan takes a new opt-in, resumeInLaunchCwd, and only the AI Vault resume builder (buildAiVaultResumeForWorktree) sets it, so it reaches the Resume button, the copied command and the drag-and-drop repin — but never sleep/wake or cold restore. On the copy and drag paths the terminal already opens in the recorded folder, so the setting selects the folder Codex would have picked anyway; it only changes the outcome when Orca deliberately opened somewhere else. The setting goes before resume <id>, so the existing fallback that strips the resume arguments from a command still strips only that part.

Local resumes needed no change to the folder handling. Main already opens at the workspace root when a terminal's start folder is gone (#7847, #13420), which is why local Claude resumes already worked.

Why

  • The existence check runs on the SSH host that owns the folder, and only its "not found" counts. Losing contact is never treated as proof that the folder is gone (docs/reference/ssh-execution-boundary.md).
  • The Codex setting is opt-in instead of on for every Codex resume. Sleep/wake and cold restore reopen at the workspace root even when the session ran in a subfolder. In those cases Codex's prompt, which pre-selects the subfolder, is the right answer. Agent Session History starts the terminal in the session's own folder, so the setting only makes a difference when that folder is gone.
  • Alternatives considered:
    • A "missing folder" fallback in the relay, mirroring local. It would need a new field passed from renderer to main to relay, and it still wouldn't remove the cd built into the scanner's command.
    • Checking the folder when the command is copied. Rejected, because the copied line runs later, in a shell Orca doesn't control.
  • Supersedes fix(ai-vault): repin resumes from deleted worktrees #18085 (+1306/−259), which also reworks the drag-and-drop, copy and remote-runtime paths. This PR stays with the Resume button and Codex's prompt.

Linked Issue

Fixes #17745

Visual Proof

Docker SSH host, hidden Orca window, Resume in New Tab on a Codex session whose folder doesn't exist. A stand-in codex on the host prints the folder it runs in and the arguments it received.

Before:

ssh-before-fix

After:

ssh-after-fix

Testing

  • Ran the flow above against a Docker SSH host (Linux) from macOS, before and after the fix.

  • Checked the Codex prompt against the real Codex 0.157.1: it appears when resuming from another folder and pre-selects the recorded folder even after that folder is deleted. -c tui.resume_cwd=current removes it. Codex 0.40.0 and 0.140.0 accept the setting without error.

  • Unit tests:

    • An SSH session whose folder the host reports gone is rebuilt with no cd, no start folder, and the Codex setting.
    • A host that can't answer leaves the session unchanged.
    • The resume-argument fallback still leaves a valid codex launch when the setting is present.
    • An SSH session whose folder the host confirms still exists keeps its recorded folder and the scanner's command.
    • A local session is never probed.
  • E2E: ORCA_E2E_SSH_DOCKER=1 pnpm exec playwright test tests/e2e/ssh-ai-vault-session-history.spec.ts --config tests/playwright.config.ts --project electron-headless (2 passed, including the new case).

  • Also ran: pnpm tc, oxlint and oxfmt on changed files, pnpm run check:code-quality:changed, and the focused and dependent test files.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Known gaps, left out to keep this PR to one fix:

  • Drag-and-drop resume onto an SSH workspace still runs cd into the deleted folder.
  • "Copy resume command" still copies cd <folder> && ….
  • Sessions on a paired Orca server (runtime: hosts) are not checked.
  • Kimi and Muse sessions only resume in their recorded folder, so over SSH they keep it and still show the cd error once it's gone. Locally, Orca's existing fallback already opens them at the workspace root, where Kimi 1.52 silently starts a new empty session under the same id. That predates this PR.
  • Waking a resumed Codex tab later can show Codex's folder prompt once more, if no message was sent before it slept. The setting isn't saved into the sleeping launch config.
  • tui.resume_cwd has to exist in the installed Codex. Versions that predate it accept -c tui.resume_cwd=current without complaint and ignore it, so they still show the folder prompt. The resume itself still starts in the right folder on those versions, because Orca no longer types the cd.
  • Over SSH the fallback is silent. A local resume whose start folder is gone prints [Orca opened this terminal at the workspace root because its saved start folder no longer exists.] into the pane, because main detects the missing folder itself and reports it back; the renderer-side SSH check has no equivalent channel, so the remote resume just opens at the workspace root. The session row is already badged "Unavailable worktree" before the click.
  • If a shell startup file cds somewhere else, Codex now resumes there without asking. Every agent launch in Orca already relies on the terminal staying in the folder Orca opened it in.

Wire compatibility: nothing new crosses the client–host boundary. The check reuses the existing fs.stat over SSH. Mobile is unaffected.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review September 30, 2026 23:41
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Handles resuming AI sessions when their working directory was deleted.

The PR appears safe to merge; no new actionable issue was found in the changes since the previous review.

Summary

This PR checks whether a recorded SSH working directory still exists before resuming from Agent Session History. When it is gone, Orca drops the scanner’s cd command and launches from the workspace root; Codex resumes use the launch directory without prompting for the deleted folder. The changes since the previous review refine types and add tests for live and local folders.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Resume from session history] --> B[Prepare session]
  B --> C{SSH folder exists?}
  C -->|Yes or unknown| D[Keep recorded folder]
  C -->|No| E[Drop folder and scanner command]
  D --> F[Build resume launch]
  E --> F
  F --> G[Launch agent]
Loading

Reviews (3) · Last reviewed commit: "refactor(ai-vault): type the deleted-cwd..."

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered
📝 Walkthrough

Walkthrough

Codex resume startup commands now specify the launch working directory. Before an SSH session resumes, the flow checks whether its recorded working directory exists on the remote host. If the path is missing, the flow clears the session’s working directory and resume command before building the startup. Unit and end-to-end tests cover missing directories and resume command arguments.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 76b51

Some SSH Codex resumes may still prompt for their recorded folder. This is a bounded issue that can be fixed before merge or accepted for follow-up.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 76b51

The recovery preserves important safeguards: an unreachable host does not trigger directory fallback, and directory-dependent agents are excluded. A remaining ownership gap is that the selected target is validated before the remote check but not checked again before launch. Wrong-host execution has not been established.

Retained concerns

  • Medium · security · inferred: The new SSH path probe occurs after session-to-target host validation. Its continuation launches using the captured worktree ID and current routing without repeating that validation or checking target removal. If ownership changes during the probe, the checked target and launch routing can diverge. The validation placement already existed, but this PR adds a network-dependent interval; actual wrong-host execution remains unverified.
Security review details

Security Blast Radius

  • inferred — The identified conditional exposure is bounded to a user-initiated resume and its selected workspace or execution host. These changes do not establish unauthenticated reachability, new credentials, or fleet-wide authority; successful wrong-host dispatch would additionally require target-routing drift and permissive downstream handling.

Security Findings and Attack Paths

  • inferred — A conditional path exists from target validation, through the new SSH await, to launch using current ownership routing. The inspected orchestration does not revalidate the original host relationship after that await. This is an ownership-enforcement concern, not a verified remote attack or demonstrated terminal execution on another host.

Trust Boundaries and Controls

  • observed — The probe uses the session's SSH identity, not a newly selected host. Filesystem IPC maps ENOENT to false and rethrows other errors; preparation catches those errors and preserves the recorded directory and command. Connection failure therefore does not authorize fallback.

Resilience and Maintainability Implications

  • observed — The continuation retains an explicit target worktree ID, so switching to a different active workspace alone does not replace the selected target. Preparation failures reach an error handler, while runtime launch failures are reported separately. Repeated invocations are independent; no at-most-once contract was established.

Hardening Proposals

  • proposed — Carry the validated target-host identity across preparation and revalidate target existence and compatibility immediately before launch. Abort on ownership drift or target removal rather than relying on the captured worktree ID alone.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue #17745 requires Agent Session History resumes to avoid a deleted recorded directory. This PR handles a confirmed missing SSH directory on the Resume button path for eligible agents. It leaves th… Apply the missing-directory fallback to the remaining supported Agent Session History resume paths, including copied commands and drag-and-drop. When the recorded directory is missing, use the selected target worktree or prompt. Add tests f…
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: resuming sessions when their recorded worktree has been deleted.
Description check ✅ Passed The description is detailed and mostly complete. It explains the user-facing change, implementation, rationale, linked issue, visual proof, testing, known gaps, and checklist. The Review section is bl…
Out of Scope Changes check ✅ Passed The SSH path check, Codex launch setting, and related tests support Issue #17745. The reviewed changes show no unrelated product change.
Full details: Linked Issues check

Explanation

Issue #17745 requires Agent Session History resumes to avoid a deleted recorded directory. This PR handles a confirmed missing SSH directory on the Resume button path for eligible agents. It leaves the copied resume command and SSH drag-and-drop path unchanged, so those paths can still use the deleted directory. The helper also clears cwd rather than selecting or prompting for the target worktree described by the issue.

Resolution

Apply the missing-directory fallback to the remaining supported Agent Session History resume paths, including copied commands and drag-and-drop. When the recorded directory is missing, use the selected target worktree or prompt. Add tests for those paths.

  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — full read of the single commit c044ba8 and its surrounding seams.

  • SSH existence gate for resume — dropDeletedSshResumeCwd (ai-vault-session-resume-preparation.ts) probes the owning SSH host with window.api.fs.pathExists, and only a definite miss drops the session cwd plus the scanner-built resumeCommand. A thrown probe (host lost) leaves the session untouched, matching the live/unverifiable/exited boundary.
  • Rebuild without cd — dropping resumeCommand makes buildAiVaultResumeForWorktree skip its remote early-return and rebuild for the target host, so the terminal opens at the workspace root.
  • Codex -c tui.resume_cwd=current — new opt-in resumeInLaunchCwd on buildAgentResumeStartupPlan, inserted before resume, so the account-unverified fallback in dropAgentResumeArgvFromCommand still strips only the resume argv.
  • Tests — unit coverage for the gone-folder rebuild and the can't-answer no-op, plus a Docker SSH e2e asserting the delivered argv and the real fake-codex pwd.

Verified locally: the four changed unit files (47 tests) and five adjacent resume files (172 tests) all pass. Two mechanical notes, neither actionable:

  • getSshTargetIdForExecutionHost decodes the encoded host id, which matches how providers are registered by raw targetId in ssh-relay-session.ts:1230 — the gate does reach the right provider.
  • resumeInLaunchCwd: true lives in the shared AI Vault builder, so it also reaches the copy-command and drag-and-drop repin paths, not only Agent Session History as the PR body says. This is benign: existing-folder SSH resumes still take the scanner command with no -c, and local resumes already open at the session cwd.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — incremental re-review of 6be104b, the only commit since the prior pullfrog review of c044ba8.

  • Folder-scoped agents keep their recorded cwd — dropDeletedSshResumeCwd now returns the session untouched for kimi and muse through a new RESUMES_ONLY_IN_RECORDED_CWD set, so an SSH resume whose recorded folder is gone keeps the honest cd failure instead of relaunching from the workspace root. This matches the existing scoping contract already documented at src/shared/ai-vault-resume-command.ts:207 (Kimi is work-dir-scoped) and :215 (Muse resume is workspace-scoped), and it resolves the greptile P1 from the prior round.
  • Falsifiable regression test — the new case stubs fs.pathExists to false and asserts the kimi session is returned by object identity; removing the guard makes it fail, so it can actually catch a regression.

Verified locally: the five changed/adjacent unit files pass (50 tests), including the new guard case. No blocking issues.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — incremental re-review of 9ee2b59, the only commit since the prior pullfrog review of 6be104b.

  • Centralized the resume session shape — exported AiVaultResumeCommandSession from ai-vault-resume-command.ts and reused it as the parameter and return type of dropDeletedSshResumeCwd, replacing the bespoke generic constraint. The sole caller and the tests still typecheck; the type-only import introduces no runtime coupling.
  • Aligned the launch-actions type — buildResumeStartup now names the exported type instead of re-deriving it through Parameters<...>, an equivalent and more readable spelling.
  • Added regression tests — a live SSH session is returned by identity with the exact pathExists arguments, and a local session is never probed. Both fail if the short-circuit or the live-folder branch regresses.

Verified locally: the two changed test files pass (23 tests) and pnpm tc:web is clean. Known gaps remain as the author documented; none are introduced here.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

AmoabaKelvin and others added 3 commits October 4, 2026 22:42
SSH resumes typed `cd <deleted folder> &&`, so the agent never started, and
Codex preselected the deleted folder when resumed anywhere else.

Fixes stablyai#17745

Co-authored-by: kaluli123123 <[email protected]>
Kimi resumed from another folder opens a new empty session under the same id.
… shape it feeds

Replaces the generic `T | Omit<T,'resumeCommand'>` return (and the
`Parameters<typeof ...>` leak it forced onto the launch hook) with the
exported session shape every resume builder already takes.

Adds the two uncovered branches: a live SSH folder keeps its scanner
command, and a local session is never probed at all.
@nwparker
nwparker force-pushed the fix/resume-after-worktree-removed branch from 9ee2b59 to 76b51e4 Compare October 5, 2026 05:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Apply the Codex resume setting to saved SSH commands. · ai-vault-resume-command.ts:144-146

src/renderer/src/lib/ai-vault-resume-command.ts:144-146
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Apply the Codex resume setting to saved SSH commands.

With no command override, a remote Codex session with non-null codexHome and a saved resumeCommand returns the stored command before the resume plan adds tui.resume_cwd=current. Codex can still prompt for its recorded folder. When that folder exists, the missing-directory preparation preserves this path. Build this case with the Codex resume plan, or add the setting using the remote host’s command syntax.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9ed14136-4e3a-4f6d-9df8-91d34b21adba
📥 Commits

Reviewing files that changed from the base of the PR and between 9ee2b592a4cbe9b6cd0f4ac5f0316e9d72940358 and 76b51e4.

📒 Files selected for processing (3)
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/renderer/src/lib/ai-vault-resume-command.test.ts
  • src/renderer/src/lib/ai-vault-resume-command.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@nwparker nwparker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Targeted SSH-host stat discards stale cwd only after confirmed absence, retains transport/permission failures and protects folder-scoped agents. 52 tests, web typecheck and quality gate pass. Adds one SSH round trip only on explicit resume.

Required PR Checks verify passed on this exact commit: 76b51e4.

@nwparker

nwparker commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Pre-merge bot audit on 76b51e4: confirmed the outside-diff Codex finding. A saved remote command still bypasses tui.resume_cwd=current when its recorded folder exists; copy and drag retain a deleted cwd. These paths already exist on main and are unchanged here. This PR fixes Resume in New Tab: confirmed SSH absence clears both cwd and the saved command, then rebuilds in the chosen workspace with the Codex setting, including sessions with a non-null Codex home. Unknown host results and Kimi/Muse retain their behavior. The copy/drag paths remain known gaps outside this fix.

All inline threads are resolved. The generic docstring-coverage suggestion is declined under AGENTS.md's concise, non-obvious-comment policy. Focused validation passed 52 tests, and current CI checks passed.

@nwparker
nwparker merged commit 0e43c4f into stablyai:main Oct 5, 2026
42 checks passed
nwparker added a commit that referenced this pull request Oct 26, 2026
…how remote hit previews

Since #27214 every SSH session is retagged runtime:<env>, so the #24236
check that drops a deleted cwd (and its prebuilt `cd`) before resuming
only ever ran for the legacy ssh: spelling. Resume on a paired or
SSH-managed server therefore ran `cd '<deleted folder>' &&` and failed.
The check now covers runtime hosts too, probing the folder with the
existing files.browseServerDir RPC; only a definite "missing" answer
drops the cwd, so an older or unreachable host keeps today's behaviour.

Search-hit cards carry no turns and remote hosts cannot reparse a first
prompt, so a server session found through search showed "No first
prompt" and "No conversation preview". Hits now borrow the preview of
their scanned history row.
nwparker added a commit that referenced this pull request Oct 26, 2026
…how remote hit previews (#33965)

Since #27214 every SSH session is retagged runtime:<env>, so the #24236
check that drops a deleted cwd (and its prebuilt `cd`) before resuming
only ever ran for the legacy ssh: spelling. Resume on a paired or
SSH-managed server therefore ran `cd '<deleted folder>' &&` and failed.
The check now covers runtime hosts too, probing the folder with the
existing files.browseServerDir RPC; only a definite "missing" answer
drops the cwd, so an older or unreachable host keeps today's behaviour.

Search-hit cards carry no turns and remote hosts cannot reparse a first
prompt, so a server session found through search showed "No first
prompt" and "No conversation preview". Hits now borrow the preview of
their scanned history row.
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.

Session History resume pins recorded cwd without existence check — fails after worktree removal

2 participants