Skip to content

feat(files): host methods to upload a file from the phone into a workspace folder - #51195

Merged
AmoabaKelvin merged 6 commits into
mainfrom
files-staged-upload
Nov 27, 2026
Merged

AmoabaKelvin merged 6 commits into
mainfrom
files-staged-upload

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

A phone could only attach files to a chat. It had no way to put a file into a folder of a workspace. This adds the host side of that: the phone sends the file in pieces to a private folder on the host, and only when every piece has arrived does the host create the file in the workspace folder. If the name is already taken, the host refuses and leaves the existing file alone. If the phone drops off halfway, nothing is left in the workspace.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​222 $\color{#cf222e}{\Huge{\mathbf{−}}}$​32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​190

What Changed

  • New host methods files.uploadBegin and files.uploadCommit, behind a new runtime capability files.upload.staged.v1. They reuse the existing staged-save store (StagedFileSaves): files.saveChunk and files.saveAbort carry the bytes and abort, which already have per-connection limits, a 2-minute idle drop, a drop when the socket closes, and a sweep at startup.
  • Each staged save now has a kind (save or upload). A text-save id can't be committed as an upload, and an upload id can't be committed through the text-save path, which would overwrite.
  • uploadBegin resolves and authorizes the target the same way every runtime file mutation does: same ownership fence, local route only, folder workspaces included. It keeps the file name itself (preserveSymlink), so a link already at that name counts as taken rather than being followed. It refuses up front, before any bytes are sent, if the name exists or the folder is gone. On Windows it also refuses a : in the name, because a:b would write into a hidden stream of file a.
  • uploadCommit authorizes the target again and copies the staged bytes into a new hidden file of its own beside the target (.orca-upload-<uuid>, created exclusively). It then publishes that file with link(), which creates the name in one step and fails if the name is taken. The real name only ever holds the whole file. On a drive with no hard links (exFAT, some network shares) the upload is refused with a clear message.
  • A save now accepts one chunk at a time. A chunk sent while the previous one is still being written is refused instead of queued, so a misbehaving client can't make the host hold chunks in memory without limit.
  • Phone allowlist: files.uploadBegin, files.saveChunk, files.uploadCommit and files.saveAbort on the execution-host route. Phones still can't call files.saveBegin or files.saveCommit.

The phone page that uses these comes in a follow-up PR. It is an OTA page and needs no store build.

Why

Two existing paths each had half of what phone uploads need. The desktop upload (files.commitUpload) writes bytes into a hidden temp file inside the worktree and relies on the client to delete it. If a phone dies mid-upload, that temp file stays in the user's folder. Staged saves already keep their bytes in the host's private profile folder and clean up after dropped sockets, but their commit could only overwrite an existing file with text, because they were built for large remote text saves in the editor. Giving staged saves an "upload" kind keeps one store with the limits and cleanup it already has, instead of adding a second one.

The commit publishes with a hard link because that is the one portable operation that creates a file atomically and fails on a taken name. Writing straight into the final name would expose a partly written file, and anything writing that same name during the copy would mix with it. A check followed by a rename could replace a file that another program created in between. Where hard links aren't available, refusing is the only choice that can never touch someone else's file. A new files.uploadBegin method, rather than a mode flag on files.saveBegin, makes older hosts answer "method not found": an older host would drop an unknown flag and commit the upload as a text overwrite.

Linked Issue

#31892: this is the host half of uploading into a folder. The phone page and the download/share direction are still to come.

Visual Proof

N/A: host RPC methods only, with no visible change. The phone page that uses them will ship with before and after captures.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

On macOS, I ran a headless orca serve built from this branch and drove it with a scripted client paired as a real mobile device (E2EE phone protocol), so every call went through the phone allowlist:

  • The serve advertises files.upload.staged.v1.
  • A 1 KB upload and an 18 MiB upload landed byte-for-byte (sha256 match) with the folder's default mode (0644). Nothing was left in staging or beside the files.
  • An upload stopped after 5 of 16 chunks: while the socket was open, its temp sat only in the profile's staging folder. After the socket closed, staging was empty and nothing appeared in the worktree.
  • An existing name was refused at begin. A name created on the host after begin was refused at commit, and the host's file was kept unchanged.
  • files.saveCommit is forbidden to phones. files.saveAbort of a begun upload leaves nothing behind.
  • The same flow works in a folder (non-git) workspace.
  • On an exFAT disk image, the upload is refused with "this drive can't create files safely" and leaves nothing behind. On APFS it is created.

In staged-file-saves.test.ts, an upload creates the file whole, refuses a name taken after begin, never commits through the wrong kind, and refuses a second chunk while one is in flight. I checked that the first test fails when the exclusive create is weakened.

Not run: Windows and Linux hosts.

Performance

None, because nothing runs unless a client uploads. With no upload there are no new timers, polls, subscriptions or file reads. The status reply only carries one more capability string. An upload costs one append per 384 KiB chunk while staging, then one streamed copy, a link and an unlink at commit. It is bounded by the existing staged-save limits: 50 MiB per file, 2 saves and 100 MiB per connection, 8 saves per host. Each save now holds at most one chunk in memory.

Risk

Level: Low

Everything is additive. Older phones never call the new methods, and older hosts don't advertise the capability, so the phone page will hide upload there. The riskiest part is the commit writing into a user's folder. It creates the file under its own hidden name and publishes with an atomic no-replace link, so it never overwrites or deletes a file it didn't create. A host crash in the middle of the commit copy can leave a hidden .orca-upload-* file beside the target, but never a partial file under the real name. Known limit: folders on drives without hard links (exFAT, some SMB/9P shares, possibly WSL's own filesystem reached over \\wsl.localhost from a Windows host) refuse phone uploads. Desktop upload there is unchanged. Text staged saves are unchanged, except that a second chunk sent before the first returns is now refused; the desktop client never does that. Back out with a plain revert.

