Skip to content

fix(editor): keep saved untitled notes when their tab closes - #23768

Merged
brennanb2025 merged 4 commits into
stablyai:mainfrom
AmoabaKelvin:fix/keep-saved-untitled-notes
Sep 30, 2026
Merged

brennanb2025 merged 4 commits into
stablyai:mainfrom
AmoabaKelvin:fix/keep-saved-untitled-notes

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​190 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​189
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129 $\color{#cf222e}{\Huge{\mathbf{−}}}$​55 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​74

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.md behind. 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.md to 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:

  • Save in the unsaved-changes prompt (the case in Choosing Save in the unsaved-changes prompt deletes a new untitled note #23688), in the main window and the floating panel.
  • Autosave users, silently. With autosave on, the note was already saved, so closing the tab showed no prompt and deleted it.
  • Notes an agent or external editor wrote into. If you never typed in the note but an agent filled it, closing the tab deleted what the agent wrote.
  • Notes written from another client paired with the same Orca host. When that client closed the tab, the host ran its own cleanup and deleted the note.
  • Close All and Close Others close tabs one at a time through the same cleanup, so they had the same problem.

The opposite case: Don't Save on a never-saved note left an empty untitled.md in 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:

  • Before deleting, Orca checks the file's size on the machine that owns it (local, WSL, SSH, or a paired Orca host) and deletes only an empty file. If the check fails for any reason, the file is kept. This check is the real fix: it covers every writer, including agents and other clients this window never sees.
  • The editor decides whether a closing tab is a placeholder from what it last saw on disk. The editor already records a signature of the file's disk content whenever it loads or saves the file. A tab whose recorded disk content is non-empty is a real note: it goes on the reopen list and no delete is attempted. No new state was added.
  • Don't Save throws away the unsaved text before closing, so a never-saved note is recognized as the placeholder it is. The main window and the floating panel now share one Don't Save function, so they can't drift apart again.

Known limits (no text is lost in any of them):

  • A note kept by the size check but whose tab never saw the content does not go on the Cmd/Ctrl+Shift+T list. This happens when an agent writes into a note whose tab is in the background, when you click Don't Save while an autosave write is still in flight, or when an agent writes into a note with unsaved edits and you then choose Don't Save. The file stays on disk and shows in the file explorer.
  • There is a small window between the size check and the delete in which an outside write could land. Before this change the delete had no check at all, so this only narrows it. Closing it fully needs a delete-if-unchanged operation on the host, which doesn't exist yet and would need a version check for older hosts, so it's left for a follow-up.
  • The paired-client case is fixed once the host runs this version, because the host is the one that deletes.

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.ts runs 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.tsx runs the real main-window and floating-panel Don't Save handlers and checks the empty file is removed.
    • editor-close-file-cleanup.test.ts adds a remote/SSH case: an untouched note that something else wrote into is kept.
    • Removing each part of the fix (the size check, the disk-state check, the draft clear in Don't Save, either dialog's wiring) turns its tests red. Reverting the whole fix fails the exact Choosing Save in the unsaved-changes prompt deletes a new untitled note #23688 scenario.
  • Not tested manually: a live SSH host, Linux, Windows. There is no platform-specific code.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Remote SSH / paired hosts: the size check and the delete both run through the existing file client on the machine that owns the file. The size check uses files.stat, which every host that can create a note already answers (New Markdown uses it).
  • Backwards compatibility: no new setting, no saved-session change and nothing new sent between clients and hosts. The untitled-note markers are not saved across restarts.
  • Mobile: mobile can't edit an untitled note, but closing one from the phone runs the same host cleanup, so it gets the same protection.
  • Performance: one extra size check when an untouched untitled tab closes, after the tab is gone. Nothing changes for other files or on save.

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)

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
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Refactors how unsaved untitled notes are discarded when tabs close.

The PR appears safe to merge based on the reviewed changes.

Summary

The PR protects saved untitled notes from close-time placeholder cleanup and makes “Don’t Save” remove a never-saved placeholder. The changes since the previous review narrow a hook’s input type and adjust lifecycle-test timing.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Close untitled tab] --> B{Unsaved changes?}
  B -->|Don't Save| C[Quiesce saves and clear draft]
  B -->|No| D[Evaluate placeholder cleanup]
  C --> D
  D --> E{File still empty on owning host?}
  E -->|Yes| F[Delete placeholder]
  E -->|No| G[Keep note]
Loading

Reviews (3) · Last reviewed commit: "test(editor): wait for untitled cleanup ..."

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 03df77eb-1158-4d5d-b896-ab5c2d0ec3c4

