Skip to content

fix(shortcuts): gate Cmd/Ctrl+N folder-workspace jumps on path status - #10748

Merged
OrcaWin merged 2 commits into
stablyai:mainfrom
vansh2408:fix/issue-10716-folder-workspace-number-shortcut-gate
Jul 27, 2026
Merged

OrcaWin merged 2 commits into
stablyai:mainfrom
vansh2408:fix/issue-10716-folder-workspace-number-shortcut-gate

Conversation

@vansh2408

Copy link
Copy Markdown
Contributor

Summary

Pressing Cmd/Ctrl+1–9 on a folder-workspace sidebar slot now enforces the same path-status gate as clicking its card. Previously the number shortcut activated the workspace unconditionally, so a folder workspace whose path is missing,
unmounted, or on a disconnected SSH host activated silently into a folder that isn't there; clicking the same card correctly blocked with an error toast.

The onJumpToWorktreeIndex handler now routes through a new activateWorkspaceNumberShortcut(workspaceId) that branches on parseWorkspaceKey — folder: keys go through the guarded activateAndRevealFolderWorkspace, everything else through activateAndRevealWorktree — mirroring activateWorktreeFromSidebar and the nav-history activator.

Fixes #10716. Credit to @Hanxcellent, whose self-closed #9560 contained this fix.

Screenshots

No visual change - the blocked case reuses the existing path-status error toast
already shown by the sidebar click path.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

