Repository navigation
Fix bugs and trim code found reviewing the watcher, safe-save and chat-start PRs - #31216
Conversation
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e2ef4c86-b6ca-4938-84bb-cfca3aafb9fa
📒 Files selected for processing: 78
config/tsconfig.cli.jsonsrc/main/acp/acp-errors.tssrc/main/acp/acp-json-rpc-peer.test.tssrc/main/acp/acp-json-rpc-peer.tssrc/main/claude/claude-structured-session-startup.test.tssrc/main/claude/claude-structured-session-startup.tssrc/main/codex/codex-cli-installation-error.tssrc/main/ipc/filesystem-watcher-dormant-rearm.test.tssrc/main/ipc/filesystem-watcher-local-capacity.tssrc/main/ipc/filesystem-watcher-local-removal.tssrc/main/ipc/filesystem-watcher-local-unsubscribe.test.tssrc/main/ipc/filesystem-watcher-native-capacity.test.tssrc/main/ipc/filesystem-watcher-remote-install.tssrc/main/ipc/filesystem-watcher-remote-rearm.test.tssrc/main/ipc/filesystem-watcher-remote-removal.tssrc/main/ipc/filesystem-watcher-remote-resync.tssrc/main/ipc/filesystem-watcher-remote-retry.tssrc/main/ipc/filesystem-watcher-terminal-resync.test.tssrc/main/ipc/filesystem-watcher.test.tssrc/main/ipc/remote-watcher-event-batch.test.tssrc/main/ipc/remote-watcher-event-batch.tssrc/main/native-chat/agent-session-wire/structured-agent-session-conversation-lifetime.tssrc/main/native-chat/agent-session-wire/structured-agent-session-event-recovery.tssrc/main/native-chat/agent-session-wire/structured-agent-session-failure-text.tssrc/main/native-chat/agent-session-wire/structured-agent-session-logger.tssrc/main/native-chat/agent-session-wire/structured-agent-session-provider-open.tssrc/main/native-chat/structured-agent-arguments-error.tssrc/main/provider-process/provider-error-chain.tssrc/main/provider-process/provider-executable-missing.tssrc/main/provider-process/provider-group-orphan-guard.test.tssrc/main/provider-process/provider-group-orphan-guard.tssrc/main/provider-process/provider-request-timeout.tssrc/main/runtime/files/watch/windows-file-watch.test.tssrc/main/runtime/files/watch/windows-file-watch.tssrc/main/runtime/orca-runtime-files-watch.test.tssrc/renderer/src/components/editor/ExternalFileChangeBanner.test.tsxsrc/renderer/src/components/editor/ExternalFileChangeBanner.tsxsrc/renderer/src/components/editor/combined-diff/load-sections/use-combined-diff-section-revalidation.test.tsxsrc/renderer/src/components/editor/combined-diff/load-sections/use-combined-diff-section-revalidation.tssrc/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-section-actions.disk-precondition.test.tsxsrc/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-section-actions.tssrc/renderer/src/components/editor/editor-deleted-file-reload.test.tssrc/renderer/src/components/editor/editor-deleted-file-reload.tssrc/renderer/src/components/editor/editor-save-disk-precondition.tssrc/renderer/src/components/editor/editor-save-queue.tssrc/renderer/src/components/editor/editor-save-shared-model.test.tssrc/renderer/src/components/editor/editor-stale-mount-guard.tssrc/renderer/src/components/editor/large-diff-section-content.tssrc/renderer/src/components/editor/use-markdown-document-watch-refresh.test.tssrc/renderer/src/components/editor/use-markdown-document-watch-refresh.tssrc/renderer/src/components/right-sidebar/file-explorer-linked-watch.test.tssrc/renderer/src/components/right-sidebar/file-explorer-watch-refresh-scheduler.test.tssrc/renderer/src/components/right-sidebar/file-explorer-watch-refresh-scheduler.tssrc/renderer/src/components/right-sidebar/useFileExplorerWatch.tssrc/renderer/src/hooks/editor-external-watch-event-reconciliation.tssrc/renderer/src/hooks/editor-external-watch-overflow.test.tssrc/renderer/src/hooks/editor-external-watch-overflow.tssrc/renderer/src/hooks/editor-runtime-file-watch.test.tssrc/renderer/src/hooks/editor-runtime-file-watch.tssrc/renderer/src/hooks/useEditorExternalWatch-background-trim.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch-subscriptions.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch-switch-back.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch.tssrc/renderer/src/runtime/mobile-markdown-bridge.test.tssrc/renderer/src/runtime/mobile-markdown-bridge.tssrc/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.tssrc/renderer/src/runtime/web-session-tabs-sync/apply-preparation-browser.tssrc/renderer/src/runtime/web-session-tabs-sync/frame-drawn-server-workspaces.test.tssrc/renderer/src/runtime/web-session-tabs-sync/state.tssrc/renderer/src/store/editor-buffer-record-lifecycle.test.tssrc/renderer/src/store/index.tssrc/renderer/src/store/react-commit-cascade-write-probe.test.tssrc/renderer/src/store/react-commit-cascade-write-probe.tssrc/renderer/src/store/slices/editor/buffers/editor-buffer-record.tssrc/renderer/src/store/store-identity-churn-probe.tssrc/renderer/src/web/preload-api/web-runtime-calls-connection-pin.test.tssrc/renderer/src/web/preload-api/web-runtime-calls.tssrc/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 |
There was a problem hiding this comment.
🎯 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.
| /** 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 | ||
| ) | ||
| } | ||
|
|
There was a problem hiding this comment.
🗄️ 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 | headRepository: 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 -120Repository: 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)| if (current.source === 'file' && state.editorDrafts[sourceFile.id] !== undefined) { | ||
| throw new Error('conflict') |
There was a problem hiding this comment.
🗄️ 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.
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)
File watching (#30270, #30415)
resyncmarker; only those run the full re-check. Older peers ignore the field.Chat start-up (#30992, #30997)
findInErrorChain. The orphan guard usesAbortController+ Node's timer instead of a hand-rolled cancellable wait.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 tcpasses;pnpm run check:code-quality:changedpasses;oxfmt --checkclean.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 inORCA_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
Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
The new
resyncfield onFsChangedPayloadis 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)