📥 Commits

Reviewing files that changed from the base of the PR and between 491d607 and 2d81784.

📒 Files selected for processing (3)
  • src/renderer/src/components/editor/editor-untitled-dont-save-dialogs.test.tsx
  • src/renderer/src/components/editor/editor-untitled-save-lifecycle.test.ts
  • src/renderer/src/components/use-terminal-editor-close-dialog-actions.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.


📝 Walkthrough

Walkthrough

Untitled-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 2d817

A concurrent write during untitled-note cleanup can still be lost. Resolve this race or explicitly accept the risk before merging.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 2d817

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected destructive path concerns an eligible open untitled file in its owning worktree and runtime. Both UI surfaces share this path; the reviewed changes do not demonstrate broader filesystem authority or a new authentication boundary.

Trust Boundaries and Controls

  • observed — Failure to establish the file owner stops cleanup. A runtime-owned file does not receive the cleanup helper’s absolute-path fallback, and filesystem clients enforce routing checks before local access. These controls predate the PR and remain in the new stat-and-delete sequence.

Resilience and Maintainability Implications

  • inferred — A claimed quiesce request has no rejection or timeout completion channel. An exceptional listener failure before resolution can therefore strand the close guard and queue. Ordinary pending-write rejection is swallowed by the save barrier; the exceptional incomplete transition already existed before this refactor.