AI Review Report

  • Key-parsing asymmetry: the folder path takes the stripped folderWorkspaceId while the worktree path takes the raw key — verified against activateAndRevealFolderWorkspace's lookup of state.folderWorkspaces by raw id and the two existing dispatch sites, which use the identical shape.
  • Behavior parity: the shortcut keeps default sidebar-reveal behavior (unlike the click path's revealInSidebar: false) because the shortcut can fire with the sidebar closed; parseWorkspaceKey returning null for plain
    worktree ids falls through to the generic path, preserving prior behavior for all non-folder targets.
  • Cross-platform (macOS/Linux/Windows): explicitly checked. The change is downstream of the onJumpToWorktreeIndex IPC event — shortcut registration (CmdOrCtrl accelerators), labels, and key handling are untouched, so Cmd+N on macOS and Ctrl+N on Linux/Windows route identically. No paths, no shell invocation, no Electron platform branches. The SSH case is the point of the fix: the gate blocks folder workspaces on disconnected SSH hosts. Folder workspaces and git worktrees are both handled per AGENTS.md.

Security Audit

  • Input handling: workspaceId comes from the internally computed rendered sidebar order, not user-typed input; parseWorkspaceKey is plain prefix parsing with no regex or injection surface.
  • No command execution, filesystem, or path handling added; no auth, secrets, or dependency changes.
  • IPC: no new channels or handlers — the existing onJumpToWorktreeIndex listener's behavior is narrowed, not widened.
  • Net effect is fail-closed: the change adds a gate, removing the ability to activate a workspace whose backing path is unavailable. No follow-up needed.

Notes

Call out any platform-specific behavior, risks, or follow-up work.

…ath-status gate

onJumpToWorktreeIndex called activateAndRevealWorktree unconditionally, but
the rendered sidebar order can contain folder-workspace keys (folder:<id>).
Those skipped the getFreshFolderWorkspacePathStatus check that clicking the
card enforces, silently activating workspaces whose folder is missing,
unmounted, or on a disconnected host.

Route the shortcut through a parseWorkspaceKey branch mirroring
activateWorktreeFromSidebar and the nav-history activator.

Fixes stablyai#10716
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Workspace activation now uses an exported helper that parses workspace keys and dispatches folder workspaces to guarded folder activation while preserving worktree activation. The workspace-index IPC handler calls this helper. New tests cover missing, ambiguous, and existing folder paths, platform-specific digit shortcut routing, and handler wiring.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific and matches the main change: gating folder-workspace shortcut activation by path status.
Description check ✅ Passed The description follows the template with summary, screenshots, testing, AI review, security, and notes sections, and includes the required cross-platform review.
Linked Issues check ✅ Passed The changes implement the folder-workspace path-status gate for number shortcuts and preserve the rendered-order shortcut routing required by #10716 and #9560.
Out of Scope Changes check ✅ Passed The diff stays within shortcut routing, shared activation logic, and regression tests, with no unrelated feature or platform changes.

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.

@vansh2408

Copy link
Copy Markdown
Contributor Author

Re: the Docstring Coverage warning - this is CodeRabbit's default advisory threshold reacting to a small diff (2 eligible functions, 1 documented). The documented one is the new exported activateWorkspaceNumberShortcut, which carries the non-obvious constraint (mixed worktree-id / folder:-key input). The undocumented one is an anonymous test mock / inline callback; adding a docstring there would just restate the obvious, which AGENTS.md ("concise, non-obvious comments only") asks us to avoid. Leaving it as is - happy to add one if reviewers prefer.

The fix is correct: Cmd/Ctrl+1-9 on a folder-workspace slot must go through
the path-status gate, and it now does. Two review changes:

1. Reuse instead of duplicate. worktree-activation.ts already contained this
   exact worktree-vs-folder dispatch inline in the nav-history activator.
   Export it as activateAndRevealWorkspace and point both the nav activator
   and the number shortcut at it, rather than adding a new module holding a
   byte-identical third copy of the same branch.

2. Test the real path. The original test mocked @/lib/worktree-activation --
   the very module whose folder branch is the fix -- so it passed even with
   the useIpcEvents wiring reverted. Replaced with a suite that drives the
   real activator against a real store, plus a wiring assertion, so both the
   guard and its call site fail on regression.

Also covers the AGENTS.md cases the fix targets: missing/unmounted path and
ambiguous (disconnected) SSH connection, and asserts the digit chord resolves
on darwin/win32/linux so the gate is not macOS-only.
@OrcaWin

OrcaWin commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Reviewed with an independent reproduction — including a live-app check of Orca opening a terminal into a directory I had just deleted. The bug is real and the gate is the right fix. Two things needed rework, both pushed to this branch.

1. The tests did not exercise the fix. workspace-number-shortcut.test.ts mocks @/lib/worktree-activation — the module whose folder branch is the fix — so it only asserted that a new wrapper forwards to a mock. I reverted the useIpcEvents wiring (restoring the exact original bug) with your tests still in place, and they passed 2/2. Replaced with a suite that drives the real activator against a real store, adds the missing-path and disconnected-SSH cases, adds darwin/win32/linux chord assertions, and pins the handler's call site so the wiring cannot silently regress.

2. The fix duplicated code it already imported. worktree-activation.ts already contained this exact worktree-vs-folder dispatch inline as the nav-history activator; the new module was a byte-identical copy, making it the 4th instance of the pattern. I exported the existing one as activateAndRevealWorkspace and pointed both the nav activator and the number shortcut at it. Net result is 2 files changed instead of a new module — the diff got smaller.

Cross-platform (AGENTS.md): clean. No metaKey is hardcoded; the binding is Mod+1, resolving to meta on darwin and control elsewhere, now asserted with a negative case for win32. Both AGENTS.md-flagged scenarios — folder workspace and disconnected SSH — verified blocking in the running app.

Perf: the guard is a synchronous in-memory cache read, not IPC or a stat, so no blocking work is added to the keystroke path.

Validation: typecheck exit 0, oxlint exit 0, 3516 tests passing across the touched trees.

Good catch on the underlying inconsistency — the click path enforcing a gate the shortcut skipped is exactly the kind of asymmetry that's easy to miss.

@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: Pro Plus

Run ID: 90d7e0c3-4fed-4184-8551-8571aa4ad73e

📥 Commits

Reviewing files that changed from the base of the PR and between ce15488 and e520c49.

📒 Files selected for processing (3)
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/lib/workspace-activation-path-gate.test.ts
  • src/renderer/src/lib/worktree-activation.ts

const visibleIds = getVisibleWorktreeIds()
if (index < visibleIds.length) {
activateAndRevealWorktree(visibleIds[index])
activateAndRevealWorkspace(visibleIds[index])

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Reject invalid workspace indices before indexing.

Negative or fractional values pass this check, yielding undefined; the workspace dispatcher then calls parseWorkspaceKey(undefined) and throws. Require a non-negative integer.

Proposed fix
-        if (index < visibleIds.length) {
+        if (Number.isInteger(index) && index >= 0 && index < visibleIds.length) {
           activateAndRevealWorkspace(visibleIds[index])
         }
📝 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
activateAndRevealWorkspace(visibleIds[index])
if (Number.isInteger(index) && index >= 0 && index < visibleIds.length) {

@OrcaWin
OrcaWin merged commit ab60045 into stablyai:main Jul 27, 2026
23 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…stablyai#10748)

Reviewed with an independent reproduction, including a live-app check. Replaced tests that mocked the module containing the fix, and reused the existing workspace activator instead of adding a 4th copy of the dispatch.
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.

Cmd/Ctrl+N on a folder workspace skips the path-status gate that clicking its card enforces

2 participants