Skip to content

fix(orcad): preserve workspace scope on Electron sidecar browser tabs - #42737

Closed
eisen0419 wants to merge 1 commit into
stablyai:mainfrom
eisen0419:fix/42718-sidecar-tab-worktree-scope
Closed

eisen0419 wants to merge 1 commit into
stablyai:mainfrom
eisen0419:fix/42718-sidecar-tab-worktree-scope

Conversation

@eisen0419

Copy link
Copy Markdown
Contributor

ELI5

When orcad opens a browser tab in its local Electron sidecar for a specific workspace (orca tab create --worktree ...), the sidecar itself runs in an isolated temporary profile without a workspace catalog and reports worktreeId: null. orcad already recorded the resolved workspace ID when creating the tab, and now puts that workspace ID back onto tab queries (tab list, tab show, tab current, tab profile-show, and adopted popups) instead of exposing worktreeId: null.

What Changed

In ElectronSidecarTabRegistry (src/main/orcad/browser-providers/electron/electron-sidecar-tab-registry.ts):

  • Add worktreeId: z.string().nullable().optional() to ElectronSidecarTabSchema and ElectronSidecarResult.
  • Project the tracked page's worktreeId (or null when unscoped) in rewriteTab so browser.tabList, browser.tabShow, browser.tabCurrent, and popups adopted from a scoped opener report their registered worktreeId rather than the sidecar's null (including unscoped orca tab list --worktree all and merged BrowserClientPageQueries listings).
  • Project top-level worktreeId in rewriteResult when 'worktreeId' in rewritten (prior to rewriting browserPageId from the sidecar ID to the public ID) so browser.tabProfileShow preserves the registered worktreeId without adding worktreeId to unrelated RPC results such as snapshots or evaluations.

Why

#42718 was reported on v1.4.258 (released 14 hours before #41989 shipped paired-desktop tab placement in v1.4.259). On main, server-agent tab create --worktree <selector> already routes to a volunteering paired "This device" desktop via opensOnPairedDesktop, while intentionally falling back to orcad's Electron sidecar when no desktop volunteers, when the desktop is set to "Server (streamed)", or when server-only parameters (--placement server, non-web URLs, older desktops) are used. However, tabs created on the Electron sidecar still lost their explicit --worktree scope in every subsequent query because ElectronServeBrowserProcess.invoke strips worktree before calling the sidecar and ElectronSidecarTabRegistry never projected the stored worktreeId back onto sidecar tab payloads (unlike externalChromiumTabInfo). Projecting the registry's worktreeId keeps workspace scope truthful from a single source of truth on orcad.

Linked Issue

Fixes #42718

Visual Proof

N/A — orcad Electron sidecar RPC registry projection fix (src/main/orcad/browser-providers/electron/electron-sidecar-tab-registry.ts) with no renderer UI layout or visual change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

Verified on macOS:

  • Added src/main/orcad/browser-providers/electron/electron-sidecar-tab-registry.test.ts covering tab list (reconcileTabs), tab show (rewriteResult), tab profile-show (top-level rewriteResult), and popup adoption from a scoped opener; all 4 new tests fail with worktreeId: null before the fix and pass after.
  • Ran all 26 unit test files under src/main/orcad (121 passed, 2 skipped).
  • Ran oxlint, oxlint --config config/oxlint-js-plugins.json, ast-grep scan --config config/sgconfig.yml --min-severity warning, and oxfmt --check cleanly on both touched files.

Risk

Level: Low

Scoped strictly to ElectronSidecarTabRegistry tab and profile-show result rewriting for orcad's Electron sidecar browser provider. Top-level worktreeId projection in rewriteResult is gated by 'worktreeId' in rewritten, so sidecar RPC responses that do not carry worktreeId keep their exact shape. Paired-desktop placement (opensOnPairedDesktop), SSH browser bridges, and persisted state are untouched; a plain revert cleanly restores previous behavior.

AI Disclosure

Implemented and cross-reviewed with Grok 4.7 (grok-4.7) and Gemini (gemini-4-carbon).

Review

  • Cross-platform: Pure in-memory TypeScript registry logic in orcad with no OS-specific branches across Linux, macOS, and Windows.
  • SSH / remote: Preserves workspace attribution on remote headless orca serve (orcad) sidecar tabs without altering paired-desktop or SSH bridge placement.
  • Agent & integration compatibility: orca tab list --worktree all --json, orca tab show, orca tab current, orca tab profile-show, and BrowserClientPageQueries merged workspace listings now report the resolved worktreeId instead of null.
  • Performance: Single O(1) Map.get lookup on pagesBySidecarId per returned tab row.
  • Security: No new IPC channels, network calls, or privilege boundaries; projects only the workspace ID already resolved by host.resolveBrowserWorkspace.

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

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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)
  • I stated the risk: what could break, for whom, and how to back it out
  • 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)

The installed sidecar has no workspace catalog, so its tab replies report worktreeId null. Project the worktree recorded at creation onto list, show, and profile-show results, including popups adopted from their opener.
@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The sidecar tab schema accepts optional, nullable worktree IDs and an optional opener page ID. The registry projects a registered page’s worktree ID into tab and result data. For unknown pages, it preserves the reported ID or defaults to null. Tests cover reconciled tabs, tab-show and profile-show results, and popup opener page ID projection.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 8317c

