Skip to content

fix(sidebar): stop background workspace creation from scrolling the sidebar - #11530

Merged
nwparker merged 2 commits into
mainfrom
nwparker/sidebar-quiet-background-workspace-create
Jul 30, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/sidebar-quiet-background-workspace-create

Conversation

@nwparker

@nwparker nwparker commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to #11445. That PR stopped background workspace creation from stealing the user's selection. The sidebar still scrolled by itself, because the scroll comes from a different signal.

Adopting a terminal and pointing the user at it were the same decision. This separates them with a surfaceOwner flag, and every background path now adopts silently.

ELI5

Creating a workspace in the background should be like a coworker quietly filing a new folder in the cabinet behind you. Orca was tapping you on the shoulder and turning your chair toward the cabinet — not far enough to change what you were working on, but far enough to lose your place in the list.

Under the hood: a background create still has to start that workspace's terminal. When Orca handed that terminal to the UI it said nothing about how to present it, and "said nothing" was read as "show it to the user" — so the sidebar scrolled. #11445 stopped the chair from turning all the way; this removes the shoulder-tap.

Now a background create explicitly says "adopt this terminal silently": the tab is still created and the agent still runs, but the sidebar stays where you left it. Terminals you actually ask for still reveal themselves as before.

Root cause

A background create still spawns the new workspace's terminals via OrcaRuntimeService.createTerminal, which asks the renderer to adopt the PTY through notifier.revealTerminalSession(...).

No worktree-create call site passed a presentation, so resolveTerminalPresentation returned undefined. Every downstream check is presentation !== 'background' — true for undefined — and the renderer mirrored it:

const shouldSurfaceOwner = terminalPresentation !== 'background' // undefined -> true
if (shouldSurfaceOwner) {
  store.revealWorktreeInSidebar(worktreeId) // scrolls the sidebar, expands collapsed groups
  focusTerminalInitiatedTab(tab.id)
}

So "no presentation stated" meant "point the user at this terminal". That default is right for orca terminal create, where discoverability is the entire point — the runtime even returns a warning when the reveal fails. It is wrong for terminals the user never asked for.

presentation: 'background' could not express this: it means "do not adopt the terminal in the renderer at all", which would leave the new workspace with no tab for its agent.

Version boundary

shouldSurfaceOwner arrived in #6686 (Jun 28), which decoupled "surface the owner" from "activate". Before it the reveal was gated on activation, so a non-activating create could not scroll the sidebar. #11445 fixed the activation half; this fixes the surfacing half.

Design

surfaceOwner is typed ?: false, not ?: boolean — absent means "surface it", so the flag is a suppression switch and true is unrepresentable. One way to express each intent.

surfaceOwner: false is passed from every background path: the agent/startup terminal, the plain initial shell, the Setup tab (both new-tab and split-pane placement), default tabs, and orchestration worker dispatch. It is threaded through createTerminal and splitTerminal. Explicitly activated creates omit it.

No new CLI/RPC surface: surfaceOwner is main-internal and absent from the terminal.create RPC schema, so callers cannot set it.

Proof of regression

Tests were written against the fix, then run with the production change reverted.

Main process — reverting only the surfaceOwner: false arguments at the worktree-create call sites, leaving the forwarding machinery intact:

Failed Tests 5
FAIL orca-runtime.test.ts > follows normal setup policy for CLI-created worktrees without activating them
FAIL orca-runtime.test.ts > creates the first terminal for CLI-created worktrees without activating them
FAIL orca-runtime.test.ts > does not surface the new workspace when a background CLI create launches its agent
FAIL orchestration.test.ts > starts a fresh agent in the coordinator current worktree
FAIL orchestration.test.ts > starts a fresh agent in an exact existing worktree without replaying setup
      Tests  5 failed | 1081 passed | 1 skipped (1087)

The no-regression pair bites in the opposite direction — replacing ...ownerSurfacing(shouldActivate) with an unconditional surfaceOwner: false:

FAIL orca-runtime.test.ts > still surfaces the new workspace when the caller explicitly activates it
FAIL orca-runtime.test.ts > still surfaces the new workspace when hooks run in the foreground
      Tests  2 failed | 935 passed | 1 skipped (938)

Split-mode Setup (the review catch below) is wired to both halves of its fix independently — removing either the ...surfacing spread in the shouldSplitSetup branch or the ...ownerSurfacing(...) in splitPtyBackedTerminal produces:

