Repository navigation
fix(ssh): re-arm remote watches that die without a reconnect - #10470
Conversation
Remote file changes stopped being detected over SSH until the file was reopened. The watch pipeline itself was fine — nothing ever re-established the subscription after the transport it was made on went away. Two paths left an editor tab permanently stale: - A reconnect kills the relay's watch registrations, and the previous provider's unwatch handle belongs to the dead transport. - A connect slower than the 60s retry window made installRemoteWatcher give up for good; first deploy to a new host far exceeds that. Neither recovered, because installRemoteWatcher is only reachable from the fs:watchWorktree handler, the retry timer, and the removal-restore path, and the renderer only issues a watch for newly added targets. Reopening the file just re-read it — the watcher stayed dead. Give the layer that owns the transport the job of re-arming: registerSshFilesystemProvider now notifies subscribers, which covers both establish and reconnect since registerProviders runs on both. The watcher keeps the intent to watch in a registry that outlives any single connection, and on registration drops the stale entry (installRemoteWatcher treats an existing entry as installed and would otherwise hand back a watcher that can never fire), reinstalls, and emits overflow so consumers resync the gap. Intent is dropped on unwatch and sender destroy so a closed tab is never resurrected. Verified over SSH to a Rocky Linux 10 host: after the reconnect that previously killed it, a remote append lands in the editor in ~2s with a live remote watcher process, and a second edit in ~1.5s.
A removed worktree kept its entry in the intent registry, so a reconnect landing before the renderer's unwatch would re-watch a deleted path — 60s of retries against the host and then a bogus overflow. Also covers two reinstall cases: several senders on one connection must collapse onto a single relay watch (and all of them resync), and a destroyed renderer must not be reinstalled.
The reinstall emitted the overflow only for listeners whose first install returned 'installed'. If that attempt failed — relay-watcher.js still spawning on the fresh transport, a transient fs.watch rejection — the 1s retry restored the watch but never signalled the gap, so everything that changed while the transport was down stayed invisible: the STA-2525 symptom reappearing inside the fix for it. Thread the resync intent through the retry record so the overflow lands when the retry does. All pre-existing callers default to false, so the watch/terminal-error/restore paths are unchanged.
… slot The `resyncOnInstall ||=` merge was uncovered: removing it left every existing test green. It is load-bearing — if a second renderer joins the reinstall's failing install and reaches the retry slot first with resync=false, the whole chain stays false and the retry restores the watch without ever signalling the gap. New sibling file rather than an append: filesystem-watcher.test.ts is ~10 counted lines from the 800-line lint cap, and AGENTS.md forbids a max-lines disable.
…te-file-changes-are-not-detected-over-ssh-until-the-file
The 60s fast-retry window gave up with a single overflow and no further trigger — provider registration is the only re-arm, and a watch killed by remote OOM/inotify exhaustion leaves the SSH link perfectly healthy. Back off from 1min to a 30min ceiling instead, and stand down entirely when the provider is gone so registration owns that case.
SshFilesystemProvider.dispose() stops each watch registration without invoking its terminal callbacks, so a dropped transport left the runtime file-explorer watch silently dead: the lease's restart only runs from the failed-removal path, and the renderer's runtime subscription stays open because it rides a different link. Reinstall on the connection's next provider registration and emit overflow so clients resync.
…followup-watch-death-no-reconnect
…te-file-changes-are-not-detected-over-ssh-until-the-file
…ver-ssh-until-the-file' of https://github.com/stablyai/orca into brennanb2025/sta2525-followup-watch-death-no-reconnect
…te-file-changes-are-not-detected-over-ssh-until-the-file
…ver-ssh-until-the-file' of https://github.com/stablyai/orca into brennanb2025/sta2525-followup-watch-death-no-reconnect
…followup-watch-death-no-reconnect # Conflicts: # src/main/ipc/filesystem-watcher.ts
📝 WalkthroughWalkthroughAdds SSH filesystem watcher recovery for provider reconnects and remote watcher retry exhaustion. Runtime file-explorer watches reinstall on matching provider registration and emit overflow events. IPC watchers use capped exponential dormant backoff, skip unavailable providers, prevent duplicate installs, and cancel timers during unwatch, removal, provider reinstall, or shutdown. New tests cover recovery, backoff, connection filtering, cleanup, and updated provider-registration mocks. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime-files-ssh-rearm.test.ts (1)
87-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winGood coverage of the core reinstall/resync path.
Test correctly asserts the dead transport's handle is never closed against the fresh provider registration, matching the "Why" comment in
armSshFileExplorerWatchRearm. Consider adding one more case that exercises thereinstallingchaining guard directly: defer the secondwatch()resolution, callunsubscribe()while it's pending, and assert only one handle ends up closed and no double-install occurs. That's the trickiest part of the new logic and isn't directly exercised by the current four tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 25270c70-6286-4cae-b7ed-4ba5890c1cfd
📒 Files selected for processing (6)
src/main/ipc/filesystem-watcher-dormant-rearm.test.tssrc/main/ipc/filesystem-watcher.tssrc/main/runtime/orca-runtime-files-ssh-rearm.test.tssrc/main/runtime/orca-runtime-files-watch.test.tssrc/main/runtime/orca-runtime-files.test.tssrc/main/runtime/orca-runtime-files.ts
…i#10470) * fix(ssh): re-arm remote file watches when the provider reconnects Remote file changes stopped being detected over SSH until the file was reopened. The watch pipeline itself was fine — nothing ever re-established the subscription after the transport it was made on went away. Two paths left an editor tab permanently stale: - A reconnect kills the relay's watch registrations, and the previous provider's unwatch handle belongs to the dead transport. - A connect slower than the 60s retry window made installRemoteWatcher give up for good; first deploy to a new host far exceeds that. Neither recovered, because installRemoteWatcher is only reachable from the fs:watchWorktree handler, the retry timer, and the removal-restore path, and the renderer only issues a watch for newly added targets. Reopening the file just re-read it — the watcher stayed dead. Give the layer that owns the transport the job of re-arming: registerSshFilesystemProvider now notifies subscribers, which covers both establish and reconnect since registerProviders runs on both. The watcher keeps the intent to watch in a registry that outlives any single connection, and on registration drops the stale entry (installRemoteWatcher treats an existing entry as installed and would otherwise hand back a watcher that can never fire), reinstalls, and emits overflow so consumers resync the gap. Intent is dropped on unwatch and sender destroy so a closed tab is never resurrected. Verified over SSH to a Rocky Linux 10 host: after the reconnect that previously killed it, a remote append lands in the editor in ~2s with a live remote watcher process, and a second edit in ~1.5s. * fix(ssh): drop watch intent when a remote worktree is removed A removed worktree kept its entry in the intent registry, so a reconnect landing before the renderer's unwatch would re-watch a deleted path — 60s of retries against the host and then a bogus overflow. Also covers two reinstall cases: several senders on one connection must collapse onto a single relay watch (and all of them resync), and a destroyed renderer must not be reinstalled. * fix(ssh): resync when a reconnect's watch only lands on a retry The reinstall emitted the overflow only for listeners whose first install returned 'installed'. If that attempt failed — relay-watcher.js still spawning on the fresh transport, a transient fs.watch rejection — the 1s retry restored the watch but never signalled the gap, so everything that changed while the transport was down stayed invisible: the STA-2525 symptom reappearing inside the fix for it. Thread the resync intent through the retry record so the overflow lands when the retry does. All pre-existing callers default to false, so the watch/terminal-error/restore paths are unchanged. * test(ssh): cover the resync merge when a fresh watch claims the retry slot The `resyncOnInstall ||=` merge was uncovered: removing it left every existing test green. It is load-bearing — if a second renderer joins the reinstall's failing install and reaches the retry slot first with resync=false, the whole chain stays false and the retry restores the watch without ever signalling the gap. New sibling file rather than an append: filesystem-watcher.test.ts is ~10 counted lines from the 800-line lint cap, and AGENTS.md forbids a max-lines disable. * fix(ssh): re-arm a remote watch that died without a reconnect The 60s fast-retry window gave up with a single overflow and no further trigger — provider registration is the only re-arm, and a watch killed by remote OOM/inotify exhaustion leaves the SSH link perfectly healthy. Back off from 1min to a 30min ceiling instead, and stand down entirely when the provider is gone so registration owns that case. * fix(ssh): re-arm the remote file-explorer watch on reconnect SshFilesystemProvider.dispose() stops each watch registration without invoking its terminal callbacks, so a dropped transport left the runtime file-explorer watch silently dead: the lease's restart only runs from the failed-removal path, and the renderer's runtime subscription stays open because it rides a different link. Reinstall on the connection's next provider registration and emit overflow so clients resync.
Re-opens #10456, whose commits never reached
main. That PR was stacked with its base set to #10445's branch; #10445 merged to main at 00:37:01 and #10456 then merged into that already-merged branch at 00:37:44, so77c2b9a306andfd55ed997fwere orphaned. Same commits, now targetingmaindirectly with main merged in.#10445 re-arms remote file watches when the SSH provider re-registers, which covers a reconnect and a first connect slower than the 60s give-up. Provider registration is the only re-arm trigger it added, and that leaves two holes. Both were confirmed by a failing test before either fix was written.
Gap 1 — a watch that dies without a reconnect
Remote OOM, inotify/fd exhaustion, or the relay watcher being killed all leave the SSH link perfectly healthy, so no provider registration ever follows. The watch went
handleRemoteWatcherTerminalError→ 1s retries → capped atREMOTE_WATCH_RETRY_TIMEOUT_MS(60s) → one give-upoverflow→ dead until the app restarts. Thatoverflowrefreshes the tab once, then it silently stops updating — the original STA-2525 symptom.After the fast window gives up, the key now arms a bounded backoff off the existing
desiredRemoteWatchersintent: 60s doubling to a 30-minute ceiling. A permanently broken remote costs roughly 5fs.watchcalls in the first half hour instead of 60 in the first minute.It stands down rather than competing when something else already owns recovery: a live
remoteWatchersentry, an in-flight fast retry, an empty listener set, a deliberate removal, or no SSH provider at all — the last hands the reconnect case back to #10445's registration hook instead of adding wire traffic to a link already being rebuilt. The timer isunref()'d so a half-hour timer never holds the process alive at quit.Gap 2 — the file-explorer watch never recovered either
SshFilesystemProvider.dispose()callsstopSshFilesystemWatchRegistration, which — unlikefailSshFilesystemWatchRegistration— never invokesterminalCallbacks. So a transport drop fires no terminal callback for the file-explorer lease.The renderer does not rescue it:
useFileExplorerWatch/useEditorExternalWatchonly take the runtime path whenruntimeEnvironmentIdis set,failSharedRuntimeFileWatchmerely deletes the shared watch, and bothonErrorhandlers onlyconsole.warn. The file tree therefore stayed stale across a reconnect even with #10445.Fixed entirely in the main process by reinstalling on the connection's next provider registration and emitting
overflow. No renderer change was needed.Testing
8 new tests across two sibling files (
filesystem-watcher-dormant-rearm.test.ts,orca-runtime-files-ssh-rearm.test.ts— sibling files becausefilesystem-watcher.test.tssits at the 800-line lint cap andmax-linesdisables are forbidden). Every one proven non-vacuous by mutating the source and watching it fail.Gates after merging main: 132/132 across the touched test files,
tsc --noEmitclean,oxlintclean.Merge conflict resolution note: merging
mainconflicted infilesystem-watcher.tsin four places, all of the same shape — this branch adds dormant-re-arm code that main simply lacks, since main received #10445 through its own merge commit. Resolved by keeping this branch's additions; no main-side change was dropped.