Skip to content

[hardening 4/5] fix(sidebar): confirm before sleeping a workspace that another host's copy shares - #30047

Merged
nwparker merged 1 commit into
mainfrom
nwparker/host-worktree-target-kill-sleep
Oct 18, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/host-worktree-target-kill-sleep

Conversation

@nwparker

@nwparker nwparker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​109 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​341 $\color{#cf222e}{\Huge{\mathbf{−}}}$​86 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​255

Stack (unmerged, for review): 1/5 #30030 → 2/5 #30035 → 3/5 #30059 → 4/5 this PR → 5/5 #30060.

ELI5

The same project folder can be open twice in Orca: once on this computer and once on a remote machine. Both copies share one workspace. Putting either copy to sleep puts the whole workspace to sleep, as it does on main today. Now Orca asks first when you picked only one of the two copies, so you aren't surprised when the other copy sleeps too.

What Changed

Before: in the sidebar, "Sleep" on one copy of a workspace that two hosts publish silently stopped the other copy's shells and agents as well.

After:

  • If your selection names only one copy of such a workspace, a dialog says "Also sleeps the copy on " before anything happens. Confirming sleeps the whole workspace, exactly as main does.
  • If your selection names every copy, the workspace sleeps once, with no dialog.
  • A refusal because Orca can't tell which host runs the terminals now says so. Before, it told you to check the connection.

Mechanism:

Twin suite: the kill, sleep and select cells now assert the documented whole-workspace behaviour (user decision 2026-10-17):

  • killing or sleeping one copy also stops the other copy's terminals;
  • selecting a copy wakes the whole workspace.

Why

Sleeping per copy needed a separate per-tab fence system, which the earlier version of this PR built and Codex kept finding gaps in. Sleeping the whole workspace with a confirmation keeps main's simple shared marker, and the user sees the cost before accepting it.

The earlier version also moved legacy remote-terminal closes and terminal identity onto the focus-free owner resolver. Codex found twice that this routes an older, unstamped row's remote terminal to the local runtime. Those files stay as on main for now.

No wire or persisted change.

Linked Issue

Stage 1 row 1.3 of the SSH hardening design. No public issue.

Visual Proof

A new confirmation dialog built from the existing shadcn Dialog pattern, the same one RemoveFolderDialog uses. Live verify: none; covered by unit tests only.

Testing

  • src/renderer/src/components/sidebar/sleep-twin-confirmation.test.ts covers three cases: one copy selected, every copy selected, and a single-host workspace.

  • sleep-worktree-flow.test.ts checks that a workspace named twice sleeps once.

  • host-twin-isolation.test.ts: the kill, sleep and select cells assert the whole-workspace behaviour.

  • Local runs:

    • pnpm tc;
    • unit tests for src/renderer/src/store, lib, components/sidebar and hooks/ipc-events;
    • the full components/terminal-pane folder (531 files);
    • a local mirror of the full static-analysis job, which passes;
    • the localization extraction check.
  • I manually tested these changes locally

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

AI Disclosure

Review

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

  • SSH and paired servers: the sleep reaches every copy, as on main. Now the user is told first.
  • Folder workspaces: covered by the twin suite.
  • Compatibility: no wire change.

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)