AI Disclosure

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

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Remote: relayed phones get one upstream socket per phone connection, so a phone dropping off also aborts its uploads on the server. SSH-provider workspaces refuse uploads, like every other runtime file mutation. Workspaces on an SSH-managed server are served locally by that server, so uploads work there.

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)
  • I stated the risk: what could break, for whom, and how to back it out
  • 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)

…e them without replacing files

Adds files.uploadBegin and files.uploadCommit (capability files.upload.staged.v1). Bytes stage in the
host's private staging folder through the existing staged-save chunk and abort methods, so an
unfinished or dropped upload leaves nothing in the folder; the commit creates the file exclusively
and refuses a taken name. Allowlisted for phones.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Staged file saves now support uploads. Uploads stage bytes before commit and create a destination file without replacing an existing file. The runtime validates upload targets, exposes upload begin and commit RPC methods, and advertises the upload capability. Append operations reject chunks submitted while a previous append remains in flight.

Merge Risk: Minimal · up to 15a7f · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: host-side methods that let a phone upload a file into a workspace folder. It uses the conventional feat(files) prefix and matches the changeset (staged upload begin an…
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.
Description check Passed The description is thorough and follows the template. It includes ELI5, What Changed, Why, Linked Issue (#31892), Visual Proof (N/A with reason), Testing with platform details (macOS tested; Windows a…
Full details: Title check

Explanation

The title names the main change: host-side methods that let a phone upload a file into a workspace folder. It uses the conventional feat(files) prefix and matches the changeset (staged upload begin and commit methods, capability, and allowlist routing). It does not mention the hard-link publish or the kind split, which is acceptable for a title.

Full details: Description check

Explanation

The description is thorough and follows the template. It includes ELI5, What Changed, Why, Linked Issue (#31892), Visual Proof (N/A with reason), Testing with platform details (macOS tested; Windows and Linux not run), Performance ("None, because" with reasoning), Risk with level (Low) and revert method, and the checklist. The AI Disclosure and Review sections are empty, but the template marks AI Disclosure as optional for internal contributors and the Review section has no required content. The final lint/typecheck/test/build checkbox is unchecked, which the template allows because CI covers it. The Linked Issue is a cross-reference to #31892 rather than a 'Fixes #' closing link, which may be a minor template deviation.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 601ab78a-e79a-4fc8-bafe-2c8ed485d1f2
Commits

Reviewing files that changed from the base of the PR and between 787c8b0 and 15a7f1d.

Files ignored due to path filters: 1

  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
Files selected for processing: 9

  • src/main/filesystem/local-file-io/filesystem-create-path.ts
  • src/main/runtime/files/staged-file-save-commands.ts
  • src/main/runtime/files/staged-file-saves.test.ts
  • src/main/runtime/files/staged-file-saves.ts
  • src/main/runtime/rpc/methods/files/files-staged-save-methods.ts
  • src/main/runtime/rpc/server/runtime-rpc-mobile-method-routing.ts
  • src/shared/file-access/files-runtime-capabilities.ts
  • src/shared/file-write/staged-file-save.ts
  • src/shared/rpc-contract/filesystem/files-staged-save-params.ts

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

@AmoabaKelvin
AmoabaKelvin merged commit 7bd95c3 into main Nov 27, 2026
57 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.

1 participant