Repository navigation
feat(files): host methods to upload a file from the phone into a workspace folder - #51195
Conversation
…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.
…er a failed upload
…c no-clobber link
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
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.
What Changed
files.uploadBeginandfiles.uploadCommit, behind a new runtime capabilityfiles.upload.staged.v1. They reuse the existing staged-save store (StagedFileSaves):files.saveChunkandfiles.saveAbortcarry 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.saveorupload). 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.uploadBeginresolves 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, becausea:bwould write into a hidden stream of filea.uploadCommitauthorizes 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 withlink(), 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.files.uploadBegin,files.saveChunk,files.uploadCommitandfiles.saveAborton the execution-host route. Phones still can't callfiles.saveBeginorfiles.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.uploadBeginmethod, rather than a mode flag onfiles.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
On macOS, I ran a headless
orca servebuilt 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:files.upload.staged.v1.0644). Nothing was left in staging or beside the files.files.saveCommitis forbidden to phones.files.saveAbortof a begun upload leaves nothing behind.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
linkand 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.localhostfrom 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)