Skip to content

feat(autopilot): pass files to and from the sessions an autopilot starts - #558

Merged
kalaspuff merged 10 commits into
mainfrom
fctl/1292-let-an-autopilot-attach-files-to-and-rea
Nov 15, 2026
Merged

kalaspuff merged 10 commits into
mainfrom
fctl/1292-let-an-autopilot-attach-files-to-and-rea

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An autopilot can now attach files to the sessions it starts and steers (fctl run --attach, fctl send --attach) and read the files sent in the sessions it reads, with a new fctl files list / fctl files get (for people too). Files like the .3mf and .stl models of the 3D printing autopilot then pass from a person to one session, and from there to another, without anyone attaching them again.

  • Relay: the autopilot's fctl sends a file to fctl-agent in base64 as a new AgentCall::ApiBytes, and the host posts the bytes as they are to a new runner endpoint, POST /api/v1/runner/sessions/{id}/relay. The Worker routes them as the JSON relay does, as the autopilot's owner, but streams the body in and the answer out, so a 20 MB file never goes into wasm memory. Only uploads and downloads of files go this way (fctl_domain::autopilot::carries_files), and the JSON relay refuses them.
  • What it may do: it uploads for a session it starts (Gate::Open) or one it started (Gate::Crew), and reads the files of the sessions it can read. GET /api/v1/sessions/{id}/attachments (new) lists a session's files, leaving out those of an autopilot's messages fctl still holds for room (feat(autopilot): hold its messages until its session limit has room #556). A held message that never goes hands its files back as unsent uploads, which are deleted a day later.
  • Its instructions: where its sandbox's fctl has fctl files, its ~/AGENTS.md tells it to attach files rather than publish screenshots for its sessions. It still publishes to show people an image in what it asks them.

I checked it with unit tests (the gate, which requests carry files, fctl-agent passing them on only from an autopilot's own session, the ~/AGENTS.md text, picking files by name) and in cargo xtask dev. There, the fake autopilot started a session with a 3 MB model attached. It then downloaded a 19.5 MB file a person had sent that session and attached it to another of its sessions. The sha256 matched at every step. Its attempt to attach a file to a person's session was refused.

Runners a version behind keep working: their fctl-agent refuses ApiBytes, and fctl says the runner needs a newer fctl. The autopilot's ~/AGENTS.md keeps telling it to publish screenshots until its sandbox's fctl has fctl files. The session socket now takes requests of up to 32 MiB (it was 8), enough for a 20 MB file in base64.

Crew sessions still send the autopilot no files, as Carl Oscar decided: what one makes for another (a sliced .gcode.3mf, say) goes on its branch, or as a screenshot it publishes, and the autopilot's instructions say so.

Worth confirming

  • Decision: the autopilot reads the files of every session it can read, people's sessions in its places too, as it already reads their transcripts. It uploads only for sessions it starts or started.
  • Decision: uploads and downloads add no line to the autopilot's log. The message or session that sends the files gets its usual line.
  • Decision: fctl files get SESSION NAME takes the newest file of that name and writes it into the current directory (or --dir), but over no file already there unless --force, as the names are whoever sent the files'. --all takes the newest of each name, and an older one is reached by its id.
  • Decision: AgentCall::ApiBytes is a variant of its own, not optional fields on AgentCall::Api as the issue suggested. An older fctl-agent refuses an unknown variant, where it would silently drop new fields and send an empty upload.
  • Assumption: the name fctl files (the files sent in a session) reads clearly beside fctl autopilot files (the autopilot's own text files, from feat(autopilot): keep files across an autopilot's sessions #555). The autopilot's instructions tell the two apart: attachments go to its sessions, while its own files are what it keeps for its next session.

Fixes #517

fctl session


Note

Medium risk. It adds a runner endpoint that streams file bodies to the API as an autopilot's owner, a new AgentCall::ApiBytes variant with its own permission gate, and raises the session socket request limit from 8 to 32 MiB.

What it does. Lets an autopilot attach files to the sessions it starts and steers (fctl run --attach, fctl send --attach) and read files in sessions it can read, through new fctl files list and fctl files get commands. Files travel from the autopilot's fctl through fctl-agent as base64 in AgentCall::ApiBytes, then through a new runner relay endpoint to the API, and a new GET /api/v1/sessions/{id}/attachments lists a session's files. Uploads are allowed only for sessions the autopilot starts or started, while downloads cover every session it can read. fctl files get downloads into hidden part files, created as new files only, and puts them in place once every download came, writing over no existing file unless --force.

Permission gate. The autopilot can read the files of every session it can read, including people's sessions in its places, but upload only to sessions it starts or started.

fctl review's first look at a8071f1 · 32 files, +1564 −83 · Review agent settings

fctl-sh Bot added 2 commits November 15, 2026 11:40
An autopilot's own session can now upload files (fctl run --attach,
fctl send --attach) and download those sent in sessions it reads
(fctl files list/get). Its fctl sends them to fctl-agent in base64 as
AgentCall::ApiBytes; the host posts the bytes as they are to the new
runner endpoint POST /runner/sessions/{id}/relay, and the Worker routes
them as the autopilot's owner with the body streamed through, never into
wasm memory. GET /sessions/{id}/attachments lists a session's files.

Refs #517
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner November 15, 2026 11:50
@fctl-review

This comment has been minimized.

Comment thread crates/fctl-host/src/session.rs Resolved
- Limited tokens that read sessions list their files too.
- The relay checks only the path before its query for .. and //, so a
  file named v1..2.pdf uploads.
- The host tries an autopilot's file only while fctl-agent still waits
  for it (110 s in all), rather than uploading it again after.
- fctl reads fctl-agent's answer even when the agent closed before it
  read the whole request, as one from before files does for a request
  over 8 MiB, so it says the runner needs a newer fctl.

Refs #517
@fctl-sh

fctl-sh Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Answers to fctl review's findings in its summary for 503fbc7. All three are fixed in f162823:

  1. Read-limited tokens can't list a session's files: right, and no limited token could, whatever its access, since the route fell through to the refusal. GET sessions/{id}/attachments is now in the Read arm beside the download, and in the test's list.
  2. Relay refuses uploads whose file name contains ..: right. The check now applies only to the path before ?. It moved to fctl_domain::autopilot::relayable_path, whose test covers ?name=v1..2.pdf (allowed) and .. or // in the path (refused).
  3. Old fctl-agent's "too large" refusal is never read: right. ask_agent now reads the reply even when the write failed, and only reports the write or read error when no answer came. A new test stands in for an older fctl-agent that reads 64 KiB of a 4 MiB request, answers and closes. Without the fix it failed with "Broken pipe"; now fctl gets the answer and says the runner needs a newer fctl.

…pilot-attach-files-to-and-rea

# Conflicts:
#	crates/fctl-control/src/autopilots.rs
#	crates/fctl-domain/src/autopilot.rs
#	docs/llms.txt
@fctl-review

This comment has been minimized.

Comment thread crates/fctl/src/cmd/files.rs Resolved
fctl-sh Bot added 2 commits November 15, 2026 12:21
…sked

- A session's files leave out those of an autopilot's messages fctl
  still holds for room; a held message that never goes (taken back,
  dropped, refused at the cap, or the project off autopilot) hands its
  files back as unsent uploads, deleted a day later.
- A task of files alone from an autopilot is named after its files, not
  after the note fctl adds to it.
- fctl files get writes over no file already there unless --force, nor
  two files of one name in one go.

Refs #517
@fctl-sh

fctl-sh Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Answers to fctl review's findings in its summary for b6cef7c. Both are fixed in 60dccbf:

  1. Files of a held message are listed as sent before the message goes: right. GET /sessions/{id}/attachments now leaves out the files of messages fctl still holds for that session (autopilots::held_files, from autopilot_held). A held message that never goes now hands its files back to the files object as unsent uploads (a new /unclaim), so they're deleted a day later instead of staying with the session unseen. That covers a message taken back, dropped because its session failed, refused at the 30-message cap, or dropped as the project goes off autopilot (drop_all_held). One part of the finding doesn't hold: forwarding such a file never fails with "already sent", because fctl send --attach uploads the downloaded bytes as a new attachment. In cargo xtask dev, with a limit of one session, two messages with a file each were held: neither file was listed. Taking one back left its file with no session (so it's deleted a day later), and the other was listed once its message went out. A held message's sent_at is when it was held, which the type's docs now say.
  2. Files-only task from an autopilot gets the crew note as its title: right. The title now looks at the task as given, before the crew note is added. In cargo xtask dev, the autopilot's fctl run --attach model.3mf with no text started a session titled model.3mf.

@fctl-review

This comment has been minimized.

Comment thread crates/fctl/src/cmd/files.rs Resolved
Each file downloads to a hidden part beside where it goes, and all go in
place once every one came, without writing over a file there unless
--force; a failure removes the parts, so the same command runs again.

Refs #517
@fctl-review

This comment has been minimized.

Comment thread crates/fctl/src/cmd/files.rs Resolved
@kalaspuff
kalaspuff merged commit 236de9f into main Nov 15, 2026
12 of 13 checks passed
@kalaspuff
kalaspuff deleted the fctl/1292-let-an-autopilot-attach-files-to-and-rea branch November 15, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Let an autopilot attach files to the sessions it starts

1 participant