Repository navigation
Description
Split from #550.
What is missing
With as many of its sessions at work as people allow, an autopilot can't start its next session or resume one that failed: fctl run and fctl resume fail, and it has to try again later. Since #556 a message to a resting session waits for room by itself, but a start and a resume don't. The spaghetti autopilot that asked for #550 had written run-when-free.sh beside send-when-free.sh, a script that tried fctl run every two minutes until one went through; a fresh session loses such scripts at every handover.
How it works now
- Starting:
POST /projects/{slug}/sessionsfrom an autopilot callsautopilots::crew_room(crates/fctl-control/src/api/sessions.rs), which answers409 conflictonce as many of its crew sessions work ascrew_maxallows ("…fctl wakes you when one ends its turn, so start this one then, or stop one (fctl stop) to make room"), and429 rate_limitedpastCREW_PER_HOUR(20) sessions started in the last hour. - Resuming: the relay's gate (
crew_room_for(…, false)incrates/fctl-control/src/autopilots.rs) refusesPOST /sessions/{id}/resumeof a session that isn't working, with the same 409, which now adds "a message to one that rests waits for room by itself". - Messages are held instead (feat(autopilot): hold its messages until its session limit has room #556, ADR 0081):
autopilots::holdkeeps them in D1 (autopilot_held) andautopilots::releasesends them in order as a crew session ends its turn, stops or fails, at the autopilot's wakes, and as its limit is raised. ADR 0081 left starts and resumes out: holding them means replaying the request later without the caller that made it, a resume is rare, and a start is what the limit is for. The briefing tells the autopilot to keep the next pieces of work in its plan and start one as fctl wakes it for a session that ended its turn.
What should happen
If autopilots still need it (see Decisions):
- Control plane: a start from an autopilot at its limit, asked to wait (
fctl run --when-free, or a field on the request), is held in order with its held messages and started as soon as there is room, from the person the autopilot acted as, with everything the request asked for (task, title, branches, model, attachments). The answer says it's held and how many go before it; the autopilot or those who steer it take it back as they do a held message. - Control plane: a resume of a failed session at the limit waits the same way, or the autopilot is told to send it a message instead (which a failed session doesn't take today).
- CLI:
fctl run --when-freesays "Held: it starts once one of your sessions ends its turn, stops or fails…";fctl autopilot heldlists held starts beside held messages. - Briefing and brief: say a start may wait, and list held starts.
Compatibility
A held start needs what the request carries (CreateSessionRequest: task, title, branches, model, effort, attachments) kept in D1 until it goes: a new migration, or new columns on autopilot_held. A start answers with a Session today, which a held start doesn't have yet, so the request should opt in (a new optional field that --when-free sets) and get a different answer: an older fctl never sets it and keeps getting the refusal. An autopilot's sandbox gets its fctl from the release's sandbox image, so --when-free reaches autopilots only with the next release after it merges.
Decisions for a person
- Whether autopilots need this at all: their wakes already come as a session ends its turn, which is when a start would go, so a held start mainly saves the autopilot from losing track of what it meant to start next. Its plan may be enough.
- Whether the hourly cap (
CREW_PER_HOUR) also holds a start, or still refuses it. - For a resume: hold it, or let a message resume a failed session (and so wait like any held message).
Activity