Skip to content

Let an autopilot's session starts and resumes wait for room at its session limit #559

Open

Description

@fctl-sh

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}/sessions from an autopilot calls autopilots::crew_room (crates/fctl-control/src/api/sessions.rs), which answers 409 conflict once as many of its crew sessions work as crew_max allows ("…fctl wakes you when one ends its turn, so start this one then, or stop one (fctl stop) to make room"), and 429 rate_limited past CREW_PER_HOUR (20) sessions started in the last hour.
  • Resuming: the relay's gate (crew_room_for(…, false) in crates/fctl-control/src/autopilots.rs) refuses POST /sessions/{id}/resume of 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::hold keeps them in D1 (autopilot_held) and autopilots::release sends 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-free says "Held: it starts once one of your sessions ends its turn, stops or fails…"; fctl autopilot held lists 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).

Session: https://app.fctl.sh/s/ses_01M7FBR91XMD2RC1EXPNDF9A4D

Activity

  1. added
    enhancement
    control-plane
    cli
    on Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clicontrol-planeenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions