Repository navigation
Conversation
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to 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 |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7943117f-f281-46c9-bec3-861a177ed264
📒 Files selected for processing (2)
src/main/ipc/ssh-browse.test.tssrc/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.
| 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) | ||
| }) |
There was a problem hiding this comment.
🩺 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.
| 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
|
Thanks, @suharvest — this race still exists on current main. Note that the SSH directory browser moved from |
ELI5
When Orca browses a remote SSH directory, the remote channel can emit
exitbefore Orca has subscribed to the channel events. Orca now uses the numeric status later delivered byclosewhen that earlyexitwas 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
exitevent was observed. If it was not observed andcloseprovides 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.
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.tspassed 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author
@suharvest — X