Repository navigation
Open
Description
The gap
- In a remote (SSH) session, paste, drop and Attach all fail with
400 Prompt uploads are not supported for remote (SSH) sessions. The refusal is right for the old code:workingDiris the remote path, so a file written on the Codeman host is one the agent on the other host can never read. - That leaves no way to hand a screenshot, a PDF or a phone video to an agent running on another machine, which is most of what I use remote sessions for.
What I built (branch: https://github.com/Randalix/Codeman/tree/feat/remote-upload-upstream, one commit on current master). I'm asking before opening a PR.
- The route receives and checks the upload exactly as it does for a local session (multipart limits, magic bytes, HEIC to JPEG, the document and
?kind=videopaths, both rate buckets), but into a private staging folder underdataPath('upload-staging')instead of the workspace. Notos.tmpdir():/tmpis a tmpfs on my host, and a 1GB video would sit in RAM for the whole copy. remoteWriteUpload()insrc/remote-files.tsthen streams the staged file over the ssh child's stdin into the remote<workspace>/.codeman-uploads/, and the staging folder is removed in afinally. The response carries the remote path, so the client types a path the agent can open. No client change.- The ssh line is the existing
buildRemoteFileCommand()(sobuildSshConnectionArgsandremoteLoginShellLine), run underrunWithRemoteSshLimit. Timeout is 30 s plus the size at 256 KiB/s, as for the edit-history reads.
The invariants I would want reviewed
- The remote script keeps the local folder rules in
sh: a symlink or non-directory at.codeman-uploadsis refused (403) and nothing is written through it,mkdirwithout-p, and the.gitignoreof*is written only when nothing is there (noclobber). - No partial file survives. A cut transfer ends
catwith a clean EOF, so the bytes go to<name>.partand are renamed only whenwc -cequals the size that was sent; otherwise the.partis removed and the route answers 502. - An upload never wakes a host. A sleeping host gives 502 with the ssh reason.
- The name reaching the remote shell must match
paste-[A-Za-z0-9._-]+, and a~/workspace resolves against the remote$HOME.
Not covered: the hourly GC still lists nothing for a remote session (uploadDirs()), so remote uploads are not aged out. I left that alone, since the sweep deletes and I didn't want to add a remote delete to this change.
Verification
- New
test/remote-upload-script.test.tsruns the generated script for real under a localsh, wrapped byremoteLoginShellLineas sshd's login shell gets it: binary bytes with NUL, quote and backslash, symlinked folder (nothing written), file in place of the folder, missing workspace, short transfer (neither file nor.partleft),~/workspace, a workspace namedit's a $(touch pwned) dir. The two "refuses remote" tests intest/routes/session-routes.test.tsare replaced by five that mock onlyremoteWriteUpload. - Targeted suites (7 files, 256 tests), tsc, eslint, prettier pass. I could not finish a full
npm teston this box: my memory guard stopped it, and the only failures up to that point were three known environment ones (remote-edit-sourcesE2BIG,remote-pane-command-shellwith SHELL unset,frontend-public-toolingwithout vendor assets). - Live against a Linux host over LAN: 3,000,000 random bytes in 0.59 s, SHA-256 identical on both ends,
.gitignorecreated. Through the running server withcurlinto a real session: the.mdlanded in the remote.codeman-uploads/and the staging folder was empty afterwards.
Most of the session-routes.ts diff is the handler body moving into an inner receiveUpload(), so git diff -w reads much smaller.
PR welcome?
Metadata
Metadata
Assignees
Labels
No labels
Activity
Ark0N commentedon Nov 18, 2026
Thanks for asking before opening the PR, and for the detailed write-up.
On current
master, the refusal you hit is thesession.remoteguard in thepaste-imageroute (src/web/routes/session-routes.ts). No PR or other issue covers remote uploads. Your branch is one commit on top of currentmasterand touches seven files, none of them undersrc/web/public/, so the client really is unchanged.What is still open is whether Codeman should write to a remote host at all. Right now the docs treat that as out of scope on purpose:
CLAUDE.md, Remote sessions paragraph: "no writes over ssh"@fileoverviewofsrc/remote-files.ts: "Read-only by design"docs/remote-sessions.md: "Not available over ssh (by choice, not by accident)"docs/file-viewer-edit-plan.mdsection 6 anddocs/architecture-invariants.md(Remote SSH cases)Your branch updates the Prompt uploads paragraphs but leaves those as they are, so taking it means changing that rule. That decision hasn't been made, so I can't say yet whether a PR for this would be accepted.
Either way, a review would look at these:
remoteWriteUpload()runs insiderunWithRemoteSshLimit(), a process-wide pool of 4 slots (CODEMAN_MAX_REMOTE_FILE_SSH) that every remote preview, probe and history read shares. The limiter leaves long-lived streams out of that pool on purpose. With your timeout (30 s plus the size at 256 KiB/s), a 1 GiB video (MAX_PASTE_VIDEO_BYTES) on a slow link can hold a slot for about 69 minutes, and four such uploads would leave every other remote file read on the server queued behind them.finally, but if the server restarts mid-upload,upload-staging/remote-*is left behind and nothing sweeps it at boot.uploadDirs()insrc/web/paste-image-gc.tsreturns nothing for a remote session, and the session-delete cleanup uses the same function, so remote uploads are neither aged out nor removed when the session is closed.fix(upload): own ssh pool for remote uploads; sweep staging at start
Randalix commentedon Nov 23, 2026
I fixed your points 1 and 2 in f33753f, on top of the same branch (
feat/remote-upload-upstream).SshSlotPoolclass. The shared functions keep the default pool of 4, and uploads run in their own pool (runWithRemoteUploadLimit, 2 slots,CODEMAN_MAX_REMOTE_UPLOAD_SSH). A long upload can no longer hold a slot that previews, probes and history reads need, and 4 + 2 stays under OpenSSH's default of 10 concurrent unauthenticated connections.sweepRemoteUploadStaging()runs once at route registration and removesupload-staging/remote-*folders older than the call. An upload that starts in the meantime keeps its folder, and a symlink is removed as a link.Tests: 6 new in
test/remote-upload-pool.test.ts. Live, a planted leftover folder was gone after a restart, and a.mdupload to a session on an SSH host arrived with the right content and left the staging folder empty.Point 3 I've left alone. Aging out and deleting remote uploads means deleting files on the host over ssh, so it depends on the same decision about writes over ssh, and I'd rather wait for that than build a remote delete you might not want.
Ark0N commentedon Nov 23, 2026
Thanks for the follow-up.
I went through f33753f on
feat/remote-upload-upstream. Both fixes work the way you describe:remoteWriteUpload()now runs inrunWithRemoteUploadLimit(), a separateSshSlotPoolof 2 (CODEMAN_MAX_REMOTE_UPLOAD_SSH), whilerunWithRemoteSshLimit()keeps the shared pool of 4 (CODEMAN_MAX_REMOTE_FILE_SSH). A long copy no longer holds a slot that previews, probes and history reads wait on.sweepRemoteUploadStaging()is called fromregisterSessionRoutes(), whichstart()insrc/web/server.tsruns before the server listens, so the sweep can't list the folder of an upload that is still running. It only touchesremote-*entries older than the call, and a symlink is removed as a link.I also copied the remote script's steps from the diff and ran them under a local
/bin/sh(dash). A full transfer lands next to the.gitignore, a short one leaves neither the file nor the.part(exit 6), a symlinked.codeman-uploadswrites nothing (exit 4), and a missing workspace exits 5. I did not run your test files.The new pool still has one gap.
runWithRemoteUploadLimit()waits for a slot with no bound (there is nomaxWaitMs), and the 30 s plus size timer only starts once a slot is held. If both slots are busy with long video copies, a pasted screenshot is received and staged, then waits behind them, with its request open, for as long as they take.The two commits are now 62 behind
master, and the combined diff still applies cleanly to currentmaster.The policy question hasn't changed: should Codeman write to a remote host over ssh at all? f33753f leaves the texts that state the current rule as they are: "no writes over ssh" in
CLAUDE.md, "Read-only by design" in the@fileoverviewofsrc/remote-files.ts(which now sits aboveremoteWriteUpload()), and "Not available over ssh (by choice, not by accident)" indocs/remote-sessions.md. Your point 3 depends on the answer. If writes over ssh are allowed, there is a second question: can remote uploads land whileuploadDirs()insrc/web/paste-image-gc.tsstill returns nothing for a remote session (so the files are never aged out and never removed when the session is closed), or does a remote delete have to come with them? Neither has been decided, so I still can't say whether a PR for this would be accepted.