Skip to content

feat(autopilot): wake autopilots as their sessions' pull requests merge - #546

Merged
kalaspuff merged 3 commits into
mainfrom
fctl/1264-wake-on-merge
Nov 14, 2026
Merged

kalaspuff merged 3 commits into
mainfrom
fctl/1264-wake-on-merge

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

Summary

The spaghetti autopilot named "wake me when PR N merges" and "message session X when PR Y merges" as the most common reasons it wrote watcher scripts. Those scripts died at every handover. A crew session's pull request that merged or closed while the session rested (its turn ended, it stopped or failed) told the autopilot nothing until its check-in, up to a day later. That hit hardest without the merge power, where people merge, and with a session held back until another's merge.

Now, when GitHub says such a pull request merged or closed, SessionObject wakes the autopilot. It's gathered a minute like other crew wakes, whoever merged it. It counts the session as changed so that the wake lists it, with #67 merged in its line. A session at work, one waiting for its background work, or one just messaged (which counts among those at work until its runner reports) doesn't wake it this way: its turn's end does, with the pull request as it stands. The briefing says so where it talks about merging, and the shared-layout lesson no longer suggests a script to wait for the first merge.

I verified it with unit tests on the rule (which statuses wake, only a pull request that newly ended) and in cargo xtask dev, through a temporary route standing in for GitHub's webhook. With the autopilot resting, nothing at work and its crew session stopped, marking that session's pull request merged scheduled a wake at once. A minute later the wake listed the session as stopped (a message resumes it); pull requests #67 merged.

Related pull requests

Worth confirming

  • Decision: a closed pull request wakes it too, not only a merged one: the work it waited for won't land.
  • Decision: the merge bumps the crew session's updated_at, which the wake's news selects by, so the session also shows as recently changed in lists. This applies only to sessions an autopilot started.

fctl session


Note

Medium risk. It changes when autopilots are woken and bumps a session's updated_at from the pull request refresh path, which the working-session count in CREW_WORKING reads.

What it does. Wakes an autopilot as soon as a pull request of one of its crew sessions merges or closes while that session rests (idle, stopped or failed), instead of at its next check-in. A session that is working, waits for background work, or ended its turn and was just messaged is left to wake the autopilot when its turn ends. The briefing text and docs now describe this.

Working-count interaction. The wake sets updated_at on the session, which is why an idle session with a newer message is skipped: CREW_WORKING counts it at work by messaged_at >= updated_at.

fctl review's first look at 86494b4 · 5 files, +154 −7 · Review agent settings

…ge or close

A pull request of a session an autopilot started that merged or closed
while the session rested (its turn ended, it stopped or failed) told the
autopilot nothing until its check-in, so autopilots without the merge
power, and those holding a session back until another's merge, polled
GitHub from scripts that died at each handover. SessionObject now wakes
the autopilot as GitHub says so (fctl_domain::autopilot::pull_wakes), and
counts the session as changed so that the wake lists it with its pull
requests. A session at work wakes it as its turn ends instead.
@fctl-review

This comment has been minimized.

Comment thread crates/fctl-control/src/do_session.rs Resolved
Comment thread crates/fctl-domain/src/autopilot.rs Resolved
A session just messaged counts among those at work by messaged_at >=
updated_at until its runner reports; the merge wake's bump of updated_at
dropped it from that count, so the autopilot could start one session too
many. Its merge now wakes nothing: the turn the message starts does. The
briefing says a session at work wakes it as its turn ends.
kalaspuff pushed a commit that referenced this pull request Nov 14, 2026
## Summary

`project#12` resolved only among the project's latest 200 sessions, so a
long-running autopilot's session became unreachable by number once 200
newer ones came, and every plan had to carry `ses_…` IDs. The spaghetti
autopilot ran into that. `GET /sessions` now takes `?number=` with
`?project=` and gives that one session however old it is. The CLI asks
for it everywhere it resolves `project#N` (`fctl show`, `send`, `logs`,
`autopilot ask --session` and the rest).

Older control planes ignore `?number=` and return the latest 200 as
before, among which the CLI still looks. Only then does its error add
"(or it is older than the last 200)".

I verified it with a CLI test (the request it makes and both errors) and
in `cargo xtask dev`: `?number=1&limit=1` returned session #1 rather
than the newest, and `fctl show playground#1` found it.

## Related pull requests

- #544
- #546

[fctl session](https://app.fctl.sh/s/ses_01M7DQEXFV9KNC4CY8ZZZ2KHZH)

<!-- FCTL_REVIEW_SUMMARY -->
---

> [!NOTE]
> **Low risk.** It adds an optional query filter to the sessions list
and changes how the CLI looks up `project#number`; an older control
plane ignores the filter and the CLI falls back to the old behavior.
>
> **What it does.** `fctl` looked up `project#number` among a project's
latest 200 sessions, so older sessions could not be found. The sessions
list now takes `?number=` together with `?project=`, and the CLI asks
for exactly that session. Docs and a test are updated.
>
> **Older control planes.** A control plane without `?number=` ignores
it and returns the latest 200, so the CLI still searches among those and
keeps the old error message.
>
> <sub>[fctl
review](https://app.fctl.sh/s/ses_01M7DSPMGMH1AR48MZ9N5Z1Y68)'s first
look at
[`e9a1f40`](e9a1f40)
· 5 files, +86 −19 · [Review agent
settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub>

<!-- /FCTL_REVIEW_SUMMARY -->

Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
@fctl-review

This comment has been minimized.

Comment thread crates/fctl-domain/src/autopilot.rs Resolved
kalaspuff pushed a commit that referenced this pull request Nov 14, 2026
)

## Summary

Carl Oscar asked the spaghetti autopilot (on fctl 0.34.1) what it would
tell any fctl autopilot. Most of its advice already reached the briefing
through #538–#543. This adds what hadn't:

- **Which sessions count toward the limit.** The autopilot had to guess,
and guessed wrong about queued ones. The briefing, the limit's error and
the docs now say: those queued, starting, working, paused on a usage
limit or still stopping count, as does one just messaged; one that ended
its turn, stopped or failed doesn't. With all of them at work, the
autopilot keeps the next tasks in its plan and starts one when fctl
wakes it for a session that ended its turn.
- **Lessons.** Name sessions as the brief and wakes do, never with a
placeholder or a guessed number (it sent one `fctl send` to a made-up
ID). Keep the scripts the work relies on in the plan whole, and lead the
plan with what a stranger must act on first. Send long output to a file
and grep it. Ask for screenshots of the case that matters (a person's
narrow window, their real file), not only the default. Have watchers
follow the base branch's newest run when a newer merge cancels one (a
cancelled run stopped its watcher, and a ship sat waiting). Look at what
people send before publishing it or passing it on (one screenshot showed
a `/Users/<name>/…` path), and unpack archives in an empty directory.
- **`fctl autopilot brief --only sessions,people,asks`** (`?only=`)
shows only the named parts: direction, notes, asks, sessions, people,
plan, log. The whole brief had grown to about 32 KB, which every wake
read again, though its plan and log are already in the autopilot's
conversation. The briefing and wake message point to `--only`. Notes and
answers in parts it leaves out stay new, so the next whole brief or wake
still marks them.

I verified it with unit tests (the briefing's lines, parsing and
ordering the parts, a brief with two of them, the CLI's flag) and end to
end in `cargo xtask dev`. An autopilot's own session ran `fctl autopilot
brief --only sessions,asks` through the relay and got only those parts,
and the CLI and the API refuse an unknown part, naming the parts there
are. The dev stack can't show that a note left out stays new, because
fake-claude reads the whole brief at every wake; that part is a filter
on what the brief showed.

## Related pull requests

The other gaps the autopilot named, each in its own pull request:

- #546
- #545

## Not done here

- Watchers that survive a handover, for what fctl doesn't wake
autopilots for (the base branch's checks, a deploy). The merge wake in
the pull request above removes the most common one.
- `fctl send --attach` from an autopilot (#517). Since #543, an ask that
names a session sends people's files to it directly.
- `fctl run --when-free`: the briefing now says the limit's rule, and a
session ending its turn already wakes the autopilot.
- A standard place for a pull request's screenshots, and a check in
`fctl send` against IDs of other projects' sessions. An autopilot can
already message only the sessions it started.

## Worth confirming

- **Decision:** `--only` names parts rather than headings: `sessions` is
the autopilot's own, `people` is people's sessions. The lines on where
it runs (time, limit, next wake, powers) always show.

[fctl session](https://app.fctl.sh/s/ses_01M7DQEXFV9KNC4CY8ZZZ2KHZH)

<!-- FCTL_REVIEW_SUMMARY -->
---

> [!NOTE]
> **Low risk.** It adds an optional `only` filter to the autopilot brief
and extends briefing text and docs; without the filter the brief is
unchanged, and an older control plane ignores the parameter.
>
> **What it does.** Adds more lessons and a rule on which sessions count
toward an autopilot's session limit (queued, starting, working, paused
or still stopping) to its briefing, the limit's error and the docs. The
autopilot can now read its brief in parts with `fctl autopilot brief
--only sessions,asks` (and `?only=` on the API), so each wake reads
less. Unknown or empty part names are refused with an error that lists
the parts.
>
> **Partial brief and notes.** Notes and answers in parts left out by
`--only` stay new, so the next whole brief or wake still marks them.
>
> <sub>[fctl
review](https://app.fctl.sh/s/ses_01M7DTRWZ9Y28496BEBENG90M5)'s first
look at
[`0f6bff4`](0f6bff4)
· 11 files, +357 −44 · [Review agent
settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub>

<!-- /FCTL_REVIEW_SUMMARY -->

---------

Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
…message

The messaged check now applies only to a session that ended its turn,
which CREW_WORKING counts at work by messaged_at. A message to one that
stopped or failed queues it at once; one that stays stopped because its
resume failed has no turn to end, so its merge wakes the autopilot.
@kalaspuff
kalaspuff merged commit 9b8ada3 into main Nov 14, 2026
13 checks passed
@kalaspuff
kalaspuff deleted the fctl/1264-wake-on-merge branch November 14, 2026 20:35
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.

1 participant