@nwparker
nwparker force-pushed the nwparker/destructive-callers-refuse-ambiguous branch from e3625de to 7c3cf40 Compare October 17, 2026 11:39
@nwparker
nwparker force-pushed the nwparker/host-worktree-target-kill-sleep branch from 73239d0 to 53aaf9e Compare October 17, 2026 11:40
@nwparker
nwparker changed the base branch from nwparker/destructive-callers-refuse-ambiguous to nwparker/fold-explicit-runtime-owner October 17, 2026 11:40
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 871fab9 to 65689bf Compare October 17, 2026 11:56
@nwparker
nwparker force-pushed the nwparker/host-worktree-target-kill-sleep branch from 436045b to ef28e88 Compare October 17, 2026 12:37
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 65689bf to 59fda1b Compare October 17, 2026 14:26
@nwparker
nwparker force-pushed the nwparker/host-worktree-target-kill-sleep branch 2 times, most recently from 135c6fa to 516f433 Compare October 17, 2026 21:59
@nwparker nwparker changed the title [hardening 4/N] fix(terminals): kill and sleep on one copy of a twin leave the other copy running [hardening 4/5] fix(sidebar): confirm before sleeping a workspace that another host's copy shares Oct 17, 2026
@nwparker
nwparker force-pushed the nwparker/host-worktree-target-kill-sleep branch from 516f433 to 9cabc62 Compare October 17, 2026 22:01
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 9732228 to 81fd4e5 Compare October 17, 2026 22:52
@nwparker
nwparker force-pushed the nwparker/host-worktree-target-kill-sleep branch from 9cabc62 to acee149 Compare October 17, 2026 22:52
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch 3 times, most recently from 858e871 to 98a5426 Compare October 18, 2026 03:24
@nwparker
nwparker force-pushed the nwparker/host-worktree-target-kill-sleep branch from acee149 to 75a8c16 Compare October 18, 2026 03:47
@nwparker
nwparker changed the base branch from nwparker/fold-explicit-runtime-owner to main October 18, 2026 03:47
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change adds a confirmation dialog for sleep actions that affect twin worktrees on other hosts. It adds shared terminal host-attribution helpers and updates repository-removal attribution to use them. The sleep flow now deduplicates worktree IDs and uses shared, translated failure messages.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 75a8c