FAIL orca-runtime.test.ts > does not surface the new workspace when a background create splits its setup pane
- "surfaceOwner": false,

Renderer — reverting each handler's guard fails only its own test, so both code paths are independently covered:

FAIL useIpcEvents.test.ts > adopts a background workspace terminal without scrolling the sidebar to it
FAIL useIpcEvents.test.ts > replies to a requested terminal create without scrolling the sidebar when surfaceOwner is false
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
Received: 1st vi.fn() call: Array [ "wt-2" ]

Proof of fix

  • Full unit suite: 41,413 passed, 72 skipped (3,920 files passed, 10 skipped).
    • The only failure, src/relay/agent-exec-handler.test.ts (2 tests), reproduces identically on a clean tree at 37af4577 and is unrelated.
  • pnpm run typecheck:node, pnpm run typecheck:web: passed.
  • pnpm run check:code-quality:changed: 0 new findings across 11 files.
  • pnpm run check:max-lines-ratchet, pnpm run verify:bundled-skill-guides: passed.
  • oxlint + oxfmt --check clean on all changed files.

Proof of no regression

  • orca terminal create still reveals its workspace — no surfaceOwner in its payload, and the pre-existing assertion is untouched. Each new renderer test also runs a control phase asserting the default still reveals.
  • Explicit --activate and legacy --run-hooks still reveal, in both new-tab and split Setup placement; four tests assert surfaceOwner is absent from the reveal payload.
  • Terminals are still adopted in every background case — the new tests assert createTab is called with the pre-minted tab id, so the agent tab exists when the user opens the workspace.
  • presentation: 'background' semantics are untouched; surfaceOwner is a separate axis.
  • The renderer no longer calls focusTerminalInitiatedTab for background creates, removing a second latent focus-steal on a workspace the user is not viewing.

Review notes

  • Split-mode Setup (caught in review): with setupScriptLaunchMode: split-vertical|split-horizontal the Setup terminal goes through splitTerminal, whose reveal payload had no surfaceOwner — a real gap, now fixed and tested. The non-PTY split path is unaffected: notifier.splitTerminal only dispatches a renderer CustomEvent and never reveals.
  • notifier.createTerminal was also flagged, but it is unreachable — grep -rn "notifier\.createTerminal" src/main (excluding tests) returns nothing. The worker path calls the OrcaRuntimeService.createTerminal method, which routes through revealTerminalSession. Threading the flag there would mean widening the notifier type for a path nothing calls.

Known second cause (not in this PR)

While investigating I reproduced a second, independent cause of sidebar self-scrolling: creating a child worktree makes buildRenderableRows collapse the parent and its children into one lineage-group row, which rewrites the parent's scroll-anchor key. If that parent was the top-visible row, runVirtualizedScrollAnchorRestore cannot find the old key and pins a different row to the top — a measured +180 px jump with no reveal involved. It is long-standing rather than RC-new, needs the anchored row to be exactly that parent, and is being handled separately.

…idebar

Creating a workspace in the background still spawns its terminals, and the
renderer treated "no presentation stated" as "point the user at this
terminal" -- revealing (scrolling to) the owning workspace.

Split adoption from surfacing with an explicit surfaceOwner flag: background
worktree creates and worker dispatch adopt their tabs silently, while
`orca terminal create` keeps its discoverability reveal.
@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a sidebar-scrolling regression introduced by the background workspace creation path: when Orca spawned terminals for a background worktree, the renderer's default "absent surfaceOwner = reveal" logic caused the sidebar to scroll to the new workspace even though the user never asked to navigate there.

  • Introduces a surfaceOwner?: false suppression flag on RuntimeTerminalCreateBaseRequestPayload (and all related types), threaded from every background terminal-creation call site through the IPC bridge to the renderer's shouldSurfaceOwner guard.
  • Adds ownerSurfacing(bool) helper in the runtime to canonicalize the "absent = surface, false = suppress" protocol, and passes surfaceOwner: false from all background paths (agent startup, plain initial shell, setup pane, default tabs, orchestration worker dispatch).
  • Covers both directions with new unit tests: background creates assert the flag is present and the sidebar is not scrolled; explicit --activate / --run-hooks creates assert the flag is absent and the reveal still fires.

Confidence Score: 5/5