Sidecar browser tab queries now report the workspace already recorded for each tab, and unscoped tabs report null. The change is small and covered by new tests. No merge-blocking risk was identified. It does not address the tab placement problem in the linked issue.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #42718 has two acceptable expected outcomes. Outcome 1: tab create --worktree <selector> creates a client-hosted tab on the paired desktop. Outcome 2: the command fails before creating a tab a… Provide evidence at the reviewed head that tab create --worktree <explicit-selector> on a headless server with a volunteering paired desktop creates a client-hosted tab, or fails clearly with an open-url hint, without creating a server-…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: restoring the workspace (worktree) scope on Electron sidecar browser tabs in orcad. The raw summary and objectives both confirm the registry projects the registered wo…
Description check Passed The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #42718), Visual Proof (N/A with reason), Testing with checkboxes and concrete verificati…
Out of Scope Changes check Passed All changes fall in src/main/orcad/browser-providers/electron/electron-sidecar-tab-registry.ts and its test file. The diff adds optional, nullable worktreeId to the tab and result schemas. It proj…
Full details: Title check

Explanation

The title names the main change: restoring the workspace (worktree) scope on Electron sidecar browser tabs in orcad. The raw summary and objectives both confirm the registry projects the registered worktreeId onto tab results. The title uses the conventional fix(scope) format and is specific, so it passes.

Full details: Description check

Explanation

The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #42718), Visual Proof (N/A with reason), Testing with checkboxes and concrete verification steps, Risk with a level and a revert note, AI Disclosure, Review, the upstream boundary checkbox, Notes, and the Checklist. Two items need attention. The Risk section does not give the revert detail in the template's required form beyond a plain-revert note, which is adequate. The Linked Issue section follows the template. The AI Disclosure section is filled in, as the template asks for non-team contributors. Overall the description is mostly complete and specific, so it passes.

Full details: Out of Scope Changes check

Explanation

All changes fall in src/main/orcad/browser-providers/electron/electron-sidecar-tab-registry.ts and its test file. The diff adds optional, nullable worktreeId to the tab and result schemas. It projects the registered page's worktreeId (or null) in rewriteTab, which covers tab list, tab show, tab current, and adopted popups. It projects top-level worktreeId in rewriteResult only when the key is present ('worktreeId' in rewritten). This gate keeps unrelated RPC results unchanged. These changes implement the workspace-scope reporting that issue #42718 describes as incorrect (worktreeId: null for an explicitly scoped tab). The test file supports this behavior. No unrelated files or behavior changes were identified in the reviewed diff.

Full details: Linked Issues check

Explanation

Issue #42718 has two acceptable expected outcomes. Outcome 1: tab create --worktree &lt;selector&gt; creates a client-hosted tab on the paired desktop. Outcome 2: the command fails before creating a tab and directs the caller to open-url. The diff does not implement either outcome. It changes only ElectronSidecarTabRegistry (electron-sidecar-tab-registry.ts). It adds worktreeId to ElectronSidecarTabSchema and ElectronSidecarResult, and projects the registered page's worktreeId in rewriteTab and rewriteResult. This makes later queries report the recorded workspace ID instead of null. The PR description states that paired-desktop routing (opensOnPairedDesktop) already exists on main. I did not verify that routing or the explicit-selector fallback path at the reviewed head. The PR objectives also state that the change does not alter tab placement and does not add placement to the create result. The reported server-hosted tab with a separate browser session therefore remains unless existing code already routes explicit-selector creates to the desktop. The create result also does not include the resolved worktreeId or placement, which the issue requests as helpful. Coding requirements in the issue are not fully established by this PR's changes alone.

Resolution

Provide evidence at the reviewed head that tab create --worktree &lt;explicit-selector&gt; on a headless server with a volunteering paired desktop creates a client-hosted tab, or fails clearly with an open-url hint, without creating a server-hosted tab. Inspect the create path that calls opensOnPairedDesktop and the fallback to the Electron sidecar. If that behavior is absent, the PR or a linked follow-up must implement outcome 1 or outcome 2. Decide whether the issue's optional request for worktreeId and placement in the create result is required.

  • 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

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: 21b3786b-0c66-429f-9755-da28ba18a7f6
Commits

Reviewing files that changed from the base of the PR and between fce620d and 8317c0c.

Files selected for processing: 2

  • src/main/orcad/browser-providers/electron/electron-sidecar-tab-registry.test.ts
  • src/main/orcad/browser-providers/electron/electron-sidecar-tab-registry.ts

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

@AmoabaKelvin

Copy link
Copy Markdown
Collaborator

Thanks @eisen0419, this was the right fix. I carried it over in #47136 with your commit kept as is. The only change is a shorter test. It's bundled with a few other orcad browser fixes from the same audit, and you're credited as co-author on the squash commit.

@AmoabaKelvin

Copy link
Copy Markdown
Collaborator

Closing since this landed in #47136, with you credited as co-author. Thanks for the fix!

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]: tab create with explicit --worktree succeeds but creates an unscoped server-hosted tab

2 participants