Skip to content

Autosave relies on the guarded save instead of pause flags; identical saves don't rewrite; non-UTF-8 files aren't autosaved - #31768

Merged
nwparker merged 6 commits into
mainfrom
nwparker/editor-drop-pause-flags
Oct 22, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/editor-drop-pause-flags

Conversation

@nwparker

@nwparker nwparker commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​855 $\color{#cf222e}{\Huge{\mathbf{−}}}$​324 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​531
Prod 25 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​369 $\color{#cf222e}{\Huge{\mathbf{−}}}$​289 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80

ELI5

After a restart, a workspace move or a reconnect, Orca used to pause autosave on tabs with unsaved edits until it had re-read the file, using two internal flags. Those flags are gone: autosave now goes through the same "refuse if the file changed on disk" save as everything else. If the file on disk already holds exactly the text being saved, the save succeeds without writing. Autosave never writes over a file that isn't valid UTF-8 text.

What Changed

  • Pause flags removed. Restored or moved tabs autosave straight away through the guarded save. If disk changed to something else, the save is refused and the existing changed-on-disk banner appears; the draft is kept. If two restored tabs of one file disagree, the first save lands and the other gets the banner.
  • Identical content isn't rewritten. When disk already holds exactly the bytes being saved, the save reports success without writing (also for a read-only file). New hosts advertise this (files.write.identical-noop.v1); for older hosts the client checks first on automatic saves.
  • Non-UTF-8 files. Automatic saves (autosave, save before restart) refuse to write a file whose disk bytes aren't valid UTF-8, so a lossy decode can never authorize an overwrite. The user sees "Autosave is paused for because it isn't UTF-8 text. Save it yourself to convert it to UTF-8."; an explicit save converts it and lifts the pause, and closing or reloading the tab clears it.
  • Switching back to a workspace that wasn't being watched compares dirty tabs with disk in the background and shows the existing changed-on-disk banner if the file changed (no pause; read errors and Orca's own just-written saves are ignored).

Why

The flags existed to stop a restored tab from writing over a newer file. The guarded save already refuses that, so the flags were a second mechanism doing the same job. Relying on one check is less code and fewer states to get stuck in. The identical-content shortcut keeps a restored draft that already matches disk from showing a false conflict. While reviewing, a pre-existing gap surfaced (two different invalid-UTF-8 files decode to the same text, so an automatic save could pass the check); automatic saves now check the bytes.

Linked Issue

Follow-up to #31655.

Visual Proof

The new notice for a non-UTF-8 file after typing with autosave on:

(screenshot removed: contained real product data)

Testing

  • Restored drafts (equal to baseline, equal to disk, disk changed), identical-content skip on every host path including a read-only file, lossy-decode refusal (small and >1 MB), valid UTF-8 containing � autosaving normally, non-UTF-8 notice shown once and again after reopen, explicit save converting, resync banner with autosave off, read-error and own-echo ignored, older hosts skipping the pre-read on explicit saves.

  • pnpm tc, check:code-quality:changed, oxfmt, oxlint, localization checks pass.

  • filesystem-watcher-real / filesystem-watcher-ignore-real time out in our local sandbox; this change doesn't touch the watcher.

  • 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

Mixed versions: the new write result field and request flag are optional; older hosts ignore the flag and older clients read the new refusal reason as "changed". The removed flags were never persisted or sent over the wire.

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)

nwparker and others added 5 commits October 21, 2026 14:42
…oved tabs

Delete the pendingDiskBaselineVerification and pendingLiveDiskVerification
pause flags. Every editor save is already a guarded write; a refusal raises
the changed-on-disk banner, which is what stops autosave until an explicit
save.

A guarded write now succeeds when disk changed but already holds exactly the
text being saved (local/host compare is byte-exact; client-side fallbacks
compare decoded text and refuse when it holds U+FFFD), so a restored draft
that matches disk goes clean instead of showing a banner.

The restore scan only raises the banner early for tabs that arrive dirty; a
watch resync no longer re-checks dirty tabs.

Co-Authored-By: Claude <[email protected]>
Return a compatible optional no-op result from hosts and client fallbacks, clean the tab, and clear its provisional self-write stamp without rewriting identical bytes.

Co-Authored-By: Claude <[email protected]>
…er hosts, flag dirty tabs on resync

- Autosave and pre-restart saves refuse when disk text can't be decoded losslessly, so a
  baseline that decoded to U+FFFD can't authorize overwriting different bytes.
- New files.write.identical-noop.v1 capability; for hosts with only the v1 guarded write the
  client compares first, skips identical saves, then delegates to the host's guarded write.