A workspace copy added while the confirmation is open can be slept without being disclosed in the prompt. Recheck the affected hosts before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 13 files. (6 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the primary change: confirming before sleeping a shared workspace when another host has a copy.
Description check Passed The description is detailed and covers the user impact, mechanism, rationale, testing, compatibility, and checklist. It does not provide an actual linked issue, an explicit N/A visual-proof statement …
Full details: Description check

Explanation

The description is detailed and covers the user impact, mechanism, rationale, testing, compatibility, and checklist. It does not provide an actual linked issue, an explicit N/A visual-proof statement or screenshots, and it leaves manual testing and the full command checklist incomplete, but the overall description is substantially complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 13 files. (6 skipped: 6 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ 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.

@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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 194981e4-052e-4755-a2a6-70f605e9ec2b
📥 Commits

Reviewing files that changed from the base of the PR and between 3d03c33 and 75a8c16.

📒 Files selected for processing: 19
  • src/renderer/src/components/sidebar/SleepTwinWorkspaceDialog.tsx
  • src/renderer/src/components/sidebar/index.tsx
  • src/renderer/src/components/sidebar/sleep-failure-message.ts
  • src/renderer/src/components/sidebar/sleep-twin-confirmation.test.ts
  • src/renderer/src/components/sidebar/sleep-twin-confirmation.ts
  • src/renderer/src/components/sidebar/sleep-worktree-flow.test.ts
  • src/renderer/src/components/sidebar/sleep-worktree-flow.ts
  • src/renderer/src/components/sidebar/use-worktree-context-menu-commands.ts
  • src/renderer/src/components/sidebar/use-worktree-context-menu-model.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/store/host-twin-isolation.test.ts
  • src/renderer/src/store/repos/host-twin-terminal-evidence.ts
  • src/renderer/src/store/repos/repo-removal-host-twin-attribution.ts
  • src/renderer/src/store/slices/ui/ui-slice-contract-contextual.ts

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

Comment on lines +46 to +48
const handleConfirm = useCallback(() => {
closeModal()
void runSleepWorktrees(worktreeIds)

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 | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

sed -n '120,225p' src/renderer/src/components/sidebar/sleep-worktree-flow.ts
sed -n '155,205p' src/renderer/src/store/host-twin-isolation.test.ts
rg -n 'collectTwinPurgeScopes|sleepWorktree|hasWorktreeSleepIntent|shutdownTerminalsForWorktree' src/renderer/src/components/sidebar/sleep-worktree-flow.ts src/renderer/src/store src/renderer/src/lib | head -130

Repository: stablyai/orca

Length of output: 10016


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- dialog and callers ---'
sed -n '1,125p' src/renderer/src/components/sidebar/SleepTwinWorkspaceDialog.tsx
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'confirm-sleep-twin' -e 'SleepTwinWorkspaceDialog' -e 'runSleepWorktrees(' -e 'openModal' src/renderer/src/components/sidebar src/renderer/src/store src/renderer/src/lib | head -220
printf '%s\n' '--- sleep flow and terminal teardown ---'
sed -n '1,125p' src/renderer/src/components/sidebar/sleep-worktree-flow.ts
sed -n '125,225p' src/renderer/src/components/sidebar/sleep-worktree-flow.ts
sed -n '1,220p' src/renderer/src/store/terminals/terminal-shutdown.ts
printf '%s\n' '--- purge and sleep-intent consumers ---'
sed -n '1,280p' src/renderer/src/store/host-twin-worktree-purge.test.ts
sed -n '1,150p' src/renderer/src/store/terminals/terminal-pty-release.ts
sed -n '1,130p' src/renderer/src/lib/worktree-sleep-intent.ts
printf '%s\n' '--- browser shutdown ---'
sed -n '220,285p' src/renderer/src/store/slices/browser/browser-close-actions.ts

Repository: stablyai/orca

Length of output: 43605


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- exact definitions and consumers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'type Modal' -e 'confirm-sleep-twin' -e 'SleepTwinWorkspaceDialog' -e 'runSleepWorktrees' -e 'shutdownWorktreeTerminals' -e 'purgeWorktreeTerminalState' -e 'browserTabsByWorktree' src/renderer/src/components/sidebar src/renderer/src/store src/renderer/src/lib | head -260
printf '%s\n' '--- dialog ---'
sed -n '1,110p' src/renderer/src/components/sidebar/SleepTwinWorkspaceDialog.tsx
printf '%s\n' '--- sleep flow ---'
sed -n '90,225p' src/renderer/src/components/sidebar/sleep-worktree-flow.ts
printf '%s\n' '--- terminal shutdown owner and implementation ---'
sed -n '1,260p' src/renderer/src/store/terminals/terminal-shutdown.ts
sed -n '1,220p' src/renderer/src/store/terminals/terminal-teardown-owner.ts
printf '%s\n' '--- browser close implementation ---'
sed -n '220,285p' src/renderer/src/store/slices/browser/browser-close-actions.ts
printf '%s\n' '--- purge implementation and relevant tests ---'
rg -n -F --glob '*.ts' -e 'purgeWorktreeTerminalState' -e 'hostWorktreeTarget' -e 'survivorStopped' src/renderer/src/store | head -120
sed -n '1,120p' src/renderer/src/store/host-twin-worktree-purge.test.ts

Repository: stablyai/orca

Length of output: 42914


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- dialog and callers ---'
sed -n '1,125p' src/renderer/src/components/sidebar/SleepTwinWorkspaceDialog.tsx
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'confirm-sleep-twin' -e 'SleepTwinWorkspaceDialog' -e 'runSleepWorktrees(' -e 'openModal' src/renderer/src/components/sidebar src/renderer/src/store src/renderer/src/lib | head -220
printf '%s\n' '--- sleep flow ---'
sed -n '90,225p' src/renderer/src/components/sidebar/sleep-worktree-flow.ts
printf '%s\n' '--- terminal shutdown ---'
rg -n -F --glob '*.ts' -e 'shutdownWorktreeTerminals' -e 'purgeWorktreeTerminalState' src/renderer/src/store | head -120
sed -n '1,260p' src/renderer/src/store/terminals/terminal-shutdown.ts
printf '%s\n' '--- browser shutdown ---'
sed -n '220,285p' src/renderer/src/store/slices/browser/browser-close-actions.ts
printf '%s\n' '--- sleep intent ---'
sed -n '1,130p' src/renderer/src/lib/worktree-sleep-intent.ts

Repository: stablyai/orca

Length of output: 42898


Recheck the affected hosts before confirming workspace sleep.

SleepTwinWorkspaceDialog uses hostIds only for the message. Confirmation passes raw worktreeIds to runSleepWorktrees. That flow can stop live PTYs from a newly published host and suspend the shared workspace without renewed confirmation.

Recalculate the affected hosts before teardown. If the host set changed, request confirmation for the new scope. Keep the final teardown workspace-wide after consent; replacing it with host-qualified targets would break the intended shared-workspace behavior.

@nwparker
nwparker merged commit 98b4139 into main Oct 18, 2026
39 of 59 checks passed
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