Skip to content

fix: pr-bug-scan validated finding from #7029 - #7184

Closed
buf0-bot[bot] wants to merge 1 commit into
mainfrom
bot/pr-bug-scan-7029-1783050355
Closed

buf0-bot[bot] wants to merge 1 commit into
mainfrom
bot/pr-bug-scan-7029-1783050355

Conversation

@buf0-bot

@buf0-bot buf0-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Automated fix-PR from pr-bug-scan for parent #7029.

Fixer status: FIXED_WITH_CODE_PROOF
Summary: resolveTerminalStartupCwdForWorkspace now falls back to worktree root when a persisted startupCwd subdir is missing; blocks the existsSync throw at local-pty-utils.ts:105.
Blocked proof link: src/main/providers/local-pty-utils.ts:105-107 (existsSync gate no longer throws — resolveGuardedPtySpawnCwd at src/main/ipc/pty.ts:1985/2557 substitutes the worktree root when the persisted startupCwd subdir is gone)
Typecheck: skipped

Proof (from validator)

  • C2 — proof_type: code_analysis
    • trigger: User selects 'Open in Terminal' on a subdirectory, persisting startupCwd=node.path; the subdirectory is later removed (agent/git checkout/user) while the worktree root remains; the tab is then restored or respawned.
    • observable: PTY spawn rejects with 'Working directory "" does not exist. It may have been deleted or is on an unmounted volume.'; the error is surfaced as a terminal error toast (src/renderer/src/components/terminal-pane/pty-transport.ts:798 storedCallbacks.onError?.(msg)) and the terminal never opens.
    • path:
      • src/renderer/src/components/right-sidebar/FileExplorer.tsx:588 handleOpenInTerminal -> createNewTerminalTab(activeWorktreeId, undefined, { startupCwd: node.path })
      • src/renderer/src/store/slices/terminals.ts:802 createTab persists startupCwd when startupCwd.length > 0
      • src/renderer/src/components/Terminal.tsx:1889 cwd={tab.startupCwd ?? workspace.path} on restore
      • src/renderer/src/components/terminal-pane/pty-transport.ts:686 window.api.pty.spawn({ cwd })
      • src/main/ipc/pty.ts:1985 const cwd = resolveGuardedPtySpawnCwd(args.worktreeId, args.cwd)
      • src/shared/terminal-startup-cwd.ts:12-18 resolveTerminalStartupCwd checks only isPathInsideOrEqual (containment), not existence, and returns the resolved cwd

Reproduction

vitest run --config config/vitest.config.ts src/shared/terminal-startup-cwd.test.ts

  • before fix: resolveTerminalStartupCwdForWorkspace returns the deleted subdir '/repo/app/packages/web' → spawn hits existsSync=false → throws 'Working directory ... does not exist'
  • after fix: with a directoryExists probe reporting the subdir gone, it returns the workspace root '/repo/app' which exists, so spawn succeeds

Generated by pr-bug-scan (proof-machine architecture). Human approval required before merge.

resolveTerminalStartupCwdForWorkspace now falls back to worktree root when a persisted startupCwd subdir is missing; blocks the existsSync throw at local-pty-utils.ts:105.
@nwparker

nwparker commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded by #7847, which fixes the same deleted-startupCwd spawn failure but with an explicit fresh-local-only opt-in (renderer flag, main re-gated on no connectionId/sessionId, WSL UNC exempt from the probe, in-terminal notice + metadata) instead of an unconditional resolver fallback — the unconditional version would also remap cwds for reattach/runtime/API callers, which must keep exact cwd semantics. This branch also predates #7750's guard removal and no longer applies cleanly.

@nwparker nwparker closed this Jul 8, 2026
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