Repository navigation
feat(native-chat): chat scratch folders expire after 30 days unused - #28394
Conversation
A path that doesn't exist yet was authorized by walking up to the nearest existing folder. A dangling symlink fails realpath with ENOENT, so the walk stepped over it and approved the link's own path; the write then followed the link and created its target outside the allowed folders. The walk now continues from the link's target, and returns that real destination.
…atch folder The per-chat folder agents write into is the chat's scratch space, not only a visuals folder. Its root becomes <state>/chat-scratch/<hash> (the hash is unchanged) and the agent variable becomes ORCA_CHAT_SCRATCH_DIR. The old ORCA_CHAT_VISUALS_DIR is never set and is still stripped from what every agent child inherits, Pi included. The visuals skill names the new variable and says the folder is temporary.
…-write' into brennanb2025/cs-rename-chat-scratch
The launch parity snapshot already pins that every agent drops the pre-rename variable.
A chat's scratch folder was removed only when its record was gone or its local workspace was proven deleted, so the folder of a long-idle chat lived forever. The sweep now expires a chat's folder once its newest journal row and the newest entry anywhere in the folder (complete, no-follow scan) are older than 30 days, unless the host holds a running agent, a delivery or an open dispatch for the chat. The final recheck and a rename to <hash>.expired run in the chat's session lane and then a per-folder lock that Orca scratch saves (desktop IPC and host RPC) also take; the delete runs outside both. A save that settles after the age scan marks that expiry stale. Leftover .expired folders and the pre-rename native-chat-visuals root are removed. The workspace-removed rule and its catalog verdict are deleted.
Following a dangling link by hand resolved relative targets against the lexical parent, not the link's real folder: through a folder link the walk could loop forever or authorize the wrong file. Refuse instead: realpath can't say where a dangling link leads, but a write would follow it.
…-write' into brennanb2025/cs-rename-chat-scratch
…-work veto - Remove the other-profile catalog options (running profile id, never-written profiles) that only the deleted workspace verdict used; history cleanup's reader is unchanged. - The sweep keeps its original remove-and-warn block; an unused chat's folder is parked by one function. Drop the unused `now` option and the candidate identity check. - The live-agent case runs against the host's real runWhileExecutionIdle.
…-write' into brennanb2025/cs-rename-chat-scratch
…tch' into brennanb2025/cs-scratch-expiry
…ch-expiry # Conflicts: # src/main/native-chat/native-chat-scratch-folder.ts # src/main/native-chat/native-chat-visuals-sweep.test.ts # src/main/native-chat/native-chat-visuals-sweep.ts # src/main/runtime/native-chat-visuals-workspace-verdict.ts # src/main/runtime/structured-agent-session-runtime.ts
…ch-expiry # Conflicts: # src/main/runtime/runtime-file-commands-write-file-explorer-file.ts
…ch-expiry # Conflicts: # src/main/runtime/files/file-mutations.ts
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⚪ Not assessed Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
35fef037-4db6-4308-96bb-a4e987604b68
📒 Files selected for processing: 17
config/scripts/ci-shard-timings.jsonconfig/scripts/vitest-sqlite-runtime-files.mjssrc/main/ipc/filesystem/filesystem-write-handlers.tssrc/main/native-chat/agent-session-journal/journal-row-table.tssrc/main/native-chat/agent-session-wire/structured-agent-session-conversation-lifetime.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host.tssrc/main/native-chat/native-chat-scratch-folder-lock.tssrc/main/native-chat/native-chat-scratch-folder.tssrc/main/native-chat/native-chat-visuals-sweep.test.tssrc/main/native-chat/native-chat-visuals-sweep.tssrc/main/orca-profiles/other-profile-workspace-catalog.test.tssrc/main/orca-profiles/other-profile-workspace-catalog.tssrc/main/runtime/files/file-mutations.tssrc/main/runtime/native-chat-visuals-workspace-verdict.test.tssrc/main/runtime/native-chat-visuals-workspace-verdict.tssrc/main/runtime/orca-runtime-get-worktree-ps.tssrc/main/runtime/structured-agent-session-runtime.ts
💤 Files with no reviewable changes: 4
- src/main/runtime/native-chat-visuals-workspace-verdict.test.ts
- src/main/orca-profiles/other-profile-workspace-catalog.test.ts
- config/scripts/ci-shard-timings.json
- src/main/runtime/native-chat-visuals-workspace-verdict.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
…e the folder lock Binary (base64) runtime saves now take the scratch folder lock like text saves, and each folder keeps a set of expiry candidates so one sweep finishing no longer hides a save from another.
…ch-expiry # Conflicts: # config/scripts/ci-shard-timings.json
Main's #28394 (chat scratch folders expire after 30 days unused) named the idle sweep's two dispatch checks, `hasOpenDispatch` and `providerHoldsDispatch`, so its new `runWhileExecutionIdle` veto can reuse them. That crossed this part's `store` reads handed to the same sweep: the sweep now gets this part's `store` plus main's named checks. The veto keeps main's own reads.
ELI5
Each Orca chat has a private scratch folder on the machine that runs it, where its agent saves the HTML pages it shows inline. Today a chat's folder is only removed when the chat record is gone or its local workspace is proven deleted, so the folder of a chat nobody has touched in months lives forever. This PR removes a chat's scratch folder once the chat has gone 30 days without use. Live work and saves Orca has confirmed are never lost.
PR 5 of 6 in the chat-scratch stack. Depends only on PR 2 (#28389, rename the folder to
chat-scratch). Nothing else in the stack depends on it.What Changed
The problem. Scratch folders pile up for every chat that ever drew a visual. The only age rule on main asked the workspace catalog whether a chat's local workspace was deleted. That never fires for a workspace that still exists, never fires for SSH or other remote hosts, and needs about 200 lines of catalog code to answer.
User-facing change. In a chat that has been unused for 30 days, inline visuals show "Visualization unavailable" (the existing state for a missing file). The chat itself, its history and its record stay. Scratch folders written before the PR 2 rename (under the old
native-chat-visualsfolder) are removed once, along with that old folder.Mechanism. The host's existing sweep (a few minutes after start, then every 6 hours) now applies these rules to each folder under
<state dir>/chat-scratch/:MAX(ts)query) and the newest modification time anywhere in its folder. The folder scan is complete and recursive, never follows links, yields to the event loop, and stops at the first recent entry. Opening or reading a visual doesn't count as use.<hash>.expired. The recursive delete runs after both locks are released. A later run removes any.expiredfolder a cut-short delete left behind.What each race now does:
A save may wait for one recheck plus one rename (a journal query, a few in-memory checks and one
rename). It never waits for an agent start or for cleanup work, and a failed sweep never fails a save, because the queue's stored tail never rejects. Brennan approved this wait.Removed:
native-chat-visuals-workspace-verdict.ts(the workspace-catalog verdict), its wiring in the runtime and inorca-runtime-get-worktree-ps.ts, and its tests.Why
Differences from the common pattern:
.expiredfolder is reaped by a later run.native-chat-visualsroot is deleted on every run without checking its contents. Native chat has no real users yet and an update restarts the host, which ends every agent that could still write there; after the first run the call does nothing.Linked Issue
N/A (maintainer PR, part of the chat-scratch stack).
Visual Proof
N/A: background cleanup. The only on-screen effect is the existing "Visualization unavailable" state for a visual whose folder expired.
Testing
One sweep fixture against a real temporary folder: a chat unused for 30 days is removed (and the old root is deleted); a recent journal row keeps a chat; a recent file nested in a subfolder keeps a chat; a chat with live work past 30 days is kept; an agent start queued behind expiry gets a fresh folder; a folder with no record is removed; and scan → completed save → locked recheck skips expiry. The existing tests for symlinks, failed removals and scheduling stay.
Checked that the start-race and save-race tests fail when their fix is removed.
File-write, files RPC and runtime suites pass; node typecheck and
orca-ci-checksclean.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
Live QA (M4Air, 2026-10-13)
Hidden Orca rig + a paired headless Orca server on the same Mac, real Claude chats, driven over CDP. Code under test: a local merge of PR 6 (80e42ed) and PR 5 (ec2ac14). All 7 QA rows passed.
native-chat-visuals/folder, that old root was still present 76 s after launch and gone at 155 s (the first sweep), and the chat's pre-rename visual shows "Visualization unavailable":