- Watch resync compares dirty tabs against disk and shows the changed-on-disk banner.
- Local guarded writes check for identical content before the write-only regular-file probe.

Co-Authored-By: Claude <[email protected]>
…false resync banners

- Local guarded writes judge losslessness by bytes, so a valid UTF-8 file containing U+FFFD
  autosaves again. A file that really isn't UTF-8 is refused with its own reason, 'not-utf8'
  (older clients read it as 'changed'), which pauses autosave for that file with one notice
  until an explicit save converts it.
- A watch resync whose disk read fails leaves dirty tabs alone; the guarded save still catches
  a real conflict.
- Resync and restored-tab checks treat disk holding the tab's own just-written save as an echo.
- On hosts with only the v1 guarded write, only automatic saves read the file first; explicit
  saves go straight to the host's guard.

Co-Authored-By: Claude <[email protected]>
…d report disk changes first

- The pause is released once no dirty tab of the file remains (close, reload from disk,
  discard), so a reopened or reloaded file's next autosave asks the host again and notifies.
- Client-side precondition checks compare the signature before looking for U+FFFD, so an
  external rewrite shows the changed-on-disk banner rather than the non-UTF-8 notice.

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

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2da36398-1789-4bd1-baa5-617ff43badaf
📥 Commits

Reviewing files that changed from the base of the PR and between 147e81e and e94149c.

📒 Files selected for processing: 1
  • src/renderer/src/i18n/locales/en.json
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/i18n/locales/en.json

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

📝 Walkthrough

The change adds content-aware disk-write comparisons, including unchanged-write results and lossless UTF-8 checks. Local, runtime, and web write paths use these comparisons and select guarded writes based on host capabilities. Editor automatic saves pause for non-UTF-8 files, while explicit saves remain available. Restored-tab and external-watch verification now compare disk content without pending-verification autosave flags.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to e9414

