Repository navigation
fix(editor): keep saved untitled notes when their tab closes - #23768
Conversation
Saving cleared the draft and dirty flag, so close-time cleanup took a saved note for an untouched placeholder and deleted it. Fixes stablyai#23688
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughUntitled-file cleanup now checks the last known disk signature and runtime file size before deleting a file. Terminal discard flows use a shared helper that requests autosave quiescence, marks the file clean, clears its draft, and closes it. New tests cover untitled-note save, discard, close, and agent-write cases. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to A concurrent write during untitled-note cleanup can still be lost. Resolve this race or explicitly accept the risk before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change adds protection against deleting saved notes and preserves existing file-ownership controls. No new privilege expansion was identified. Concurrent file writes and exceptional close interruptions remain limitations, so the change should not be treated as eliminating every data-loss scenario. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 94e10849-3faa-4b93-8976-e298a69cf9fe
📒 Files selected for processing (11)
src/renderer/src/components/editor/discard-editor-file-changes.tssrc/renderer/src/components/editor/editor-autosave-controller-test-fixture.tssrc/renderer/src/components/editor/editor-save-queue.tssrc/renderer/src/components/editor/editor-untitled-save-lifecycle.test.tssrc/renderer/src/components/floating-terminal/use-floating-terminal-editor-close-queue.tssrc/renderer/src/components/terminal/useTerminalSaveDialog.tssrc/renderer/src/components/use-terminal-editor-close-dialog-actions.tssrc/renderer/src/store/slices/editor-close-file-cleanup.test.tssrc/renderer/src/store/slices/editor/actions/open-file-mutations.tssrc/renderer/src/store/slices/editor/tabs/untitled-file-cleanup.tssrc/renderer/src/store/slices/editor/types/editor-files-slice.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| // Why: agents, external editors, and paired clients can fill the file without this window's keep flag, so delete only a still-empty placeholder. | ||
| void statRuntimePath(context, file.filePath) | ||
| .then(async (stat) => { | ||
| if (stat.size !== 0) { |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Do not delete a file based only on an earlier size check.
If an agent or external editor writes the placeholder after statRuntimePath reports size zero, Line 26 can delete the new content. The saved-content flag cannot detect that external write. Use a deletion operation that checks the file is still empty at deletion time, or retain the file when that guarantee is unavailable.
There was a problem hiding this comment.
The window between the size check and the delete is real, but it's narrower than before: on main this delete had no check at all, so any write into an untouched untitled note was lost on close. Now it takes a write landing inside one file operation.
Closing the window fully needs a "delete only if still empty" operation on the host that owns the file. files.delete doesn't have one, and adding it spans the main process, the SSH relay and the RPC contract, with version handling for older hosts. Never deleting would bring back the untitled.md clutter #821 removed and fail #23688's Don't Save requirement. Tracking the host-side fix in #23772.
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
gh issue view 23772 --repo stablyai/orca --json number,title,state,body,url --jq '{number,title,state,body,url}'Length of output: 1911
@AmoabaKelvin, thanks for the context. I verified that #23772 is open and covers the remaining race for local, SSH, remote, and older hosts. The size check narrows the race, and retaining every empty note would conflict with the Don’t Save requirement. I’ll leave this finding open as the tracked follow-up, without asking for that trade-off in this PR.
✏️ Learnings added
Learnt from: AmoabaKelvin
Repo: stablyai/orca PR: 23768
File: src/renderer/src/store/slices/editor/tabs/untitled-file-cleanup.ts:23-23
Timestamp: 2026-09-29T03:23:38.403Z
Learning: In `stablyai/orca`, `deleteUntouchedUntitledFile` in `src/renderer/src/store/slices/editor/tabs/untitled-file-cleanup.ts` checks size before deletion. The delete operation does not support deleting only if the file is still empty. A host-side fix must account for the main process, SSH relay, RPC contract, and older hosts; issue #23772 tracks that race. Retaining every empty untitled note would conflict with the Don't Save cleanup requirement.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
You are interacting with an AI system.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Untitled keep-flag recorded on save —
setUntitledFileHasSavedContentmaps a non-empty save todeleteUntouchedOnClose = false, and the save queue calls it after the write lands but before the superseded-generation check, so a save that lost a quiesce race still records what is on disk. - Disk check gates deletion —
deleteUntouchedUntitledFilenowstatRuntimePaths first and deletes only asize === 0placeholder; a stat failure keeps the file, so outside writers can't lose content. - One shared "Don't Save" —
discardEditorFileChangesAndClose(quiesce → clear dirty → clear draft → close) replaces the duplicated logic in the terminal dialog and floating panel, which also fixes never-saved placeholders not being removed. - Tests/fixtures — new
editor-untitled-save-lifecycle.test.ts, a remote size-check case ineditor-close-file-cleanup.test.ts, and an in-memoryFakeEditorDiskfixture.
I verified the three touched/adjacent test files (31 tests) and the full components/editor + components/floating-terminal directories (1968 passed, 3 skipped) with vitest run --config config/vitest.config.ts. The new assertions pin real behavior: isReopenable needs the save flag, and the remote case needs the stat gate.
ℹ️ Known stat → delete race, and old-host degradation
The author documents a residual TOCTOU window between the size check and the delete; it is strictly narrower than the previous unconditional delete and a real fix needs a host-side delete-if-unchanged with a version gate. Separately, on a remote host without files.stat the cleanup degrades to leaving an empty placeholder — files.stat is already used by runtimePathExists, so this is theoretical. Both are acceptable as-is; noting only so they're carried forward.
Technical details
# Untitled cleanup: residual race and compatibility
## Affected sites
- `src/renderer/src/store/slices/editor/tabs/untitled-file-cleanup.ts` — `statRuntimePath` then
`deleteRuntimeRelativePath`/`deleteRuntimePath` is not atomic.
## Required outcome
- Out-of-scope here; follow-up needs a host-side delete-if-unchanged operation.
- No action required from this PR.
## Open questions for the human
- Is the follow-up (version-gated delete-if-unchanged) tracked, or should it be filed?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Reviewing now! Thanks for the PR! |
…save flag Drop setUntitledFileHasSavedContent and its save-queue hook so deleteUntouchedOnClose keeps its creation-time template meaning. A clean untitled tab now counts as an empty placeholder only while its last-known disk content is empty or not yet loaded; the on-disk size check still gates every actual delete. Notes an agent filled while their tab was showing now stay reopenable with Cmd+Shift+T. Also test both Don't Save dialogs end to end, mirror the shared discard in the floating panel test mock, and remove markFileDirty selectors left without consumers.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (1fceb8d113): a mechanism swap that drops the purpose-built per-save flag in favour of state the editor already keeps.
- Keep decision now reads the disk baseline —
shouldDeleteUntouchedUntitledFileaddslastKnownDiskSignature === undefined || === EMPTY_DISK_SIGNATURE, so a save or reload that left content on disk keeps the note. The oldsetUntitledFileHasSavedContentaction, its slice type, and thedeleteUntouchedOnClose = falsewrite in the save queue were removed;deleteUntouchedOnCloseis now only set at creation for templated notes. - Stat gate still owns the backstop —
deleteUntouchedUntitledFilecontinues tostatRuntimePathand delete only asize === 0placeholder, so writes this window never saw (agents, external editors, paired clients, remote hosts) are covered. - One discard path, less plumbing —
discardEditorFileChangesAndCloseis now the sole "Don't Save" implementation;closeFile/markFileDirtywere dropped fromuseTerminalSaveDialog,useTerminalEditorCloseDialogActions,useFloatingTerminalPanelStoreState, anduseFloatingTerminalEditorCloseQueue. - Tests — new
editor-untitled-dont-save-dialogs.test.tsxpins placeholder removal for both the main window and floating panel; the save-lifecycle suite adds loaded-empty-signature and background-agent-write cases; the remote cleanup test pins the stat gate.
I traced the new predicate as strictly more conservative than the previous one (the signature clause is an added &&, deleteUntouchedOnClose !== false is retained), and the only case where the removed flag kept a note that the new check would not (a save superseded by a quiesce, so setLastKnownDiskSignature never runs) is covered by the disk stat, which sees the landed write. Verified: the three touched tests, the full components/editor + components/floating-terminal suites (1974 passed, 3 skipped), and pnpm run typecheck:web.
ℹ️ Notes kept only by the disk stat are not added to the reopen stack
When a note survives solely because the stat found content — a background tab an agent wrote into, or a paired-host write this window never reloaded — it is not pushed onto recentlyClosedEditorTabsByWorktree, because that decision shares the pre-stat predicate with the delete decision. The new test asserts this (isReopenable === false in the background case), so it is intentional, but it is narrower than the PR body's "a note with content on disk is kept, and it can be reopened with Cmd+Shift+T." The file is still on disk and reachable from the explorer, so this is a UX gap rather than data loss. Worth a look if that promise is meant to hold for outside writers too.
Technical details
# Kept-but-not-reopenable notes
## Affected sites
- `src/renderer/src/components/editor/editor-untitled-save-lifecycle.test.ts:158-176` — asserts `isReopenable === false` for the background agent-write case.
- `src/renderer/src/store/slices/editor/actions/close-file-action.ts:22,136-141` — `shouldDeleteFromDisk` (pre-stat) gates the reopen-stack push.
- `src/renderer/src/store/slices/editor/actions/recently-closed-editor-tabs.ts:149-154` — same predicate in `closeAllFiles`.
## Required outcome
- Decide whether a note that only the stat keeps should also be reopenable; if not, the PR body's reopen claim should be scoped.
## Open questions for the human
- Is the reopen-stack gap for outside-writer notes a known limitation, or should the keep evidence be shared with the reopen decision?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Drain the stat-then-delete chain before the untitled-note tests assert the file survived, so the in-flight Don't Save case fails if the size check is removed. Type the main-window close dialog hook by the controller fields it reads, which lets its test drop a type assertion.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (491d6070a4): a test-hardening and typing follow-up with no production behavior change.
- Tests drain the stat → delete chain before asserting —
await vi.advanceTimersByTimeAsync(0)was added after save-and-close and after the in-flight Don't Save discard, so a note the size check failed to protect turns the test red instead of passing while the delete is still in flight. - Close-dialog hook typed by the fields it reads — the exported
TerminalEditorCloseDialogActionsInput(Pick<TerminalEditorCloseQueueController, …>over the ten fields the hook reads) replaces the full-controller parameter, letting the main-window dialog test drop itsas unknown asassertion.
I verified the hardening actually bites: temporarily removing the stat.size !== 0 guard in untitled-file-cleanup.ts fails the in-flight Don't Save case and the background-agent-write case. The three touched test files pass (30 tests) and pnpm run typecheck:web is clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Review status: ready for maintainer reviewThe problem (#23688). New Markdown writes an empty What changes for users. A note with anything on disk is never deleted when its tab closes, whoever wrote it. Save in the prompt and autosave-then-close keep the note, and Cmd/Ctrl+Shift+T reopens it. Don't Save on a never-saved note removes the empty file. Closing an untouched new note still removes the placeholder. What the review changed (commits 491d607 and 2d81784, plus a conflict-free merge of main, dadfa2a):
Deferred (no text is lost in any of these):
Not caused by this PR (seen during QA, same on main): Save in the close prompt writes Verified:
Not verified live: SSH or remote workspaces, Linux, Windows, the floating-panel Don't Save dialog, and Close All/Others. These are covered only by unit tests. Save in the prompt, before (main): the note is gone from the explorer after closing Save in the prompt, after (this branch): the prompt, then the note reopened with its text Don't Save on a never-saved note: before leaves an empty untitled.md, after leaves nothing Autosave then close: before deletes the note, after keeps and reopens it |









ELI5
If you made a new untitled note, typed in it, closed the tab and chose Save in the unsaved-changes prompt, Orca deleted the note and your text was gone. Choosing Don't Save did the opposite and left an empty
untitled.mdbehind. Now a note with anything written to disk is always kept, and Don't Save on a note that was never saved removes the empty file.What Changed
The problem. New Markdown writes an empty
untitled.mdto disk right away so the tab has a real file. When the tab closes, Orca deletes that file if the note looks untouched. "Untouched" meant "no unsaved edits", but that is also true right after a save, so a note you had just saved was deleted along with your text.Who lost text, before this PR:
The opposite case: Don't Save on a never-saved note left an empty
untitled.mdin the folder.After: a note with content on disk is never deleted when its tab closes, whoever wrote the content. Don't Save on a note that was never saved removes the empty file, just like closing an untouched note already did. A note you saved, or one an agent filled while its tab was showing, can be reopened with Cmd/Ctrl+Shift+T.
How it works now:
Known limits (no text is lost in any of them):
Why
The bug was in the untitled-note cleanup, not in one close button, so fixing only the Save button would have left autosave, agents and paired clients still losing notes. The decision now comes from the file itself (its size on the owning machine) and from the disk state the editor already tracks, rather than from a new "this note was saved" flag that every save path would have to remember to set and that could never see writes from agents or other clients.
Linked Issue
Fixes #23688
Visual Proof
Scenario: New Markdown → type text → close the tab → choose Save.
Before:
CleanShot.2026-09-29.at.02.56.44.mp4
After:
CleanShot.2026-09-29.at.02.59.48.mp4
The other paths (floating panel, autosave, outside writers, close-all, Don't Save) are covered by the automated tests listed below.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Manual (macOS): New Markdown, type, close, Save: the note stays in the file explorer and reopens with its text. Two-arm Electron QA (main vs this branch) is posted in a PR comment.
Automated:
editor-untitled-save-lifecycle.test.tsruns the real store, autosave controller, save queue and close path against an in-memory disk: Save in the prompt, autosave then close, an untouched note (before and after its content loads), Don't Save on a never-saved note, Don't Save while an autosave write is in flight, and an agent writing into a showing or a background note.editor-untitled-dont-save-dialogs.test.tsxruns the real main-window and floating-panel Don't Save handlers and checks the empty file is removed.editor-close-file-cleanup.test.tsadds a remote/SSH case: an untouched note that something else wrote into is kept.Not tested manually: a live SSH host, Linux, Windows. There is no platform-specific code.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
files.stat, which every host that can create a note already answers (New Markdown uses it).Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)