Skip to content

feat(runtime-files): the host serves a chat's scratch folder as a file root - #28397

Merged
brennanb2025 merged 19 commits into
mainfrom
brennanb2025/cs-host-serves-scratch
Oct 14, 2026
Merged

brennanb2025 merged 19 commits into
mainfrom
brennanb2025/cs-host-serves-scratch

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​58 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​95 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​78

ELI5

Each Orca chat has a private scratch folder on the machine that runs it, where the agent saves the HTML pages it shows inline. Today the app can only show those pages inside the chat; it can't open, edit or preview them like ordinary files, because Orca's file commands only work on workspaces, and the scratch folder isn't one. This PR lets the machine that owns a chat serve that chat's scratch folder through the normal file commands, so the next PR can open a chat visual like any other file.

PR 3 of 6 in the chat-scratch stack. Depends on PR 2 (#28389, the folder is renamed to chat-scratch), which depends on PR 1 (#28385, never write through a dangling symlink). PR 4 (open a chat visual like any file) builds on this one.

What Changed

The problem. To open, edit or preview a file, the app asks the machine that holds it, naming a workspace and a relative path. A chat's scratch folder sits in Orca's own state directory, not in any workspace, so no request could name it, and path authorization would refuse it anyway because it isn't under a project root. The inline visual reader also never said where the file lives, so the app had nothing to point a file command at.

User-facing change. None yet. PR 4 uses this for "Open in new tab", edits saved on the chat's machine, and the document preview of a remote chat's visual.

Mechanism.

  • Addressing. A file request may name a scratch folder with the existing path: workspace selector: path:<this machine's chat-scratch folder>/<32-hex folder name>. The machine answers only when that is exactly its own scratch root plus a 32-hex name, and the folder is a real directory, not a symlink. A folder with the same name under some other directory falls through to the normal workspace lookup and fails as an unknown workspace.
  • Where the check lives. It sits where file commands resolve their target (orca-runtime-file-commands.ts), not in the general workspace resolver. That resolver also decides where a new chat runs, and a scratch folder must never become a chat's workspace. Git, terminals and chat creation never see this selector.
  • Authorization. File commands now authorize paths against the project roots plus this machine's chat-scratch root, through one small wrapper (resolveRuntimeAuthorizedPath) used where they authorize: the file provider (read, write, stat and so on), preview and chunk reads, the mobile file read, the folder watch and the upload commit. Symlinks that lead out of the scratch folder are refused as they are everywhere else; PR 1 covers dangling links.
  • Opening a tab is refused. files.open and files.openDiff for a scratch folder fail with chat_scratch_not_openable, because they would hand the desktop a workspace id it has no row for.
  • The inline visual reader says where the file is. Both successful answers from agentSession.readVisual (the full page, and "unchanged since your copy") now include path, the file's absolute path on that machine, spelled under the same folder the selector check expects. It is a new optional field on an existing result; nothing else about the call changes.

Why

The scratch folder has no workspace row, so something must name it. Reusing the existing path: selector with an exact equality check keeps it to one branch: no new selector syntax, no new RPC, and no workspace row that other features (Git, terminals, chat placement) would then have to learn to ignore.

Alternatives considered:

  • Recognize any path that ends in chat-scratch/<hex>: two different folders with the same ending would map to one name, so a tab could read or save a file other than the one it names. Exact equality with this machine's own folder rules that out.
  • Put the branch in the general workspace resolver, like the floating workspace: that resolver also places new chats, so a client could start a chat whose workspace is a scratch folder.
  • A dedicated read/write RPC for scratch files: it would duplicate the file commands (save, preview, watch) that PR 4 wants to reuse as they are.

No compatibility code: no capability check and no fallback. An older machine simply omits path, which PR 4 treats as "can't open".

Differences from the common pattern:

  • Intended: the scratch folder is addressed by its absolute path on the owning machine rather than by a workspace id. Safe because the machine accepts only its own scratch root, refuses tab-opening commands for it, and authorizes every path against that root as it does for project roots.

Linked Issue

N/A (maintainer PR, part of the chat-scratch stack).

Visual Proof

N/A: plumbing for PR 4; nothing on screen changes.

Testing

One test of the whole contract (structured-agent-session-visual.test.ts): readVisual returns path on both successful answers; path:<its folder> then writes, reads and document-previews the file through the real file commands; files.open is refused; a same-named folder at a different path inside the allowed root is refused by the selector alone; a link from the scratch folder to outside it is refused. Removing the scratch root from authorization makes it fail at the write.

  • Runtime file command, file RPC, native-chat, provider, filesystem and doc-preview suites: 547 files, 5,473 tests pass.
  • Typecheck: node and web clean.
  • orca-ci-checks: 22 of 23 pass; the one failure is the known local-only typecheck:ci "Script not found check" (the plain typecheck step passes).

Size against PR 2's branch: production +96 / −18 (one of those lines registers the contract test, which opens a real SQLite store, to run under Node), tests +58 / −5.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

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

  • Security: the new root is Orca-owned state and is added only for the runtime's file commands. The exact-equality selector and the existing symlink checks keep requests inside this machine's chat-scratch root and its usual workspace roots. As in any workspace, a symlink the local agent creates inside a scratch folder is followed only as far as those roots allow.
  • Cross-platform: the selector is compared with the host's own path.dirname/path.join spelling, so Windows and POSIX hosts each match what they themselves returned from readVisual.
  • SSH/remote: a remote chat's requests go to the machine that runs it, which matches against its own root. A request that reaches another machine names a root that isn't that machine's own and is refused.
  • Mobile: unchanged.

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.

  • The visual's source on the paired server opened in the editor through the scratch folder (editable on first open, no "External local files are not available" error), and the save landed in the server's file:

source of a server scratch file, edited and saved

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.
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.
…e root

File commands accept `path:<this host's chat-scratch root>/<32 hex>` and
resolve it only when it names this host's own folder, at the file-commands
seam so the selector never reaches chat placement. They authorize against
the project roots plus the chat-scratch root, refuse files.open/openDiff
for the folder, and agentSession.readVisual's ok results carry the file's
absolute path so a client can build the selector.
…-write' into brennanb2025/cs-rename-chat-scratch
…-write' into brennanb2025/cs-rename-chat-scratch
…tch' into brennanb2025/cs-host-serves-scratch
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/cs-rename-chat-scratch to main October 14, 2026 05:09
…serves-scratch

# Conflicts:
#	src/main/runtime/rpc/methods/structured-agent-session-visual.test.ts
@brennanb2025
brennanb2025 marked this pull request as ready for review October 14, 2026 05:39
@coderabbitai

coderabbitai Bot commented Oct 14, 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

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: 4684182d-0d05-4d29-b354-784042cc9d69
📥 Commits

Reviewing files that changed from the base of the PR and between 6680781 and acbed66.

📒 Files selected for processing: 6
  • src/main/runtime/files/chat-scratch-file-root.ts
  • src/main/runtime/files/file-mutations.ts
  • src/main/runtime/files/file-reads.ts
  • src/main/runtime/files/file-target.ts
  • src/main/runtime/files/watch/file-watches.ts
  • src/main/runtime/orca-runtime-file-commands.ts

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

Runtime file authorization now includes the host’s chat-scratch root. Runtime file commands resolve chat-scratch selectors and reject attempts to open or diff those worktrees. Successful visual reads now return the visual file path, including unchanged results. Tests cover scratch-folder file operations and rejection of nested foreign folders and symlinked paths.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to acbed

No actionable merge-blocking risk remains from the reviewed changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 19 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 and concisely describes the main change: serving a chat's scratch folder as a runtime file root.
Description check Passed The description is complete and aligned with the repository template. It explains the user impact, implementation, rationale, linked PR context, visual-proof exception, testing, security, cross-platfo…
✨ 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 47e95a4b-1bb9-415e-8044-9079430aaefe
📥 Commits

Reviewing files that changed from the base of the PR and between 9b1e83a and 73465c1.

📒 Files selected for processing: 14
  • config/scripts/vitest-node-runtime-files.mjs
  • src/main/ipc/filesystem-auth.ts
  • src/main/native-chat/native-chat-visual-file-read.test.ts
  • src/main/native-chat/native-chat-visual-file-read.ts
  • src/main/runtime/orca-runtime-file-commands.ts
  • src/main/runtime/orca-runtime-files-terminal-link-host-translation.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session-visual.test.ts
  • src/main/runtime/runtime-chat-scratch-file-root.ts
  • src/main/runtime/runtime-file-command-target.ts
  • src/main/runtime/runtime-file-commands-assert-remote-terminal-file-grant-path-still-canonical.ts
  • src/main/runtime/runtime-file-commands-create-file-explorer-dir-no-clobber.ts
  • src/main/runtime/runtime-file-commands-read-file-explorer-preview.ts
  • src/main/runtime/runtime-file-commands-terminal-file-paths.ts
  • src/shared/rpc-contract/agent-session-visual-params.ts

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

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

🟠 Major · Bind scratch selectors to the authenticated chat. · runtime-chat-scratch-file-root.ts:30-49

src/main/runtime/runtime-chat-scratch-file-root.ts:30-49
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

Bind scratch selectors to the authenticated chat.

agentSession.readVisual returns the visual's absolute path, and its caller supplies the sessionId. The scratch folder name is a deterministic hash of that ID. A caller can therefore obtain or construct a sibling path: selector.

resolveChatScratchSelectorFolder checks only the host root, the 32-hex name, and directory existence. The file-command boundary has no caller-session check. The selector then reaches file reads, writes, previews, directory reads, and watcher setup. One chat can read or modify another chat's scratch files.

Pass the authenticated caller session into this boundary and reject selectors that do not resolve to that session's nativeChatScratchFolderFor(...) folder. Add a sibling-folder regression test.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d971fa2-874d-4225-b7aa-68e0aef33748
📥 Commits

Reviewing files that changed from the base of the PR and between 73465c1 and 4dfe58c.

📒 Files selected for processing: 1
  • src/main/runtime/rpc/methods/structured-agent-session-visual.test.ts

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

…serves-scratch

# Conflicts:
#	src/main/runtime/files/file-reads.ts
#	src/main/runtime/files/file-target.ts
#	src/main/runtime/files/watch/file-watches.ts
#	src/main/runtime/runtime-file-commands-create-file-explorer-dir-no-clobber.ts
#	src/main/runtime/runtime-file-commands-terminal-file-paths.ts
@brennanb2025
brennanb2025 merged commit 81ed8c0 into main Oct 14, 2026
32 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/cs-host-serves-scratch branch October 14, 2026 17:50
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