Skip to content

fix(cli): target the calling terminal's folder workspace, not its parent - #33703

Merged
AmoabaKelvin merged 1 commit into
mainfrom
cli-folder-workspace-caller-tie
Oct 26, 2026
Merged

AmoabaKelvin merged 1 commit into
mainfrom
cli-folder-workspace-caller-tie

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​12 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

ELI5

When an agent in a folder project's second workspace opened a browser tab, the tab went to the project's first workspace instead. All of a folder project's workspaces live in the same folder, so the CLI couldn't tell them apart by folder. Now it asks the terminal which workspace it belongs to whenever the folder alone can't decide.

What Changed

  • Before: run orca tab create (or tab list, tab current, browser commands without --page, terminal commands, computer, worktree current, --worktree current) from a terminal in a folder project's extra workspace, and the CLI resolves the parent <repoId>::<path> row. The tab lands in a workspace the user isn't looking at, and the workspace's own tab strip stays empty.
  • After: the CLI resolves the terminal's own <repoId>::<path>::workspace:<uuid> row, so the tab shows up in that workspace.
  • Mechanism: selectEnclosingWorktreeSelectionOnHost picks the innermost catalog row that contains the cwd. Rows with the same path used to resolve by catalog order, and the runtime always lists the parent first. Now the row whose id matches the pane's ORCA_WORKTREE_ID wins that tie. The cwd still decides whenever paths differ, so a terminal that cds into another worktree still targets that worktree.

Why

resolveCurrentWorktreeSelection is the one cwd-based default that every implicit target goes through, and folder workspaces are the one case where the cwd can't pick a single row. Fixing the tie there covers every command at once, and nothing needs a special case.

Alternatives considered:

Linked Issue

Fixes #33618

Linear: STA-12165

Visual Proof

N/A for screenshots: the change is in which workspace id the CLI sends. I reproduced it from real state on a throwaway orca serve: a non-git folder project with a second workspace, ws2. Both rows have path /private/tmp/o33618-folder. I ran the commands from that folder.

orca worktree current --json:

CLI ORCA_WORKTREE_ID = ws2 row unset
installed app parent …::/private/tmp/o33618-folder parent
origin/main parent parent
this branch …::/private/tmp/o33618-folder::workspace:eed101ec-… parent

I also ran orca tab create --url about:blank --json with ORCA_WORKTREE_ID set to ws2. tab list --worktree all then showed main's tab under the parent and this branch's tab under ws2.

Testing

  • I manually tested these changes locally

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

  • Manual (macOS): the headless serve repro above. I also ran from a git repo with ORCA_WORKTREE_ID pointing at the folder workspace, and it still resolved to the git repo's own row.

  • New test in src/cli/browser.test.ts: tab create from a folder workspace pane targets that pane's row, not the parent that shares its path. It fails on main, which sends id:repo::/tmp/folder.

  • Focused suites pass: browser, worktree-selector-caller-host, index-worktree-selector-resolution, index-terminal-commands, handlers/emulator. Both check:code-quality:changed and check:react-doctor:changed are clean.

AI Disclosure

Review

  • One Codex review round came back with no high-value findings.

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

  • Git worktrees: unchanged. Their paths are distinct, so the tie-break never applies.
  • SSH:
    • SSH terminals run their own orcad runtime, so ORCA_WORKTREE_ID comes from that runtime's catalog.
    • For legacy relay panes, the existing host filtering runs before the tie-break.
  • Paired remote clients still refuse cwd shortcuts, as before.
  • Windows/WSL: path comparison is unchanged, and ORCA_WORKTREE_ID is already forwarded through WSLENV.
  • Stale or unmatched ids: a deleted workspace id, or the floating terminal's id, matches no row. The resolver then falls back to the previous choice and never errors.
  • Mixed versions: CLI-only change. It reads the same worktree.list fields older runtimes already return.
  • Performance: one string compare per enclosing row. No new RPCs.
  • Separate bug found while testing, not fixed here: on macOS, a folder registered under the /tmp/... symlink never matches the cwd, because the shell reports the real path /private/tmp/.... Main has the same behaviour.

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)