Hardening Proposals

  • proposed — Consider an owner-side conditional deletion operation that atomically verifies file identity and emptiness before removal. The current separate stat and delete calls cannot guarantee preservation of a concurrent write occurring between them; this is a hardening proposal, not a verified introduced vulnerability.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR meets the coding requirements in [#23688]. The save-and-close path preserves typed untitled content on disk, and the lifecycle test verifies that the file remains reopenable. `discardEditorFile…
Out of Scope Changes check ✅ Passed The changes stay within [#23688]. The discard helper, runtime size check, save lifecycle handling, floating-panel routing, test fixtures, and regression tests support untitled-note save, discard, or c…
Title check ✅ Passed The title clearly and concisely describes the main change: preserving saved untitled notes when their tabs close.
Description check ✅ Passed The description is complete and closely follows the repository template. It explains the user impact, implementation, rationale, linked issue, visual proof, testing, limitations, compatibility conside…
  • Fix all pre-merge checks with AI

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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 94e10849-3faa-4b93-8976-e298a69cf9fe

📥 Commits

Reviewing files that changed from the base of the PR and between a134d12 and 1fceb8d.

📒 Files selected for processing (11)
  • src/renderer/src/components/editor/discard-editor-file-changes.ts
  • src/renderer/src/components/editor/editor-autosave-controller-test-fixture.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/editor-untitled-save-lifecycle.test.ts
  • src/renderer/src/components/floating-terminal/use-floating-terminal-editor-close-queue.ts
  • src/renderer/src/components/terminal/useTerminalSaveDialog.ts
  • src/renderer/src/components/use-terminal-editor-close-dialog-actions.ts
  • src/renderer/src/store/slices/editor-close-file-cleanup.test.ts
  • src/renderer/src/store/slices/editor/actions/open-file-mutations.ts
  • src/renderer/src/store/slices/editor/tabs/untitled-file-cleanup.ts
  • src/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) {

@coderabbitai coderabbitai Bot Sep 29, 2026 •

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 | 🏗️ 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

🧩 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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Untitled keep-flag recorded on save — setUntitledFileHasSavedContent maps a non-empty save to deleteUntouchedOnClose = 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 — deleteUntouchedUntitledFile now statRuntimePaths first and deletes only a size === 0 placeholder; 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 in editor-close-file-cleanup.test.ts, and an in-memory FakeEditorDisk fixture.

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?

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor

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.

@pullfrog pullfrog 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.

✅ 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 — shouldDeleteUntouchedUntitledFile adds lastKnownDiskSignature === undefined || === EMPTY_DISK_SIGNATURE, so a save or reload that left content on disk keeps the note. The old setUntitledFileHasSavedContent action, its slice type, and the deleteUntouchedOnClose = false write in the save queue were removed; deleteUntouchedOnClose is now only set at creation for templated notes.
  • Stat gate still owns the backstop — deleteUntouchedUntitledFile continues to statRuntimePath and delete only a size === 0 placeholder, so writes this window never saw (agents, external editors, paired clients, remote hosts) are covered.
  • One discard path, less plumbing — discardEditorFileChangesAndClose is now the sole "Don't Save" implementation; closeFile/markFileDirty were dropped from useTerminalSaveDialog, useTerminalEditorCloseDialogActions, useFloatingTerminalPanelStoreState, and useFloatingTerminalEditorCloseQueue.
  • Tests — new editor-untitled-dont-save-dialogs.test.tsx pins 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?

Pullfrog  | View workflow run | Using 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.

@pullfrog pullfrog 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.

✅ 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 its as unknown as assertion.

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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor

Review status: ready for maintainer review

The problem (#23688). New Markdown writes an empty untitled.md to disk so the tab has a real file, and closing the tab deletes that file if the note "looks untouched". "Untouched" meant "no unsaved edits", which is also true right after a save. So choosing Save in the unsaved-changes prompt deleted the note and the text was lost. The same thing happened silently to autosave users, and to notes an agent or another paired client had written into. Don't Save did the opposite and left an empty untitled.md behind.

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

  • Removed the per-save "this note has content" flag the PR added. The on-disk size check (delete only a 0-byte file, checked on the machine that owns it: local, WSL, SSH or a paired host) is what actually fixes every writer. The flag was a second copy of that fact that agents and other clients could never set.
  • The instant decision at close (is this tab a placeholder, should it go on the Cmd/Ctrl+Shift+T list) now comes from the disk-content signature the editor already records on every load and save. No new state.
  • Added tests that run the real main-window and floating-panel Don't Save handlers. Before, removing either dialog's wiring left every test green.
  • Fixed a test that checked the disk before the cleanup had run, so it now fails if the size check is removed.
  • Removed two store selectors the PR left unused, and a type assertion in a test.
  • Rewrote the PR body: some claims were inaccurate (the flag was never sent to other clients; the floating-panel Save and Close All are not separate code paths), and the known limits are now stated.

Deferred (no text is lost in any of these):

  • A note kept by the size check whose tab never saw the content stays on disk and in the file explorer, but is not on the Cmd/Ctrl+Shift+T list. This covers an agent writing into a background untitled tab, Don't Save while an autosave write is in flight, and an outside write into a note with unsaved edits followed by Don't Save.
  • There is still a small window between the size check and the delete (previously there was no check at all). Closing it needs a host-side delete-if-unchanged call with version negotiation for older hosts; that's a follow-up.
  • On a remote workspace whose folder path the client can't resolve, the size check fails and an empty placeholder can be left behind. No one has shown this state is reachable, and saving already fails there.
  • A paired client's close is protected only once the host runs this version, because the host performs the delete.

Not caused by this PR (seen during QA, same on main): Save in the close prompt writes untitled.md to the workspace root without asking, while Cmd+S on the same note opens a Save As dialog that asks for a name and folder.

Verified:

  • Code review: 2 rounds (3 parallel reviewers, then a fresh reviewer on the redesign) plus a final readiness pass. No P0–P2 issues remain.
  • Automated: 27 test files / 309 tests pass. Removing each part of the fix turns its tests red, and reverting the whole fix fails the exact Choosing Save in the unsaved-changes prompt deletes a new untitled note #23688 scenario. Web typecheck and lint pass. CI on 2d81784: 19 passed, 14 skipped, 0 failed.
  • Live Electron QA on a separate macOS machine (arm64), comparing main (9f43115) with this branch (491d607; the later commit only changes tests and a parameter type). Disk state was checked with ls/cat after each close. Results:
    • Save in the prompt: main deletes the note; this branch keeps it and Cmd+Shift+T reopens it with its text.
    • Don't Save on a never-saved note: main leaves an empty untitled.md; this branch leaves nothing.
    • Autosave on, type, close: main deletes the autosaved note; this branch keeps it.
    • Close an untouched note: the placeholder is removed on both.
    • Don't Save after an autosave on this branch: the saved content is kept.

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
before: explorer after Save + close lists README.md only

Save in the prompt, after (this branch): the prompt, then the note reopened with its text
after: Unsaved Changes prompt over the note
after: note reopened with Cmd+Shift+T shows its text

Don't Save on a never-saved note: before leaves an empty untitled.md, after leaves nothing
before: explorer still lists the empty untitled.md
after: explorer lists README.md only

Autosave then close: before deletes the note, after keeps and reopens it
before: explorer after closing the autosaved note lists README.md only
after: explorer lists untitled.md
after: autosaved note reopened with its text

@brennanb2025
brennanb2025 merged commit 8b01590 into stablyai:main Sep 30, 2026
33 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.

Choosing Save in the unsaved-changes prompt deletes a new untitled note

2 participants