Skip to content

fix(ssh): preserve directory browse status on close - #26403

Closed
suharvest wants to merge 2 commits into
stablyai:mainfrom
suharvest:fix/ssh-browse-close-status
Closed

suharvest wants to merge 2 commits into
stablyai:mainfrom
suharvest:fix/ssh-browse-close-status

Conversation

@suharvest

Copy link
Copy Markdown
Contributor

ELI5

When Orca browses a remote SSH directory, the remote channel can emit exit before Orca has subscribed to the channel events. Orca now uses the numeric status later delivered by close when that early exit was missed, while still treating an unknown status as a failure and preserving an exit status observed by Orca.

What Changed

The SSH directory browser records whether an exit event was observed. If it was not observed and close provides a numeric status, that status completes the command result. A close status cannot overwrite an exit status already received. Missing or null status remains an error, so a failed or unverifiable remote listing is not shown as an empty directory.

Tests cover successful close-only completion, early exit delivery before listener subscription, exit-versus-close disagreement, null signal status, and missing status. POSIX-to-PowerShell fallback behavior remains covered.

Why

Issue #8956 tracks Linux remote browsing and PowerShell error symptoms. Closed, unmerged #10785 by @luizeof addressed POSIX command failure fallback; this change addresses the separate early-exit and close-status race.

Linked Issue

Fixes #8956

Visual Proof

Before: user report from macOS 1.4.214

Before: user report from macOS 1.4.214.

After: isolated hidden Electron Add Project remote filesystem fixture

After: isolated hidden Electron Add Project remote filesystem fixture selecting projects

After: Isolated hidden Electron Add Project / remote filesystem fixture, selecting projects returns path to parent.

Testing

  • I manually tested these changes locally

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

    Production SSH browse handler regression coverage in src/main/ipc/ssh-browse.test.ts: 19 tests passed.

    Existing supporting checks: src/main/ssh/ssh-remote-commands.test.ts passed with 22 tests passed and 7 skipped; Node typecheck passed; changed-code quality passed with zero new findings for the two changed files; max-lines and runtime checks passed. Real local SSH2 batch delivered exit before subscription; close retained 0/127 in 4 runs.

    Hidden Electron UI E2E passed: 1 test passed in 5.9s. The Add Project flow used an SSH filesystem fixture, browsed the remote list, entered projects, selected the folder, and returned /srv/orca-ssh-fixture/projects. The helper reported all windows hidden, focus false, and no errors.

AI Disclosure

Codex (GPT-6 family) and GPT-5.6-Luna agents were used for implementation support and review.

Review

The independent code review checked the SSH2 and system SSH channel event contracts, including Linux, macOS, and Windows command channels; SSH remote and local compatibility; fallback behavior; signal and unknown-status handling; listener cleanup; and performance impact. No blocking issue was found in the seven-line production change.

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

Security: remote paths continue through the existing shell escaping and PowerShell literal paths; this change only selects the completion status.

Cross-platform support: ssh2 channels and the system SSH child-process wrapper both provide numeric close codes; Windows PowerShell fallback remains covered.

Remote SSH: an observed exit status remains authoritative; a numeric close status is used only when exit is absent; unknown status fails closed.

Mobile: no mobile code or mobile UI is changed.

Backwards compatibility: no wire format, IPC argument, or public result shape changes.

Performance: the change adds one boolean check per channel completion and no extra remote command.

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)

Author

@suharvest — X

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →Review in Change Stack →

📝 Walkthrough

Walkthrough

The browse command now records whether the SSH channel emitted an exit event. On close, it uses the close status only if no exit event was recorded and the status is numeric. Tests cover conflicting statuses, missing statuses, and an exit event that occurs before subscription.


Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to c1753