The change is narrowly scoped — it adds a suppression flag that defaults to the existing reveal behavior, so any omission on a new call site silently falls back to the pre-existing safe path rather than breaking anything.

All background terminal creation call sites are updated consistently, the absent-means-surface default is preserved throughout, and both directions (background creates suppress; explicit activations still reveal) are independently exercised by new unit tests verified to fail against the pre-fix code.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/main/runtime/orca-runtime.ts Core runtime changes: adds ownerSurfacing helper, threads surfaceOwner: false through all background terminal creation paths (startup terminal, default tabs, setup pane, plain shell), and moves shouldActivate earlier in one method so it's available when constructing reveal payloads.
src/renderer/src/hooks/useIpcEvents.ts Renderer: updates both onCreateTerminal and onRequestTerminalCreate handlers to gate shouldSurfaceOwner on surfaceOwner !== false, correctly keeping the "absent = reveal" default while suppressing for background creates.
src/main/window/attach-main-window-services.ts IPC bridge: forwards surfaceOwner: false from the main-process payload to the renderer event only when explicitly set, preserving the absent-means-surface protocol across the IPC boundary.
src/shared/runtime-types.ts Adds surfaceOwner?: false to RuntimeTerminalCreateBaseRequestPayload as a suppression-only flag; well-documented with a JSDoc comment explaining the absent-means-surface convention.
src/main/runtime/rpc/methods/orchestration-worker-topology.ts Adds surfaceOwner: false to the worker dispatch createTerminal call, preventing orchestration worker creation from scrolling the sidebar to the worker's workspace.
src/renderer/src/hooks/ipc-events-test-harness.ts Test harness: adds RequestTerminalCreateRequest type and requestTerminalCreate helper; types surfaceOwner as boolean (slightly looser than the production false-only type) — no production impact.

Reviews (2): Last reviewed commit: "fix(sidebar): keep split-mode setup pane..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 522f04e0-8300-4a84-818e-82e0ab561540

📥 Commits

Reviewing files that changed from the base of the PR and between aa273e4 and ed28a01.

📒 Files selected for processing (5)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/shared/runtime-types.ts

📝 Walkthrough

Walkthrough

Adds an optional surfaceOwner flag to terminal creation contracts and propagates it through runtime, main-window IPC, preload, and renderer handlers. Background or non-activating terminal creation passes surfaceOwner: false, allowing terminals to be adopted without sidebar reveal or tab focus. Runtime and renderer tests cover silent background creation, explicit activation, foreground hooks, split setup, and worker terminal creation.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it does not follow the required template and omits Screenshots, Testing checkboxes, AI Review Report, and Security Audit sections. Rewrite the PR description to match the template, adding Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main behavior change in this PR.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/runtime/orca-runtime.ts (1)

19994-20051: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Split-mode Setup terminal doesn't respect surfaceOwner: false.

When setupScriptLaunchMode is split-vertical/split-horizontal, the Setup terminal is created via this.splitTerminal(primaryTerminalHandle!, {...}) (lines 20040-20046), which never receives silent/surfaceOwner. splitTerminal's options type and its revealTerminalSession call (see splitPtyBackedTerminal, ~lines 25278-25291) have no surfaceOwner field at all — only activate. During background (non-activated) worktree creation with this launch mode, the Setup terminal's reveal will still surface the workspace/sidebar (only its focus is suppressed via activate: false), which defeats the intent of this PR for that configuration.

Thread surfaceOwner through splitTerminal's options and its revealTerminalSession call the same way createTerminal does, and pass it from this shouldSplitSetup branch when silent.surfaceOwner === false.