Every workspace in a folder project shares the project path, so the cwd
match always picked the parent row.

Fixes #33618
@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 26, 2026 19:43
@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: 3539a4a0-7dd3-4162-90ac-d50c9f80cdaa
Commits

Reviewing files that changed from the base of the PR and between 1b58be9 and f7d5a92.

Files selected for processing: 3
  • src/cli/browser.test.ts
  • src/cli/caller-host-worktree-selection.ts
  • src/cli/selectors.ts

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

Walkthrough

The CLI now passes ORCA_WORKTREE_ID to host-scoped worktree selection. When enclosing worktrees have equal-length paths, the helper can select the row whose ID matches the caller worktree ID. A browser CLI test checks that tab create targets the workspace when the parent and workspace share a path. The test setup also restores stubbed environment variables after each test.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to f7d5a

The workspace-selection change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary CLI fix: selecting the calling terminal's folder workspace instead of its parent.
Description check Passed The description is complete and follows the repository template. It explains the user impact, implementation, rationale, linked issue, testing, compatibility considerations, and checklist status.
Linked Issues check Passed Issue #33618 requires that an implicit-target CLI command from a folder workspace terminal use that workspace's row (::::workspace:) instead of the parent row (::). T…
Out of Scope Changes check Passed All changes stay within the implicit worktree-selection path that #33618 describes. src/cli/caller-host-worktree-selection.ts adds the tie-break for equal-length enclosing rows. src/cli/selectors.ts f…
Full details: Linked Issues check

Explanation

Issue #33618 requires that an implicit-target CLI command from a folder workspace terminal use that workspace's row (<repoId>::<path>::workspace:<uuid>) instead of the parent row (<repoId>::<path>). The PR meets this in src/cli/caller-host-worktree-selection.ts. selectEnclosingWorktreeSelectionOnHost now takes an optional callerWorktreeId. Among enclosing rows with equal path length, the row whose id matches the caller id replaces the current pick. Other equal-length rows are skipped. Longer enclosing paths still win, so the cwd still decides when paths differ. src/cli/selectors.ts passes process.env.ORCA_WORKTREE_ID into resolveCurrentWorktreeSelection. That resolver backs the implicit default for getBrowserWorktreeSelector, which covers tab create, tab list, tab current, and browser commands without --page, as the issue describes. Commands with --page are not changed, which matches the issue. The host filter runs before the tie-break, so SSH and paired-client behavior keeps its existing guards. A new test in src/cli/browser.test.ts (#33618) checks that tab create from a folder workspace pane sends id:<workspace id>. The issue's suggested fix (mirror the emulator's env-first order) is not copied. The PR explains why: an env-first order would ignore the cwd after a cd. The issue asks for the outcome, and the outcome is implemented. The behavior was not executed in this review. Evidence is the diff and the test assertions. The PR reports focused suites and a manual repro.

Full details: Out of Scope Changes check

Explanation

All changes stay within the implicit worktree-selection path that #33618 describes. src/cli/caller-host-worktree-selection.ts adds the tie-break for equal-length enclosing rows. src/cli/selectors.ts forwards ORCA_WORKTREE_ID to that function. src/cli/browser.test.ts adds the #33618 regression test and vi.unstubAllEnvs() in afterEach, which supports the new env stub. The change also affects worktree current, --worktree current, terminal, and computer commands. These commands use the same cwd default through resolveCurrentWorktreeSelection, so the fix applies to them as a shared consequence, not as an unrelated change. No unrelated files or features are touched. Git worktree rows have distinct paths, so the tie-break does not change their behavior. The PR does not add the folder:<id> selector work from #19699 or #19700, and it lists those as not addressed.

Finishing Touches: 💡 1
📝 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.

@AmoabaKelvin
AmoabaKelvin merged commit 67851c0 into main Oct 26, 2026
67 checks passed
@AmoabaKelvin
AmoabaKelvin deleted the cli-folder-workspace-caller-tie branch October 26, 2026 20:12
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.

[Bug]: orca tab create from a folder workspace terminal puts the tab in the parent workspace

1 participant