Skip to content

fix(ssh): re-arm remote watches that die without a reconnect - #10470

Merged
brennanb2025 merged 13 commits into
mainfrom
brennanb2025/sta2525-followup-watch-death-no-reconnect
Jul 25, 2026
Merged

brennanb2025 merged 13 commits into
mainfrom
brennanb2025/sta2525-followup-watch-death-no-reconnect

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

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, so 77c2b9a306 and fd55ed997f were orphaned. Same commits, now targeting main directly 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 at REMOTE_WATCH_RETRY_TIMEOUT_MS (60s) → one give-up overflow → dead until the app restarts. That overflow refreshes 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 desiredRemoteWatchers intent: 60s doubling to a 30-minute ceiling. A permanently broken remote costs roughly 5 fs.watch calls 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 remoteWatchers entry, 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 is unref()'d so a half-hour timer never holds the process alive at quit.

Gap 2 — the file-explorer watch never recovered either

SshFilesystemProvider.dispose() calls stopSshFilesystemWatchRegistration, which — unlike failSshFilesystemWatchRegistration — never invokes terminalCallbacks. So a transport drop fires no terminal callback for the file-explorer lease.

The renderer does not rescue it: useFileExplorerWatch / useEditorExternalWatch only take the runtime path when runtimeEnvironmentId is set, failSharedRuntimeFileWatch merely deletes the shared watch, and both onError handlers only console.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 because filesystem-watcher.test.ts sits at the 800-line lint cap and max-lines disables 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 --noEmit clean, oxlint clean.

Merge conflict resolution note: merging main conflicted in filesystem-watcher.ts in 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.

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.
…te-file-changes-are-not-detected-over-ssh-until-the-file
…te-file-changes-are-not-detected-over-ssh-until-the-file
…followup-watch-death-no-reconnect

# Conflicts:
#	src/main/ipc/filesystem-watcher.ts
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and testing, but it omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, including screenshots or 'No visual change', a testing checklist, AI review cross-platform checks, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the SSH remote watch re-arm fix and matches the main change.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

🧹 Nitpick comments (1)
src/main/runtime/orca-runtime-files-ssh-rearm.test.ts (1)

87-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Good 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 the reinstalling chaining guard directly: defer the second watch() resolution, call unsubscribe() 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

📥 Commits

Reviewing files that changed from the base of the PR and between a903304 and 13495a2.

📒 Files selected for processing (6)
  • src/main/ipc/filesystem-watcher-dormant-rearm.test.ts
  • src/main/ipc/filesystem-watcher.ts
  • src/main/runtime/orca-runtime-files-ssh-rearm.test.ts
  • src/main/runtime/orca-runtime-files-watch.test.ts
  • src/main/runtime/orca-runtime-files.test.ts
  • src/main/runtime/orca-runtime-files.ts

@brennanb2025
brennanb2025 merged commit 9acb685 into main Jul 25, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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