Skip to content

fix(runtime): isolate same-path folder workspace terminals - #12435

Closed
dgk-dev wants to merge 1 commit into
stablyai:mainfrom
dgk-dev:fix/folder-workspace-instance-terminal-identity
Closed

dgk-dev wants to merge 1 commit into
stablyai:mainfrom
dgk-dev:fix/folder-workspace-instance-terminal-identity

Conversation

@dgk-dev

@dgk-dev dgk-dev commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Folder projects intentionally support multiple independent workspace sessions backed by the same directory. Their IDs differ only by the synthetic ::workspace:<uuid> suffix.

Runtime PTY ownership comparisons used splitWorktreeIdForFilesystem, which deliberately strips that suffix for cwd/filesystem operations. As a result, two distinct folder workspace instances compared equal. During controller inventory refresh, an exact target could select or rebind a sibling workspace's PTY; paired/mobile clients could then receive a stale or perpetually pending terminal handle and remain on Loading terminal.

This change keeps the suffix in runtime identity comparison and identity-map keys by using splitWorktreeId. Filesystem callers continue using splitWorktreeIdForFilesystem, so both sessions still launch in the shared physical directory.

User-visible result

Multiple workspaces under one Folder project can keep separate terminal graphs even though they intentionally share a directory. Opening one workspace from Mobile no longer allows another same-path workspace's PTY to satisfy its terminal refresh.

Regression coverage

The regression creates two live controller PTYs with the same folder path and different ::workspace:<uuid> owners, requests the second workspace by exact ID, and proves only its own PTY is selected and recorded. The pre-fix comparison admits both because the UUID suffix is stripped.

Validation

  • src/main/runtime/orca-runtime.test.ts: 1,022 passed, 1 existing skip
  • Node/CLI/Web TypeScript projects passed
  • Focused Oxlint passed
  • Focused formatter check passed
  • git diff --check passed

Relationship to #11868

This is complementary and substantially narrower. #11868 restores and reattaches persisted folder session snapshots across runtime generations and adds deletion/routing fences. This PR fixes the lower-level synthetic folder-project instance identity (repo::path::workspace:<uuid>) that currently collapses before those snapshot/materialization decisions. It does not duplicate the reattachment or tombstone work.

Preserve ::workspace:<uuid> in runtime identity comparisons so folder project sessions sharing one directory cannot adopt or select each other’s PTYs.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8f9d9a32-189c-48b0-8087-cc979f880384

📥 Commits

Reviewing files that changed from the base of the PR and between 086a5d6 and 993caa1.

📒 Files selected for processing (2)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

📝 Walkthrough

Walkthrough

The runtime now uses splitWorktreeId for worktree comparisons and identity keys. This preserves workspace-specific IDs for terminal and session state. A regression test verifies exact PTY scoping for same-path folder workspaces, prevents fallback worktree scans, and confirms that only the matching PTY remains indexed.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and testing well, but it omits the required AI Review Report, Security Audit, Notes, Screenshots, and template Testing sections. Add all required template sections, including cross-platform AI review confirmation, security audit findings, screenshots status, testing checkboxes, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: isolating terminals for same-path folder workspaces.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

@nwparker

nwparker commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thanks @dgk-dev — independently reproduced and confirmed your diagnosis: runtimeWorktreeIdsEqual/runtimeWorktreeIdentityKey were parsing with splitWorktreeIdForFilesystem, so every folder workspace on one path (including the suffix-less folder root) compared equal.

I've opened #12474 which carries your regression test over essentially verbatim (it drives the public listTerminals('id:<exact>') path and asserts the sibling PTY is never recorded — a better vector than my private-method tests), plus your inline note on runtimeWorktreeIdentityKey. Credit for the root cause is yours.

It adds three follow-ons: collapsing the duplicated hand-rolled comparison in stopTerminalsForWorktree (the drift that caused this), a targetWorktreeId tie-break in findResolvedWorktreeIdForPath (without it, the stricter identity comparison silently drops unowned cwd-only PTYs from a folder workspace's inventory — a new regression the identity fix would otherwise introduce), and coverage for the persisted-surface / "Loading terminal" path and the folder root as a third distinct identity.

@AmethystLiang

Copy link
Copy Markdown
Contributor

Duplicate of #12474.

Same root cause and intended fix: isolate same-path folder workspace PTY identity so distinct ::workspace:<uuid> sessions do not compare equal after filesystem id stripping. Please continue review/landing on #12474. If this branch has a meaningfully different implementation detail worth cherry-picking, call it out on #12474.

@nwparker

nwparker commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Landed as #12474 → 6ea99f66075 on main, with your regression test carried over essentially verbatim and your inline note on runtimeWorktreeIdentityKey. Credited as co-author on the squash commit. Thanks for finding and diagnosing this one, @dgk-dev — the root cause (splitWorktreeIdForFilesystem used for identity) was yours.

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.

4 participants