Some restored dirty tabs may show an incorrect changed-on-disk warning. The risk is bounded but warrants owner awareness before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 48 functions across 44 files. (1 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 main changes: guarded autosave, identical-write avoidance, and non-UTF-8 autosave refusal. It is somewhat long but remains specific and relevant.
Description check Passed The description follows the required template and explains the user impact, implementation, rationale, linked issue, visual proof, testing, compatibility, and checklist status. Manual testing is not c…
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 follows the required template and explains the user impact, implementation, rationale, linked issue, visual proof, testing, compatibility, and checklist status. Manual testing is not checked, and some full validation commands are not reported as passing, but the description is otherwise substantially complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 48 functions across 44 files. (1 skipped: 1 unsupported.)

Resolution

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

  • 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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f81b8071-7eb0-42cd-abc3-931ae9dd3216
📥 Commits

Reviewing files that changed from the base of the PR and between ec546de and 147e81e.

📒 Files selected for processing: 53
  • src/main/ipc/filesystem/filesystem-write-handlers.ts
  • src/main/ipc/filesystem/filesystem-write-identical.test.ts
  • src/main/ipc/filesystem/local-disk-write-precondition.test.ts
  • src/main/ipc/filesystem/local-disk-write-precondition.ts
  • src/main/runtime/markdown-tab-disk-documents.test.ts
  • src/main/runtime/markdown-tab-disk-host.ts
  • src/main/runtime/orca-runtime-mobile-markdown-tab-routes.test.ts
  • src/main/runtime/rpc/methods/files-write-disk-precondition.test.ts
  • src/renderer/src/components/editor/editor-autosave-conflict-flow.test.ts
  • src/renderer/src/components/editor/editor-autosave-controller-test-fixture.ts
  • src/renderer/src/components/editor/editor-autosave.ts
  • src/renderer/src/components/editor/editor-non-utf8-autosave-pause.ts
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.recheck.test.ts
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.test.ts
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.races.test.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.test.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts
  • src/renderer/src/components/editor/editor-save-guarded-disk-fixture.ts
  • src/renderer/src/components/editor/editor-save-large-paste.test.ts
  • src/renderer/src/components/editor/editor-save-lossless-baseline.test.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/editor-save-rebaseline.ts
  • src/renderer/src/components/editor/editor-save-shared-model-dirty.test.ts
  • src/renderer/src/hooks/editor-external-watch-dirty-resync.test.ts
  • src/renderer/src/hooks/editor-external-watch-disk-verification.ts
  • src/renderer/src/hooks/editor-external-watch-overflow.test.ts
  • src/renderer/src/hooks/editor-external-watch-overflow.ts
  • src/renderer/src/hooks/useEditorExternalWatch-background-trim.test.tsx
  • src/renderer/src/hooks/useEditorExternalWatch-self-move.test.ts
  • src/renderer/src/hooks/useEditorExternalWatch-shared-root.test.tsx
  • src/renderer/src/hooks/useEditorExternalWatch-switch-back.test.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/execute-open-editor-path-move.test.ts
  • src/renderer/src/runtime/runtime-file-write-disk-precondition.test.ts
  • src/renderer/src/runtime/runtime-file-write-disk-precondition.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.test.ts
  • src/renderer/src/store/slices/editor-layout-owner-records.test.ts
  • src/renderer/src/store/slices/editor-read-only-tabs.test.ts
  • src/renderer/src/store/slices/editor-rekey-open-files.test.ts
  • src/renderer/src/store/slices/editor/actions/hydrated-editor-session-state.ts
  • src/renderer/src/store/slices/editor/actions/open-file-mutations.ts
  • src/renderer/src/store/slices/editor/actions/rekey-open-files-action.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts
  • src/renderer/src/store/slices/editor/types/editor-files-slice.ts
  • src/renderer/src/store/slices/editor/types/open-file.ts
  • src/renderer/src/store/slices/restored-editor-owner-reparent.test.ts
  • src/renderer/src/web/web-file-mutation-methods.ts
  • src/renderer/src/web/web-file-write-disk-precondition.test.ts
  • src/shared/file-write-disk-precondition.test.ts
  • src/shared/file-write-disk-precondition.ts
  • src/shared/files-runtime-capabilities.ts
  • src/shared/rpc-contract/files-mutation-params.ts
💤 Files with no reviewable changes: 8
  • src/renderer/src/store/slices/editor-layout-owner-records.test.ts
  • src/renderer/src/store/slices/editor-read-only-tabs.test.ts
  • src/renderer/src/store/slices/editor/types/open-file.ts
  • src/renderer/src/components/editor/editor-save-shared-model-dirty.test.ts
  • src/renderer/src/store/slices/editor/actions/hydrated-editor-session-state.ts
  • src/main/ipc/filesystem/filesystem-write-handlers.ts
  • src/renderer/src/store/slices/editor/types/editor-files-slice.ts
  • src/renderer/src/store/slices/editor/actions/open-file-mutations.ts

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

Comment on lines +184 to +185
if (writeResult.unchanged) {
clearSelfWrite(liveFile.filePath, liveFile.runtimeEnvironmentId)

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 | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Trace stamp replacement, clearing, and watcher classification.
rg -n -C 6 '\b(recordSelfWrite|clearSelfWrite|getRecentSelfWrite|hasRecentSelfWrite)\s*\(' \
  src/renderer/src/components/editor/editor-self-write-registry.ts \
  src/renderer/src/components/editor/editor-save-queue.ts \
  src/renderer/src/hooks

Repository: stablyai/orca

Length of output: 26413


Preserve the self-write stamp for the real save.

If a real save is followed by an unchanged save before the first watcher event arrives, clearSelfWrite removes the stamp for the real save. The watcher then treats the pending event as external because it uses getRecentSelfWrite to identify Orca’s own writes. Keep the stamp for the real write while avoiding a stamp for the unchanged attempt.

Comment on lines +98 to +110
// Why: compare dirty tabs asynchronously; autosave stays free to run its own guarded check.
if (file.isDirty) {
if (!resync) {
continue
}
// Why: a dirty tab is never reloaded; the restored-tab scan shows the changed-on-disk banner if disk moved.
// Mirrors the scan's eligibility so it always resolves the flag.
if (
file.lastKnownDiskSignature &&
file.externalMutation !== 'changed' &&
canAutoSaveOpenFile(file)
) {
requestRestoredTabReverification(file.id)
state.setPendingDiskBaselineVerification(file.id, true)
if (resync) {
scheduleEditorSelfMoveEchoVerification(
{
...target,
connectionId: target.connectionId,
runtimeEnvironmentId: target.runtimeEnvironmentId ?? null
},
[file.id],
false,
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 | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '90,118p' src/renderer/src/hooks/editor-external-watch-overflow.ts
sed -n '225,286p' src/renderer/src/hooks/editor-external-watch-disk-verification.ts
rg -n 'lastKnownDiskSignature|isDirty:' src/renderer/src/store/slices/editor/actions/hydrated-editor-session-state.ts src/renderer/src/store/slices/editor/actions/open-file-mutations.ts

Repository: stablyai/orca

Length of output: 4212


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- hydration ---'
sed -n '70,135p' src/renderer/src/store/slices/editor/actions/hydrated-editor-session-state.ts
printf '%s\n' '--- open-file mutations ---'
sed -n '1,180p' src/renderer/src/store/slices/editor/actions/open-file-mutations.ts
printf '%s\n' '--- verifier/reloadable symbols ---'
rg -n -F --glob '*.ts' -e 'function resolveLiveMoveVerification' -e 'const resolveLiveMoveVerification' -e 'isExternalReloadableEditorTab' -e 'markFileChangedOnDisk' src/renderer/src
printf '%s\n' '--- production dirty and signature references ---'
rg -n -F --glob '*.ts' -e 'isDirty:' -e 'lastKnownDiskSignature' -e 'setLastKnownDiskSignature' src/renderer/src --glob '!**/*.test.*'
printf '%s\n' '--- updateEditorBuffer callers ---'
rg -n -F --glob '*.ts' -e 'updateEditorBuffer(' src/renderer/src --glob '!**/*.test.*'

Repository: stablyai/orca

Length of output: 21133


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- reloadable predicate ---'
sed -n '70,112p' src/renderer/src/components/editor/editor-autosave.ts
printf '%s\n' '--- verifier resolution ---'
sed -n '165,220p' src/renderer/src/hooks/editor-external-watch-disk-verification.ts
printf '%s\n' '--- session serialization ---'
sed -n '120,170p' src/renderer/src/lib/workspace-session.ts
printf '%s\n' '--- save precondition ---'
sed -n '80,155p' src/renderer/src/components/editor/editor-save-disk-precondition.ts
printf '%s\n' '--- open-file creation sites ---'
rg -n -F --glob '*.ts' -e 'openFiles.push' -e 'openFiles:' -e 'createOpenFile' -e 'filePath:' src/renderer/src/store/slices/editor/actions src/renderer/src/components/editor --glob '!**/*.test.*'
printf '%s\n' '--- direct signature setters ---'
rg -n -F --glob '*.ts' -e 'setLastKnownDiskSignature(' src/renderer/src --glob '!**/*.test.*'

Repository: stablyai/orca

Length of output: 34625


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- open-file action and apply ---'
sed -n '1,220p' src/renderer/src/store/slices/editor/actions/open-file-action.ts
sed -n '1,340p' src/renderer/src/store/slices/editor/actions/open-file-apply.ts
printf '%s\n' '--- editor draft state ---'
sed -n '1,120p' src/renderer/src/store/slices/editor/actions/editor-draft-state.ts
printf '%s\n' '--- baseline initialization references ---'
rg -n -F --glob '*.ts' -e 'setEditorDiskBaseline' -e 'lastKnownDiskSignature:' -e 'markFileDirty(' src/renderer/src --glob '!**/*.test.*'
printf '%s\n' '--- resync callers and tests ---'
rg -n -F --glob '*.ts' -e 'reconcileEditorTabsAfterOverflow' -e 'scheduleEditorSelfMoveEchoVerification' src/renderer/src --glob '!**/*.test.*'

Repository: stablyai/orca

Length of output: 26328


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- edit and initial content handling ---'
sed -n '1,90p' src/renderer/src/components/editor/use-editor-content-change-handler.ts
sed -n '1,95p' src/renderer/src/components/editor/editor-clean-tab-disk-baseline.ts
printf '%s\n' '--- persisted file contract ---'
rg -n -F --glob '*.ts' -e 'type PersistedOpenFile' -e 'interface PersistedOpenFile' -e 'lastKnownDiskSignature?:' src/renderer/src
printf '%s\n' '--- overflow and marker ---'
sed -n '75,118p' src/renderer/src/hooks/editor-external-watch-overflow.ts
sed -n '1,55p' src/renderer/src/components/editor/editor-changed-on-disk-mark.ts
printf '%s\n' '--- restored scan guard ---'
sed -n '20,42p' src/renderer/src/components/editor/editor-restored-tab-conflict-scan.ts

Repository: stablyai/orca

Length of output: 10056


Skip resync verification when no disk baseline exists.

During resync, a dirty edit tab without lastKnownDiskSignature reaches scheduleEditorSelfMoveEchoVerification. A successful read that is not a recent self-write cannot match the undefined baseline, so resolveLiveMoveVerification marks the dirty tab as changed on disk. This can show a false conflict banner.

Suggested fix
-      if (resync) {
+      if (resync && file.lastKnownDiskSignature !== undefined) {
         scheduleEditorSelfMoveEchoVerification(

@nwparker
nwparker merged commit 7a912a3 into main Oct 22, 2026
41 checks passed
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