Skip to content

test(accounts): cover the workspace-folder fallback for account-restart resume cwd - #34203

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-account-restart-launch-cwd
Oct 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-account-restart-launch-cwd

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17
Prod 0 0 0 0

ELI5

#34202 fixed a typecheck break in the account-switch restart code, but added no test for the behavior that line guards. This adds that test. It's test-only.

What Changed

When an account switch restarts a Claude pane whose tab recorded no start folder, the restart falls back to the workspace folder. It then compares that folder with the folder the session ran in, so a session started in a subfolder resumes with cd '<subfolder>' && claude --resume …. Two PRs merging together (#33629 and #33659) broke that fallback, and #34202 restored it. Nothing tested it.

  • New case in agent-account-restart-startup.test.ts: the tab has no start folder, the workspace is /repo, and the Claude session ran in /repo/pkg, so the command must start with cd '/repo/pkg'.
  • The Claude block's beforeEach now also resets tabsByWorktree and worktreesByRepo, so the store state these tests set up doesn't carry into the next case.

Why

A regression test, so the next refactor of this function can't drop the fallback silently. No production code changes.

Linked Issue

N/A (follow-up to #34202; this PR was #34203's original fix, now reduced to its test).

Visual Proof

N/A: test-only.

Testing

  • All 17 tests in the file pass.

  • The new case fails if the workspace-folder fallback is removed (the command has no cd).

  • pnpm tc:web, oxlint, the ast-grep gates and the changed-code gate pass.

  • I manually tested these changes locally

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

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Test-only.

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)

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

When a tab has no startupCwd, the restart startup plan now gets its fallback path from state.getKnownWorktreeById(args.worktreeId). A new test verifies that a Claude session resumes from its recorded working directory when the worktree identifies the workspace folder.

Priority: Normal

Merge Risk: Low · up to fe7dc

In a narrow stale-state case, Claude may resume from the wrong directory after an account switch.

Pre-merge checks: Passed 5
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description covers the change, reason, testing, visual proof, scope, and checklist. It is clear and aligned with the pull request.
Title check Passed The title clearly identifies the account-restart resume working-directory fallback test. It is specific and related to the main change.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@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.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a5d5ba5-8d13-4c66-8c0f-a71e98655a42
Commits

Reviewing files that changed from the base of the PR and between 584b112 and fe7dc02.

Files selected for processing: 2
  • src/renderer/src/lib/agent-account-restart-startup.test.ts
  • src/renderer/src/lib/agent-account-restart-startup.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.

Comment on lines 103 to 109
// Both restart executors spawn in the tab's start folder.
launchCwd:
state.tabsByWorktree[args.worktreeId]?.find((tab) => tab.id === args.tabId)?.startupCwd ??
worktree?.path
state.getKnownWorktreeById(args.worktreeId)?.path
})
if (!startupPlan) {
return null

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.

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

set -o pipefail
printf '%s\n' '--- restart references ---'
rg -n -F --glob '*.ts' -e 'resolveAgentAccountRestartResumeStartup' -e 'queuePaneAccountRestarts' -e 'account restart' src/renderer/src src/shared || test "$?" -eq 1
printf '%s\n' '--- restart implementation ---'
sed -n '1,180p' src/renderer/src/lib/agent-account-restart-startup.ts
printf '%s\n' '--- restart state and executor references ---'
rg -n -F --glob '*.ts' -e 'queuePaneAccountRestarts' -e 'runAsAutomaticDeselection' -e 'purgeWorktreeTerminalState' src/renderer/src/store src/renderer/src/lib || test "$?" -eq 1
printf '%s\n' '--- relevant caller excerpts ---'
sed -n '1,270p' src/renderer/src/lib/claude-session-account-move.ts
printf '%s\n' '--- stale cleanup excerpt ---'
sed -n '150,235p' src/renderer/src/store/slices/worktrees/listing/fetch-all-worktrees.ts

Repository: stablyai/orca

Length of output: 40072


Script executed:

set -o pipefail
printf '%s\n' '--- account-switch flow ---'
sed -n '250,430p' src/renderer/src/lib/claude-session-account-move.ts
sed -n '1,120p' src/renderer/src/lib/claude-account-switch-sessions.ts
printf '%s\n' '--- restart queue and execution ---'
sed -n '1,110p' src/renderer/src/store/terminals/terminal-restart-state.ts
rg -n -F --glob '*.ts' -e 'buildPaneAccountRestartStartup' -e 'resolveAgentAccountRestartResumeStartup' -e 'pendingPaneAccountRestarts' src/renderer/src/components src/renderer/src/store src/renderer/src/lib || test "$?" -eq 1
printf '%s\n' '--- tab and path-bearing state definitions ---'
rg -n -F --glob '*.ts' -e 'export type TerminalTab' -e 'interface TerminalTab' -e 'startupCwd' -e 'worktreePath' -e 'path:' src/shared/terminal-tab-types.ts src/renderer/src/store/slices/worktrees src/renderer/src/store/terminals || test "$?" -eq 1
printf '%s\n' '--- producer diff against requested base ---'
git diff --find-renames 584b11288dea158da59b230daf8c6c41534b080b3 fe7dc02b098372bd225a581fc291e7cf5e2292f3 -- src/renderer/src/lib/agent-account-restart-startup.ts src/renderer/src/lib/claude-session-account-move.ts src/shared/tui-agent-resume-startup.ts

Repository: stablyai/orca

Length of output: 37823


Script executed:

set -o pipefail
printf '%s\n' '--- resume plan and consumer ---'
rg -n -F --glob '*.ts' -e 'function buildAgentResumeStartupPlan' -e 'export function buildAgentResumeStartupPlan' -e 'agentCwd' -e 'launchCwd' src/shared/tui-agent-resume-startup.ts src/renderer/src/lib/tui-agent-startup.ts src/shared || test "$?" -eq 1
sed -n '1,150p' src/shared/tui-agent-resume-startup.ts
printf '%s\n' '--- provider session and cwd contracts ---'
rg -n -F --glob '*.ts' -e 'type AgentProviderSessionMetadata' -e 'interface AgentProviderSessionMetadata' -e 'cwd:' -e 'providerSession.cwd' -e 'transcriptPath' src/shared src/renderer/src/lib src/renderer/src/store | head -220
printf '%s\n' '--- tab type and worktree-id path helpers ---'
sed -n '35,85p' src/shared/terminal-tab-types.ts
rg -n -F --glob '*.ts' -e 'splitWorktreeIdForFilesystem' -e 'worktreeIdFrom' -e 'folderWorkspaceKey' src/shared src/renderer/src/store | head -160
printf '%s\n' '--- restart spawn cwd usage ---'
rg -n -F --glob '*.ts' -e 'startupPlan.launchCommand' -e 'startup.command' -e 'buildPaneAccountRestartStartup' src/renderer/src/components/terminal-pane src/renderer/src/store | head -180

Repository: stablyai/orca

Length of output: 41619


Do not drop the session-directory correction for stale worktree IDs.

During an account switch, a stale tab entry can reach this producer before stale-worktree cleanup runs. If the tab has no startupCwd, the missing worktree makes launchCwd undefined. The resume builder then omits the cd to providerSession.cwd, so Claude can resume in the wrong directory.

Retain a valid launch path for this restart case. The available source does not establish a safe replacement path, so no patch is included.

@nwparker
nwparker force-pushed the nwparker/fix-account-restart-launch-cwd branch from fe7dc02 to 0ca6bda Compare October 27, 2026 03:02
@nwparker nwparker changed the title fix(accounts): restore the workspace-folder fallback for account-restart resume cwd test(accounts): cover the workspace-folder fallback for account-restart resume cwd Oct 27, 2026
@nwparker
nwparker merged commit f4103b8 into main Oct 27, 2026
34 checks passed
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.

1 participant