Skip to content

Fix bugs and trim code found reviewing the watcher, safe-save and chat-start PRs - #31216

Merged
nwparker merged 1 commit into
mainfrom
nwparker/stack-review-fixes
Oct 20, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/stack-review-fixes

Conversation

@nwparker

@nwparker nwparker commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​451 $\color{#cf222e}{\Huge{\mathbf{−}}}$​171 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​280
Prod 48 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​351 $\color{#cf222e}{\Huge{\mathbf{−}}}$​341 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

ELI5

We had two AI reviewers (Opus and GPT) re-read eight recently merged PRs about file watching, safe saving and chat start-up. This PR fixes the real bugs they found and deletes code that turned out to be unneeded. Production code ends slightly smaller (+327 / −343) even with the fixes.

What Changed

Saving and conflicts (#30605, #30885, #30417, #31113)

  • Phone save could overwrite a newer desktop save. The phone path compared against a tab snapshot taken before an awaited disk read, so a desktop save during that read slipped past the check. It now re-reads the live tab after the read and reports a conflict if the desktop changed.
  • Web requests failed after a successful reconnect with "Runtime connection changed". Reconnect status checks bypassed the wrapper that records connection proof; the wrapper now re-checks status when its proof is missing or stale, still refusing if the runtime is different. No wire change.
  • Reload in a clean tab threw away another tab's edits with no Undo when both tabs show the same file. Undo now uses the edits from whichever tab held them.
  • "Keep my edits" now clears the banner on every tab of the file; the banner updates when a sibling tab gets or loses edits; Compare shows the sibling's edits; a huge paste into an empty file no longer reports a false conflict; closed tabs no longer leak reload entries.
  • Crash diagnostics again record which action wrote to the store and what changed (the per-tab unsaved-state middleware had hidden both). The duplicate buffer-record construction in remote session sync is removed; the middleware already does it.

File watching (#30270, #30415)

  • Autosave could stall during heavy writes. Every "too many changes" event paused autosave on edited tabs and re-checked every tab and diff section. On a Windows paired server (which only sends such events, every 500 ms) autosave never fired while an agent was writing. Events sent because the watch was down now carry an optional resync marker; only those run the full re-check. Older peers ignore the field.
  • Windows paired servers show the first change after 150 ms again (steady 500 ms afterwards, was always 500 ms).
  • Deleted files with an apostrophe in the name are recognised as deleted.
  • The markdown file list keeps publishing on very slow file systems (the stuck-scan watchdog backs off instead of discarding every slow scan).
  • Removed timer options production never varied.

Chat start-up (#30992, #30997)

  • "Took too long to start" only worked for Codex. OpenCode, Gemini (ACP) and Claude start timeouts still showed the generic message. They are now tagged too.
  • Five copies of the same error-chain search replaced with one findInErrorChain. The orphan guard uses AbortController + Node's timer instead of a hand-rolled cancellable wait.
  • Documented an accepted gap: on macOS, a supervisor killed within its provider's first second can leave that provider running; closing it would weaken the reused-PID protection.

Why

These are follow-ups to merged work, not new features. Each fix was checked against the code before being applied (the reviewers disagreed in places, e.g. one said the timeout tagging was dead; ACP and Claude starts still reach it, so it was extended instead). Larger cleanups were skipped where they weren't clearly smaller or would touch busy delivery paths: merging the desktop/web older-host save fallbacks, removing the overflow existence probe (hidden tabs would lose their early "deleted" mark), and a shared batcher timer helper. The per-tab unsaved-state record from #30885 is kept because the next phase builds on it.

Linked Issue

Follow-up to #30270, #30605, #30885, #30417, #31113, #30415, #30992, #30997.

Visual Proof

N/A — no layout or styling change; the behaviour changes (banner/Undo, conflict reporting, refresh timing) are covered by regression tests.

Testing

  • pnpm tc passes; pnpm run check:code-quality:changed passes; oxfmt --check clean.

  • Test suites for every touched area pass (src/main, editor, hooks, store, runtime, web, right-sidebar), with new regression tests for each fix.

  • Some tests also fail on unchanged origin/main (6ac9458) on this machine: tests that start real shells (zsh/bash/fish) or forked children, and in ORCA_REAL_CLAUDE_CLI_TEST=1 claude-structured-real-cli.test.ts, "stops a message interrupted before its reply starts". None of these are caused by this PR.

  • Not manually tested in the running app; macOS only.

  • I manually tested these changes locally

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

AI Disclosure

Review

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

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

The new resync field on FsChangedPayload is optional, so older peers simply get the ordinary handling. Runtime-host recovery overflows are not marked yet (that would need a negotiated stream change).

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)

…rt stacks

Fixes bugs found reviewing #30270, #30605, #30885, #30417, #31113, #30415,
#30992 and #30997, and removes code those PRs made unnecessary.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The changes update filesystem overflow payloads and renderer recovery behavior, watcher refresh scheduling, provider error handling, editor save and shared-model state, store instrumentation, and runtime-pinned web calls. They also add or revise tests for these behaviors.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to a1341

Three issues should be fixed before merge. After heavy file activity, combined-diff reviews can keep showing outdated content. A phone save can overwrite edits typed on the desktop in another tab that shares the same document. Choosing Overwrite from the external-change banner can also save an older draft from a different tab instead of the latest edit.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 48.98% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 49 functions across 50 files. (23 skipped… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the pull request’s main purpose: fixing bugs and removing unnecessary code across file watching, safe saving, and chat startup.
Description check Passed The description is detailed, structured according to the template, and explains the changes, reasons, testing, scope, and known limitations. It reports no manual app testing and does not confirm that …
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.
Full details: Description check

Explanation

The description is detailed, structured according to the template, and explains the changes, reasons, testing, scope, and known limitations. It reports no manual app testing and does not confirm that lint, typecheck, test, and build commands all passed, but these omissions do not make the description incomplete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 48.98% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 49 functions across 50 files. (23 skipped: 1 unsupported, 22 over the file limit.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · 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: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e2ef4c86-b6ca-4938-84bb-cfca3aafb9fa
📥 Commits

Reviewing files that changed from the base of the PR and between 8a4ef49 and a1341f2.

📒 Files selected for processing: 78
  • config/tsconfig.cli.json
  • src/main/acp/acp-errors.ts
  • src/main/acp/acp-json-rpc-peer.test.ts
  • src/main/acp/acp-json-rpc-peer.ts
  • src/main/claude/claude-structured-session-startup.test.ts
  • src/main/claude/claude-structured-session-startup.ts
  • src/main/codex/codex-cli-installation-error.ts
  • src/main/ipc/filesystem-watcher-dormant-rearm.test.ts
  • src/main/ipc/filesystem-watcher-local-capacity.ts
  • src/main/ipc/filesystem-watcher-local-removal.ts
  • src/main/ipc/filesystem-watcher-local-unsubscribe.test.ts
  • src/main/ipc/filesystem-watcher-native-capacity.test.ts
  • src/main/ipc/filesystem-watcher-remote-install.ts
  • src/main/ipc/filesystem-watcher-remote-rearm.test.ts
  • src/main/ipc/filesystem-watcher-remote-removal.ts
  • src/main/ipc/filesystem-watcher-remote-resync.ts
  • src/main/ipc/filesystem-watcher-remote-retry.ts
  • src/main/ipc/filesystem-watcher-terminal-resync.test.ts
  • src/main/ipc/filesystem-watcher.test.ts
  • src/main/ipc/remote-watcher-event-batch.test.ts
  • src/main/ipc/remote-watcher-event-batch.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-conversation-lifetime.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-event-recovery.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-failure-text.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-logger.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-provider-open.ts
  • src/main/native-chat/structured-agent-arguments-error.ts
  • src/main/provider-process/provider-error-chain.ts
  • src/main/provider-process/provider-executable-missing.ts
  • src/main/provider-process/provider-group-orphan-guard.test.ts
  • src/main/provider-process/provider-group-orphan-guard.ts
  • src/main/provider-process/provider-request-timeout.ts
  • src/main/runtime/files/watch/windows-file-watch.test.ts
  • src/main/runtime/files/watch/windows-file-watch.ts
  • src/main/runtime/orca-runtime-files-watch.test.ts
  • src/renderer/src/components/editor/ExternalFileChangeBanner.test.tsx
  • src/renderer/src/components/editor/ExternalFileChangeBanner.tsx
  • src/renderer/src/components/editor/combined-diff/load-sections/use-combined-diff-section-revalidation.test.tsx
  • src/renderer/src/components/editor/combined-diff/load-sections/use-combined-diff-section-revalidation.ts
  • src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-section-actions.disk-precondition.test.tsx
  • src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-section-actions.ts
  • src/renderer/src/components/editor/editor-deleted-file-reload.test.ts
  • src/renderer/src/components/editor/editor-deleted-file-reload.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/editor-save-shared-model.test.ts
  • src/renderer/src/components/editor/editor-stale-mount-guard.ts
  • src/renderer/src/components/editor/large-diff-section-content.ts
  • src/renderer/src/components/editor/use-markdown-document-watch-refresh.test.ts
  • src/renderer/src/components/editor/use-markdown-document-watch-refresh.ts
  • src/renderer/src/components/right-sidebar/file-explorer-linked-watch.test.ts
  • src/renderer/src/components/right-sidebar/file-explorer-watch-refresh-scheduler.test.ts
  • src/renderer/src/components/right-sidebar/file-explorer-watch-refresh-scheduler.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerWatch.ts
  • src/renderer/src/hooks/editor-external-watch-event-reconciliation.ts
  • src/renderer/src/hooks/editor-external-watch-overflow.test.ts
  • src/renderer/src/hooks/editor-external-watch-overflow.ts
  • src/renderer/src/hooks/editor-runtime-file-watch.test.ts
  • src/renderer/src/hooks/editor-runtime-file-watch.ts
  • src/renderer/src/hooks/useEditorExternalWatch-background-trim.test.tsx
  • src/renderer/src/hooks/useEditorExternalWatch-subscriptions.test.tsx
  • src/renderer/src/hooks/useEditorExternalWatch-switch-back.test.tsx
  • src/renderer/src/hooks/useEditorExternalWatch.ts
  • src/renderer/src/runtime/mobile-markdown-bridge.test.ts
  • src/renderer/src/runtime/mobile-markdown-bridge.ts
  • src/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.ts
  • src/renderer/src/runtime/web-session-tabs-sync/apply-preparation-browser.ts
  • src/renderer/src/runtime/web-session-tabs-sync/frame-drawn-server-workspaces.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/state.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.test.ts
  • src/renderer/src/store/index.ts
  • src/renderer/src/store/react-commit-cascade-write-probe.test.ts
  • src/renderer/src/store/react-commit-cascade-write-probe.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts
  • src/renderer/src/store/store-identity-churn-probe.ts
  • src/renderer/src/web/preload-api/web-runtime-calls-connection-pin.test.ts
  • src/renderer/src/web/preload-api/web-runtime-calls.ts
  • src/shared/filesystem-entry-types.ts
💤 Files with no reviewable changes: 5
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts
  • src/renderer/src/runtime/web-session-tabs-sync/frame-drawn-server-workspaces.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/state.ts
  • src/main/ipc/filesystem-watcher-remote-install.ts
  • src/renderer/src/runtime/web-session-tabs-sync/apply-preparation-browser.ts

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

normalizeRuntimePathForComparison(payload.worktreePath) !==
normalizeRuntimePathForComparison(file.filePath) ||
!payload.events.some((change) => change.kind === 'overflow')
payload.resync !== true

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.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Refresh combined-diff content after storm overflows.

A storm overflow can omit the path of a changed file. If that file was already modified, its content can change without changing its git-status signature. This condition skips section reloads, and reconcileEditorTabsAfterOverflow also retains cached combined-diff bodies for storm overflows. Mounted and reopened reviews can therefore continue to show old content. Add a bounded catch-up path for storm overflows that refreshes loaded sections and invalidates cached bodies.

Comment on lines +81 to +87
/** The tab holding the model's unsaved text; it may be a sibling of `file`, not `file` itself. */
export function editorModelDraftHolder(state: AppState, file: OpenFile): OpenFile | undefined {
return editorModelSiblingTabs(state, file).find(
(tab) => tab.isDirty && state.editorDrafts[tab.id] !== undefined
)
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '40,100p' src/renderer/src/store/slices/editor/actions/editor-draft-state.ts
rg -n 'setEditorDraft\(' src/renderer/src --type ts | grep -v test | head -30
rg -n 'editorModelDraftHolder' src/renderer/src | head

Repository: stablyai/orca

Length of output: 3402


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- content change handler ---'
nl -ba src/renderer/src/components/editor/use-editor-content-change-handler.ts
printf '%s\n' '--- save precondition and sibling helpers ---'
nl -ba src/renderer/src/components/editor/editor-save-disk-precondition.ts | sed -n '1,180p'
printf '%s\n' '--- external file change banner ---'
nl -ba src/renderer/src/components/editor/ExternalFileChangeBanner.tsx | sed -n '1,250p'
printf '%s\n' '--- relevant draft clear calls ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'clearEditorDraft(' -e 'clearEditorDrafts(' -e 'setEditorDraft(' src/renderer/src/components/editor src/renderer/src/store src/renderer/src/runtime | head -120

Repository: stablyai/orca

Length of output: 39062


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- handler registration ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'useEditorContentChangeHandler' -e 'onContentChange' -e 'contentChange' src/renderer/src/components/editor | head -160
printf '%s\n' '--- save attempt and queue ---'
nl -ba src/renderer/src/components/editor/editor-file-save-attempt.ts | sed -n '1,260p'
nl -ba src/renderer/src/components/editor/editor-save-queue.ts | sed -n '1,240p'
printf '%s\n' '--- shared model tests ---'
nl -ba src/renderer/src/components/editor/editor-save-shared-model.test.ts | sed -n '1,360p'
nl -ba src/renderer/src/components/editor/editor-save-shared-model-dirty.test.ts | sed -n '1,300p'

Repository: stablyai/orca

Length of output: 42355


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- EditorPanel callback wiring ---'
nl -ba src/renderer/src/components/editor/EditorPanel.tsx | sed -n '145,175p;350,390p'
nl -ba src/renderer/src/components/editor/EditorPanelShell.tsx | sed -n '130,165p'
nl -ba src/renderer/src/components/editor/EditorEditFileSurface.tsx | sed -n '160,235p'
nl -ba src/renderer/src/components/editor/monaco-editor-input-bindings.ts | sed -n '95,135p'
printf '%s\n' '--- save content flow ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'export async function requestEditorFileSave' -e 'fallbackContent' -e 'editorDrafts[' src/renderer/src/components/editor/editor-autosave.ts src/renderer/src/components/editor/editor-save-queue.ts
nl -ba src/renderer/src/components/editor/editor-autosave.ts | sed -n '1,180p'
nl -ba src/renderer/src/components/editor/editor-save-queue.ts | sed -n '100,220p'

Repository: stablyai/orca

Length of output: 25035


Synchronize drafts across shared-model tabs before selecting a holder.

useEditorContentChangeHandler receives the active tab, so typing in A stores A’s draft and typing in B stores B’s draft. It does not update the sibling draft. editorModelDraftHolder then selects the first dirty sibling in openFiles order. If A’s older draft appears first, ExternalFileChangeBanner can pass A to attemptEditorFileSave, and the save queue can write A’s stale draft over B’s newer edit.

Suggested fix
 import { isEditorContentUnchanged } from './editor-content-dirty-state'
+import { editorModelSiblingTabs } from './editor-save-disk-precondition'

...
-      setEditorDraft(file.id, content)
       const ignoreTrailingWhitespace = file.language === 'markdown'
       if (file.mode === 'edit') {
+        const modelSiblings = editorModelSiblingTabs(useAppStore.getState(), file)
         const original = fileContentsRef.current[file.id]?.content ?? ''
-        markFileDirty(
-          file.id,
-          !isEditorContentUnchanged(content, original, ignoreTrailingWhitespace)
-        )
-        // Why: back at the saved text, a kept draft could later restore stale text into the model.
-        if (content === original) {
-          clearEditorDraft(file.id)
+        const dirty = !isEditorContentUnchanged(content, original, ignoreTrailingWhitespace)
+        for (const sibling of modelSiblings) {
+          markFileDirty(sibling.id, dirty)
+          if (dirty) {
+            setEditorDraft(sibling.id, content)
+          } else {
+            clearEditorDraft(sibling.id)
+          }
         }
         return
       }
+      setEditorDraft(file.id, content)

Comment on lines +130 to +131
if (current.source === 'file' && state.editorDrafts[sourceFile.id] !== undefined) {
throw new Error('conflict')

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Check sibling drafts before accepting the phone edit.

If the desktop types in a different source-view tab that shares this Markdown model during the disk read, editorDrafts[sourceFile.id] can remain undefined. The phone save then injects its draft and proceeds despite the newer desktop edit. Check the model’s dirty draft holders, not only the requested tab, before injecting phone content.

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