🐛 Proposed fix sketch
         const setupTerminal = await (shouldSplitSetup
           ? this.splitTerminal(primaryTerminalHandle!, {
               direction: setupLaunchMode === 'split-horizontal' ? 'horizontal' : 'vertical',
               command: setupCommand,
               env: setupEnv,
-              activate: false
+              activate: false,
+              ...silent
             })

(plus adding surfaceOwner?: boolean to splitTerminal's opts type and forwarding it into the revealTerminalSession call in splitPtyBackedTerminal.)


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 84f9209d-b0ce-4c1d-bf5d-ebf458c074cc

📥 Commits

Reviewing files that changed from the base of the PR and between d0d8695 and aa273e4.

📒 Files selected for processing (11)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/orchestration-worker-topology.ts
  • src/main/runtime/rpc/methods/orchestration.test.ts
  • src/main/window/attach-main-window-services.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/hooks/ipc-events-test-harness.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/shared/runtime-types.ts

...(opts.viewMode ? { viewMode: opts.viewMode } : {}),
activate: opts.activate !== false,
...(opts.presentation ? { presentation: opts.presentation } : {}),
...(opts.surfaceOwner === false ? { surfaceOwner: false } : {}),

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Forward surfaceOwner through the notifier-based create path.

surfaceOwner: false is added only to the revealTerminalSession payload at Line 405. The sibling setNotifier().createTerminal callback still omits it at Lines 339–347. Because the worker path now passes surfaceOwner: false to runtime.createTerminal, this can reach the renderer as undefined, causing surfaceOwner !== false to reveal and focus the worker workspace.

Mirror the conditional spread in the first ui:createTerminal payload.

Proposed fix
         title: opts.title,
         ...(opts.presentation ? { presentation: opts.presentation } : {}),
+        ...(opts.surfaceOwner === false ? { surfaceOwner: false } : {})
       }),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
...(opts.surfaceOwner === false ? { surfaceOwner: false } : {}),
title: opts.title,
...(opts.presentation ? { presentation: opts.presentation } : {}),
...(opts.surfaceOwner === false ? { surfaceOwner: false } : {}),

@nwparker

Copy link
Copy Markdown
Contributor Author

Good catch — confirmed and fixed.

splitPtyBackedTerminal calls revealTerminalSession with activate: opts.activate !== false but no surfaceOwner, so with setupScriptLaunchMode: split-vertical|split-horizontal a background workspace create would still scroll the sidebar to its Setup terminal. The non-PTY split path is unaffected — notifier.splitTerminal only dispatches a renderer CustomEvent and never reveals.

Threaded surfaceOwner?: false through both splitTerminal and splitPtyBackedTerminal, forwarded it into the reveal call, and passed it from the shouldSplitSetup branch. Adding a regression test for the split-mode configuration specifically, since it is a separate code path from the createTerminal one already covered.

@nwparker

Copy link
Copy Markdown
Contributor Author

On the notifier.createTerminal callback (attach-main-window-services.ts:339-347) — I checked, and that path is unreachable, so I am leaving it alone.

RuntimeNotifier.createTerminal is declared (orca-runtime.ts:1693) and implemented, but has no live caller in main:

$ grep -rn "notifier?\.createTerminal\|notifier\.createTerminal" src/main --include=*.ts | grep -v "\.test\."
(no results)

The worker path calls runtime.createTerminal(...) — the OrcaRuntimeService method, not the notifier callback — and that method routes to the renderer through revealTerminalSession, which does forward surfaceOwner. So surfaceOwner: false cannot reach the notifier callback. Threading the flag into dead code would mean also widening the notifier type for a path nothing calls, so I would rather not add that plumbing.

The split-mode Setup gap from the other comment was real and is fixed, with a regression test.

Review catch: with setupScriptLaunchMode split-vertical/horizontal the Setup
terminal goes through splitTerminal, whose reveal payload had no surfaceOwner,
so a background create still scrolled the sidebar in that configuration.

Also narrow surfaceOwner to `false` so "surface it" can only be expressed by
omitting the key, and fold the repeated conditional spreads into ownerSurfacing.
@nwparker
nwparker merged commit 0fe1278 into main Jul 30, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…idebar (stablyai#11530)

* fix(sidebar): stop background workspace creation from scrolling the sidebar

Creating a workspace in the background still spawns its terminals, and the
renderer treated "no presentation stated" as "point the user at this
terminal" -- revealing (scrolling to) the owning workspace.

Split adoption from surfacing with an explicit surfaceOwner flag: background
worktree creates and worker dispatch adopt their tabs silently, while
`orca terminal create` keeps its discoverability reveal.

* fix(sidebar): keep split-mode setup panes silent, tighten surfaceOwner

Review catch: with setupScriptLaunchMode split-vertical/horizontal the Setup
terminal goes through splitTerminal, whose reveal payload had no surfaceOwner,
so a background create still scrolled the sidebar in that configuration.

Also narrow surfaceOwner to `false` so "surface it" can only be expressed by
omitting the key, and fold the repeated conditional spreads into ownerSurfacing.
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