This change fixes how SSH directory browsing reports status when the connection closes. The code looks sound and the author reports the tests passing. The only open note is a minor test-timing improvement.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. 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 concise, specific, and accurately describes the main change: preserving the SSH directory browse status from the channel close event.
Description check Passed The description covers all required sections, explains the behavior change and rationale, links an issue, includes visual proof, documents testing, and addresses security, compatibility, performance, …
Linked Issues check Passed Issue [#8956] reports intermittent Linux remote directory listing failures with a false powershell.exe fallback error. In src/main/ipc/ssh-browse.ts, runBrowseCommand uses a numeric close stat…
Out of Scope Changes check Passed The production change is limited to SSH directory-browse channel completion handling. The added tests verify this behavior and preserve fallback behavior. No unrelated production behavior, public resu…


  • Fix all pre-merge checks with AI
  • Autopilot · 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: 7943117f-f281-46c9-bec3-861a177ed264
📥 Commits

Reviewing files that changed from the base of the PR and between 6664de1 and c175351.

📒 Files selected for processing (2)
  • src/main/ipc/ssh-browse.test.ts
  • src/main/ipc/ssh-browse.ts

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

Comment on lines +112 to +133
it('uses a close status when the exit event was missed before subscription', async () => {
const channel = createMockChannel()
const exec = vi.fn().mockResolvedValue(channel)
const getConnectionManager = () => ({
getConnection: () => ({ exec })
})
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: This mock only implements the getConnection().exec surface consumed by the handler; the production manager type is intentionally outside this unit test.
registerSshBrowseHandler(getConnectionManager as never)

const resultPromise = handler(null, { targetId: 'ssh-1', dirPath: '/tmp' })
channel.emit('exit', 0)
await Promise.resolve()
channel.emit('data', Buffer.from('/tmp\nfolder/\n'))
channel.emit('close', 0)

await expect(resultPromise).resolves.toEqual({
resolvedPath: '/tmp',
pathFlavor: 'posix',
entries: [{ name: 'folder', isDirectory: true }]
})
expect(exec).toHaveBeenCalledTimes(1)
})

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

Test does not prove the exit event came before subscription.

The test emits exit after handler(...) returns a pending promise. The exec mock has not resolved at that point, so runBrowseCommand has not subscribed yet. This matches the intended "missed exit" scenario. await Promise.resolve() only gives one microtask tick before data and close are emitted. If runBrowseCommand needs more ticks to subscribe, the data and close events are lost and the test hangs. Use await vi.waitFor(() => expect(channel.listenerCount('close')).toBe(1)) before the data and close emits. This matches the pattern in the later tests and removes the timing dependency.

Proposed fix
     channel.emit('exit', 0)
-    await Promise.resolve()
+    await vi.waitFor(() => expect(channel.listenerCount('close')).toBe(1))
     channel.emit('data', Buffer.from('/tmp\nfolder/\n'))
📝 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
it('uses a close status when the exit event was missed before subscription', async () => {
const channel = createMockChannel()
const exec = vi.fn().mockResolvedValue(channel)
const getConnectionManager = () => ({
getConnection: () => ({ exec })
})
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: This mock only implements the getConnection().exec surface consumed by the handler; the production manager type is intentionally outside this unit test.
registerSshBrowseHandler(getConnectionManager as never)
const resultPromise = handler(null, { targetId: 'ssh-1', dirPath: '/tmp' })
channel.emit('exit', 0)
await Promise.resolve()
channel.emit('data', Buffer.from('/tmp\nfolder/\n'))
channel.emit('close', 0)
await expect(resultPromise).resolves.toEqual({
resolvedPath: '/tmp',
pathFlavor: 'posix',
entries: [{ name: 'folder', isDirectory: true }]
})
expect(exec).toHaveBeenCalledTimes(1)
})
it('uses a close status when the exit event was missed before subscription', async () => {
const channel = createMockChannel()
const exec = vi.fn().mockResolvedValue(channel)
const getConnectionManager = () => ({
getConnection: () => ({ exec })
})
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: This mock only implements the getConnection().exec surface consumed by the handler; the production manager type is intentionally outside this unit test.
registerSshBrowseHandler(getConnectionManager as never)
const resultPromise = handler(null, { targetId: 'ssh-1', dirPath: '/tmp' })
channel.emit('exit', 0)
await vi.waitFor(() => expect(channel.listenerCount('close')).toBe(1))
channel.emit('data', Buffer.from('/tmp\nfolder/\n'))
channel.emit('close', 0)
await expect(resultPromise).resolves.toEqual({
resolvedPath: '/tmp',
pathFlavor: 'posix',
entries: [{ name: 'folder', isDirectory: true }]
})
expect(exec).toHaveBeenCalledTimes(1)
})

Source: Learnings

@OrcaWin

OrcaWin commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks, @suharvest — this race still exists on current main. Note that the SSH directory browser moved from src/main/ipc/ssh-browse.ts to src/main/ssh/ssh-remote-directory-browse.ts (onClose still ignores the status close delivers), so this will need a rebase onto that file. #26940 touches the same spot, so it would be good to land just one of them.

@suharvest suharvest closed this Oct 11, 2026
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]: Fail to list remote dirs

2 participants