Skip to content

A chat's visuals and sent images live as long as the chat - #30413

Merged
brennanb2025 merged 12 commits into
mainfrom
brennanb2025/chat-files-live-with-chat
Oct 19, 2026
Merged

brennanb2025 merged 12 commits into
mainfrom
brennanb2025/chat-files-live-with-chat

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​361 $\color{#cf222e}{\Huge{\mathbf{−}}}$​322 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39
Prod 38 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​466 $\color{#cf222e}{\Huge{\mathbf{−}}}$​419 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47

ELI5

When you open a native chat you haven't used for a month, its charts and diagrams show "Visualization unavailable", and in a local chat the images you pasted and sent show as a grey label instead of the picture. The chat and its history are still there; only its files were deleted, by two 30-day timers. This PR keeps a chat's own files for as long as the chat exists, which is the common pattern. Only files no chat owns are still cleaned up: pastes that were never sent, and leftovers whose chat is gone.

What Changed

Before

  • Each chat's visuals folder (<state>/chat-scratch/<hash>) was deleted once the chat had gone 30 days without a new message or file change. Old chats then showed "Visualization unavailable".
  • A local chat's pasted images lived in one folder (<userData>/native-chat-pastes) that deleted every image older than 30 days at startup, including images already sent and still shown in the transcript.

After

  • Visuals: a chat's visuals folder is kept as long as the chat. The cleanup removes only folders that no chat record maps to (unchanged). A folder that an older build had set aside for deletion (<hash>.expired) is put back for its chat.
  • Pasted images in local chats: a structured chat's paste goes into this machine's chat attachment store, the same store paired-server chats already use. When you send the message, the host records that this chat holds the file, in the same database write that saves the message. A file a chat holds is never swept; only unsent pastes are.
  • Unsent pastes: the store now keeps an unsent paste for 30 days instead of 1 day, on every host. 30 days is what a local draft's image had before, so an unsent draft keeps its image as long as it used to. Paired-server drafts now keep theirs as long too. When the cleanup does remove an unsent draft's image, the draft shows it as "Not kept" with Send disabled, as local drafts did before. This holds even if the draft is open when the cleanup runs: the host tells the window about each upload it removes, and drafts that name it check it again.
  • Terminal-backed chats and the old paste folder: a chat that runs in a terminal has no saved message log, so nothing can tell its sent pastes from unsent ones. Its pastes stay in the old paste folder, which is no longer cleaned up at all. That folder also holds every paste from before this change, which sent messages may still point at. Restored drafts read from it as before.
  • Agent instructions: the skill Orca gives agents for drawing visuals no longer says the folder is temporary and may be removed after 30 days.

What the mechanism is now

  • Ownership decides deletion, never age.
  • A visuals folder belongs to its chat record.
  • A pasted file belongs to every chat whose sent message names it. The send's own database write records this, so a send and the cleanup can never both win.
  • Removing the age rule also removes everything that existed only to make it safe:
    • the per-folder lock every scratch-folder save took;
    • the session-lane idle check;
    • the "last journal activity" query;
    • the migration's fresh-timestamp step;
    • the paste-folder timer.

Hosts

  • Local: both changes apply.
  • WSL, SSH and paired servers: their structured chats already paste into their own host's store, so they only gain the visuals change and the 30-day unsent window. Each host sweeps its own folders.
  • Mixed client and server versions: nothing on the wire changes. An older server keeps its 1-day unsent window until it updates.

Why

  • The common pattern. A chat's files are deleted when the chat is deleted, and on a timer only if the user opts into a retention policy. Uploads that were never sent and half-written files are the only things cleaned up on age. Brennan's ruling for this lane was "do what they do".
  • Reusing the store. Orca already had this mechanism for paired-server chats: an attachment store whose files are claimed by the send. Local chats were the only path that bypassed it. Pointing local pastes at the same store keeps one rule on every host, and adds no new saved data and no new kind of claim.
  • Alternatives considered:
    • Keep the paste folder and skip files a saved message names. Rejected: the check would scan the whole chat journal on every sweep (9 GB on one real install), and it would add a second ownership mechanism beside the store's.
    • Copy each paste into the chat's own folder when it is sent. Rejected: that rewrites paths inside the message, which breaks how a sent message is matched to its on-screen copy.
  • Differences from the common pattern:
    • intended: ownership is a row in the store's existing claim table, not a copy into a chat-named file. One upload can then be held by two chats (after a /clear), without a duplicate.
    • intended: the common pattern keeps a draft's image bytes in the draft itself, so a draft image never expires. Orca's draft stores a path, so the store's 30-day unsent window bounds a draft's image. A local draft older than that shows its image as "Not kept" with Send disabled, as before. A paired-server draft still meets it as a refused send ("This attachment expired."), as it already does.
    • intended: the paste folder for terminal-backed chats (and pastes from before this change) is never cleaned up, because which of its files a sent message needs can't be told. Its growth is noted for Brennan rather than capped.
    • intended: Orca has no "delete chat" action today, so a chat's files now stay as long as the chat record, which is forever.

Linked Issue

N/A (maintainer PR; Brennan asked for it directly).

Visual Proof

Real Electron app, files aged 31 days on disk, then the app restarted.

Before (main): the sent image is a grey label and the chart says "Visualization unavailable".
main after 31 days: grey image label and Visualization unavailable

After (this PR): the same kind of chat keeps its sent image and its chart.
PR after 31 days: sent image and chart still render

Unsent draft whose image the cleanup removes while the chat is open: before the cleanup it still shows the picture; after it, without touching the chat, it shows "Not kept" and Send is disabled.
open draft before cleanup: image shown
same open draft after cleanup: Not kept, Send disabled

A chart whose folder an older build had set aside for deletion comes back when the chat opens.
chart restored from the set-aside folder

Re-checked on the final head (after a small cleanup fix to the window's listener): the open old draft turns "Not kept" with Send disabled when the cleanup runs, the 31-day-old sent image still shows, and a page reload keeps it that way.
final head: open old draft before cleanup
final head: same draft after cleanup, Not kept, Send disabled
final head: 31-day-old sent image still renders
final head: Not kept persists after a reload

Testing

  • Named test files run locally (10 files, 103 tests):

    • the visuals sweep: a long-idle held chat keeps its folder, a set-aside folder is put back, an orphan is removed;
    • the folder migration;
    • the attachment-store sweep: a paste stored in place and claimed by a send survives past the unsent window, and the unsent one goes;
    • the clipboard save: a local composer paste lands in the store;
    • the paste-folder restore.
    • the composer: a draft image that passed its restore check turns "Not kept" when a later cleanup removes its upload, whether or not the chat is on screen; the cleanup reports each removal.
  • Lint and typecheck are left to CI.

  • Real Electron QA (agent-driven through the app's debugging port, real signed-in Codex, isolated test profiles), with files aged 31 days on disk:

    • main against the PR on one Mac: main loses the sent image and the chart; the PR keeps both, with the sent image's ownership record in place. A visuals folder with no chat is removed on both.
    • that run found that an unsent draft's image removed by the cleanup a minute after launch showed no "Not kept" warning on the PR. Fixed in this PR (the host now tells the window about each removal), then a second run on another Mac passed: open and reopened old drafts show "Not kept" with Send disabled, a 2-day-old draft keeps its image, and a set-aside visuals folder is restored.
    • a third short run on the final head passed the same open-draft and sent-image checks, plus a page reload. A Windows attempt in between could not finish: in its isolated test profile Codex's own hooks failed and replaced the agent's reply, which this PR does not touch.
    • not exercised in the app: paired servers, SSH, mixed client and server versions, terminal-backed chats. Those paths are covered by the named tests above.
  • I manually tested these changes locally

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

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

  • Cross-platform: store paths use path.join and the store's existing Windows rename retry. The claim matcher already handles Windows case and separators.
  • SSH and remote: covered above.
  • Mobile: unchanged. The phone shows a placeholder for any bare host image path, before and after.
  • Performance: the paste path writes one file, as before. Removing the age rule removes a recursive folder scan and a journal query per chat per sweep.

Author: @BrennanKB5

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)

A chat's scratch folder was deleted once the chat had gone 30 days
unused, so an old chat's inline visuals turned into "Visualization
unavailable" while the chat and its history stayed. The common pattern
keeps a chat's files for as long as the chat and never deletes them on
an "unused for N days" timer.

The sweep now removes only folders no chat record maps to, plus
leftover .expired folders older builds parked. Everything that existed
only to make the age rule safe goes with it: the per-folder save lock
and its expiry candidates, the session-lane idle check, the journal
last-activity query, and the migration's fresh-window timestamp. The
visuals skill no longer tells agents the folder is temporary.
…chat

A local chat's pasted images lived in one paste folder that deleted
every file older than 30 days, sent or not, so an old chat's images
turned into label chips. Paired-server chats already keep pastes in the
host's attachment store, where the send that names a file claims it for
its chat and only unclaimed files are ever swept: the common pattern.

A local composer paste now goes into this machine's own attachment
store (starting the local chat host first), so its send claims it the
same way. The old paste folder is no longer written or swept: messages
sent before this change may name its files. Restored drafts still read
it.

An unclaimed upload now waits 30 days instead of one before the sweep
takes it. A draft names its image by this path, so the window is how
long an unsent draft keeps its image; 30 days is what local drafts had,
and it outlasts the host's send-id window so a resent draft still finds
its image.

A chat folder an older build set aside as unused (<hash>.expired) goes
back to its chat instead of being deleted.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 18, 2026 20:35
A terminal-backed chat has no journal, so no send claims its pastes and
nothing can tell a sent one from an abandoned one. Its pastes therefore
stay in the paste folder, which is no longer swept, rather than in the
attachment store, whose sweep would take them after 30 days unclaimed.
Only a local structured chat's paste (forStructuredChat) goes to the
store, where its send claims it.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Native-chat visuals sweeping now retains folders mapped to held chats and removes folders without held records. Age-based expiry, journal-activity checks, execution-idle checks, and per-folder scratch-save locking are removed. Local structured-chat clipboard images can be stored in the host attachment store. Unclaimed attachments use a 30-day retention threshold, and the legacy native-chat paste expiration sweep is removed. Restored drafts now check local attachment images when the draft owner is local.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to b47b7

A retained selector can cause a file write to fail if its chat folder is swept after the chat is gone. This is a narrow stale-target issue; validate selectors before accepting writes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 39 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly summarizes the primary change: chat visuals and sent images are retained for the lifetime of the chat.
Description check Passed The pull request description is complete and closely follows the repository template. It explains the user impact, changes, rationale, alternatives, linked-issue exception, visual proof, testing, plat…
Full details: Description check

Explanation

The pull request description is complete and closely follows the repository template. It explains the user impact, changes, rationale, alternatives, linked-issue exception, visual proof, testing, platform considerations, and checklist. The manual-testing checkbox and several CI checks remain unchecked, but the description documents the manual Electron QA and states that lint and typecheck are left to CI. The blank Review and AI Disclosure sections are non-critical for this maintainer PR.

  • Fix all pre-merge checks with AI
✨ 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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Reject stale scratch selectors before file mutations. · native-chat-visuals-sweep.ts:79-83

src/main/native-chat/native-chat-visuals-sweep.ts:79-83
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Reject stale scratch selectors before file mutations.

A stale path:<scratch-folder> selector can pass resolveChatScratchSelectorFolder after its chat row is gone. The sweep can then remove the folder before files.write reaches the provider. Since the local provider does not recreate the parent directory, the write can fail.

The sweep should keep removing unheld folders. Validate that the scratch selector still maps to a held chat before accepting the mutation target.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b6146e64-021a-49d9-bf3f-7d0db1eec0c4
📥 Commits

Reviewing files that changed from the base of the PR and between 2c05c8f and b47b772.

📒 Files selected for processing: 2
  • src/renderer/src/components/tab-bar/TabSessionSurfaceSwitchMenuItems.test.tsx
  • src/shared/agent-session-attachments.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/shared/agent-session-attachments.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.

A draft checks its pasted images once, when its composer comes back. Every
chat in an open workspace mounts its composer at launch, so that check ran
before the store sweep (60 s after host start, then every 6 h) deleted an
expired unsent upload, and nothing checked again: the chip lost its picture
with no Not kept feedback and Send stayed enabled.

The sweep now reports each removal attempt; the main process forwards it to
its window, and the draft store starts a fresh finite check for every loaded
local draft image in that folder, mounted or not. A notice is a reason to
check, never proof of absence.
…es-live-with-chat

# Conflicts:
#	src/main/ipc/filesystem/filesystem-write-handlers.ts
#	src/main/runtime/files/file-mutations.ts
startNativeChatDraftLoad dropped the unsubscribe for the upload-removal
listener, so each recovery through the root error boundary's Retry remounted
App and added another listener. Return it so the effect's cleanup removes it.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

An old chat could retain its messages while cleanup deleted the sent pasted images and inline charts those messages needed. Files now stay while their chat owns them. Cleanup still removes known abandoned uploads and folders whose chat is gone; uncertain filesystem reads preserve files and ownership.

The full loop completed three source rounds and resumed round 4 on the final correction and main-merge resolutions. Review fixes preserve claims after failed reads, recover folders set aside by older cleanup before first use, and give each restored image its own finite check. Real Electron QA found an expired unsent image could disappear after its startup check while Send remained enabled. Host removal notices now trigger a fresh check, including drafts not on screen, so the image shows Not kept and Send is disabled. Readiness also caught a listener retained after an app Retry; the final cleanup returns its unsubscribe to the app mount effect, and independent narrow review verified it.

No confirmed finding remains open. Deferred: ownership-selector cost in unusually large workspaces has not been measured; no failing input or observed slowdown was established. The final correction adds no setting, saved field, remote operation, or retention policy.

Verified through 67fd28b9cf79a3597bce9de5c70327fab69dc628: independent renderer and host/merge reviews, all seven readiness areas, and the narrow listener-cleanup recheck. The full PR workflow and aggregate gate passed on attempt 2; headless server checks passed. All applicable checks are green, the PR is out of draft with a clean merge state, and the complete review-thread query returned no threads. Both merge resolutions retain the current disk-write preconditions while removing the obsolete scratch-folder lock.

Real Electron QA used admitted machines, isolated profiles, and real Codex. The earlier main comparison reproduced lost sent images/charts. The 172e593 run passed normal paste/send, owned image/chart retention after 31-day aging, active and reopened expired-draft feedback, a young draft preview, and parked-folder recovery. A short run on the final 67fd28b head passed paste/send, active-draft expiry, sent-image retention, and persistence after renderer reload. Its configuration hashes matched and recorded QA processes exited. Main and chart recovery were not repeated in that final short run.

Limits: the earlier shared-machine comparison recorded an unattributed configuration-hash change. A Windows attempt stopped when Codex hooks failed in its isolated profile; no PR attribution was established, and it is not passing Windows evidence. Paired servers, SSH, mixed versions, terminal-backed retention, and other operating systems were not validated in rendered QA. The exact Retry-remount cleanup has source proof; the final runtime check used startup and renderer reload.

For Brennan's review

Main after aging a chat's files 31 days:

Main: the sent image and chart are unavailable

PR image and chart retention (172e593, before the listener-only cleanup):

PR: sent image and chart still render after aging

Final head: the same open draft before and after cleanup:

Final head before cleanup: unsent image present Final head after cleanup: Not kept, Send disabled

Final head: the sent image survives, and the expired draft's feedback survives reload:

Final head: 31-day-old sent image still renders Final head after reload: Not kept and disabled Send persist

Recovered chart (172e593; no rendered main recovery comparison was captured):

Chart restored from a folder set aside by older cleanup

Three deliberate boundaries:

  • Attachment collection: existing transactional claims protect sent images; unknown reads never establish deletion authority.
  • Draft image rechecks: drafts retain paths, so unclaimed images can expire after 30 days. A host notice rechecks availability and preserves the existing local guidance.
  • Startup recovery: held charts recover with conflicts preserved. Terminal and legacy pastes stay unswept because ownership cannot be established, so disk use can grow.

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