Skip to content

feat: drain runners so they take no new sessions - #74

Merged
kalaspuff merged 4 commits into
mainfrom
fctl/29-drain-runners
Oct 18, 2026
Merged

kalaspuff merged 4 commits into
mainfrom
fctl/29-drain-runners

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

There was no way to take a runner out of rotation and still serve the sessions it runs. fctl host uninstall and disabling the runner both cut it off: its agents kept working in their sandboxes, nothing of it reached the app, and ten minutes later the sessions showed as stopped. This adds draining, the first two items of #56, as decided there.

What changes

  • A draining runner takes no new sessions, and the sessions it has carry on there. FleetDO places new sessions on runners that don't drain. When every runner online drains, a queued session says "Waiting for a runner: the ones online are draining".
  • Resumes still go back to it. A follow-up to a session whose sandbox is on a draining runner resumes there (feat: stop idle sessions after ten minutes and resume them for a message #67), with Claude's conversation and no new sandbox.
  • Its idle sessions stop after a minute, rather than after their idle timeout, so a draining runner is empty whenever no turn runs. FleetDO asks each idle session it sees in the runner's heartbeats. SessionObject agrees only when no message is on its way to the agent, and marks the session stopping in the same step, so a message that comes later waits for the next run (fix: resume a session for messages that come as it stops #73). The transcript shows "Stopping: dev-host-2 is draining"; older hosts know no stop reason for this, so the last status reads "Stopped after being idle".
  • Who drains, from where:
    • Admins: Drain / Stop draining in the runners list, and fctl admin drain NAME / fctl admin undrain NAME (PATCH /api/v1/runners/{id} with draining).
    • The machine: fctl host drain [--wait] and fctl host undrain, with the runner token (POST /api/v1/runner/drain). --wait returns once no session runs there.
    • It is one state, kept in FleetDO's storage with who started the drain and when; either side can end it. The audit log records runner.drained and runner.undrained.
  • Showing it:
    • The runners list: a "draining" or "drained" label, an amber dot, and "Dev Owner started draining it 3 minutes ago: no new sessions start on it, and 1 session still runs."
    • fctl admin runners: the same, as draining / drained and a line.
    • fctl host status: the runner and its sessions (GET /api/v1/runner).
    • The floor: "2 runners online, 1 draining".
  • Disable and Remove ask first. Remove always asks, and Disable asks when sessions run. When sessions run, the dialog says what happens to them and offers Drain instead. Remove used to delete a runner on one click.
  • On phones the runner actions now sit under the runner's details; three actions squeezed the text into a narrow column.
  • Docs: docs/architecture.md (Draining a runner), docs/cli.md, and ADR 0015.

Compatibility

  • No migration and no change to the WebSocket protocols. FleetDO's new columns are added with add_column.
  • New optional API fields: Runner.drain and UpdateRunnerRequest.draining. Older CLIs ignore them. Draining isn't a new RunnerStatus, which they would refuse.
  • Hosts: draining works with hosts as they are. The control plane stops their idle sessions with the existing idle stop. Only fctl host drain, undrain and the runner in fctl host status need this release on the machine.
  • Privacy: FleetDO keeps the name and id of the admin who started a drain while the runner drains, and the runners list shows them to admins, as it shows who registered a runner. fctl.sh's privacy policy needs no change.

How I verified it

  • Unit tests in fctl_domain::schedule:
    • A draining runner takes only resumes of its own sessions.
    • New sessions go elsewhere.
    • A session waits with Wait::Draining when every online runner drains.
  • A protocol test: runners from older control planes have no drain.
  • cargo xtask check passes.
  • End to end with cargo xtask dev and a second process-driver host (dev-host-2, capacity 1), first on the branch as written and again after rebasing onto main:
    1. fctl admin drain dev-host-2 while session S idled there.
      • fctl admin runners showed draining and "Dev Owner started draining it …: 1 session left".
      • About 75 seconds after S went idle, its transcript showed stopping - Stopping: dev-host-2 is draining, then stopped, and the runner showed drained.
    2. A new session went to dev-host, though dev-host-2 was the emptier runner.
    3. fctl send S "write drained.md" resumed S on the draining dev-host-2, with the same Claude conversation (the same session_id in both init events), and it wrote the file.
    4. On dev-host-2's config:
      • fctl host status showed runner: online, Dev Owner started draining it 1m ago: 1 session left and the session.
      • fctl host drain --wait printed it and returned "✓ No sessions run here." after 58 seconds, when the drain had stopped S.
    5. With both runners draining, a new session waited with "Waiting for a runner: the ones online are draining". fctl host undrain on dev-host-2 started it there. Draining dev-host stopped its two long-idle sessions at once.
    6. In the web app:
      • Drain and Stop draining work.
      • The Disable dialog offers Drain instead for a runner with a session.
      • The Remove dialog shows the same warning.
      • The floor reads "2 runners online, 1 draining".

Screenshots

I took these with Playwright against cargo xtask dev, main beside this branch. This session can't attach them (#40), and its sandbox's fctl (0.4.0) has no fctl publish yet, so here is what they show:

  • Runners list (Admin → Runners), 1440 px, both themes.
    • Before, each runner has Disable and the bin.
    • After, the draining dev-host-2 has an amber dot, "draining" beside its name, the line "Dev Owner started draining it 3 minutes ago: no new sessions start on it, and 1 session still runs.", and Stop draining, Disable and the bin. dev-host has Drain.
  • At 390 px: before, the details sat beside Disable; after, the actions are under the details.
  • Disable dialog (a runner with one session, not draining): "Disable dev-host-2? It disconnects at once and can't connect again until you enable it." The warning reads "A session runs on it. Its agent keeps working in its sandbox without reaching fctl, and the session stops after ten minutes. Drain it instead to let it finish: no new sessions start on it meanwhile." Buttons: Cancel, Drain instead, Disable.
  • Remove dialog: "Remove dev-host-2? Its token stops working: the machine has to be registered again to run sessions.", with the same warning when sessions run.
  • Floor: "1 session is waiting for you · 2 runners online, 1 draining".

Left for later

fctl host uninstall saying what happens to the sessions on the host, asking first, and stopping them properly (the third item of #56) comes in the next pull request.

Refs #56

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

fctl-sh Bot added 4 commits October 18, 2026 14:39
A draining runner takes no new sessions, and the sessions it has carry
on there: resumes of sessions whose sandbox it has still go back to it.
Its idle sessions stop once they have waited a minute, so it empties
whenever no turn runs, and a message resumes them there.

- Admins drain a runner from the runners list (Drain, Stop draining)
  and with fctl admin drain/undrain; its host drains itself with
  fctl host drain [--wait] and fctl host undrain, with the runner token.
- The runners list, fctl admin runners and fctl host status show a
  draining runner, who drained it and when, and the sessions left.
- Disable and Remove in the runners list ask first, and point to Drain
  when sessions run.

Refs #56
@kalaspuff
kalaspuff merged commit ec87cce into main Oct 18, 2026
4 checks passed
@kalaspuff
kalaspuff deleted the fctl/29-drain-runners branch October 18, 2026 15:59
kalaspuff pushed a commit that referenced this pull request Oct 31, 2026
## Summary

A session with many pull requests listed them in the order its agent
found them, so the row in session lists, which cuts off what doesn't
fit, could show only merged ones, and the rail's Pull requests section
put the open ones at the bottom. Now open, draft and queued pull
requests come first, then those whose state nobody has looked up yet,
then merged and closed ones. Each group keeps the order the agent found
them in. The session header's list of links uses the same order, since
all three take it from the same function.

I added a unit test for the order, ran `npm run check`, and looked at a
dev session with ten pull requests in mixed states, staged in its
SQLite, against `main`'s web app and this branch's.

## Screenshots

At 8051709, dark theme. The row in the project's session list, before
and after:

![Before: the row shows merged playground#72, #58, #59 and
#60](https://app.fctl.sh/api/v1/published/6LEmb7ECkKM3Hzk64T0ez4PHCQDWxyk9qkFeD9HAze6/before-row.png)

![After: the row shows open #74, draft #75, queued #73 and #76, whose
state isn't known
yet](https://app.fctl.sh/api/v1/published/TklVAQfGRDRnVTnvFkn7At2OTeveure74E26S8YFHzD/after-row.png)

The session page's Pull requests section:

| Before | After |
|---|---|
| ![Before: six merged and closed pull requests above the open, draft
and queued
ones](https://app.fctl.sh/api/v1/published/crf3daCylMT0PsXwM8As9nzWvj6kie5kCOQRSKUQ3yq/before-rail.png)
| ![After: open, draft and queued at the top, merged and closed at the
bottom](https://app.fctl.sh/api/v1/published/MUktZKgORZgWnAZD2zhYsOHUAJZSGcEQk2EunjMehgC/after-rail.png)
|

## Worth confirming

- **Decision:** Pull requests whose state fctl doesn't know yet (nobody
has looked them up on GitHub) come after open, draft and queued ones and
before merged and closed ones, because they are usually new and so
likely still open.
- **Decision:** Within each group the order stays the one the agent
found them in, not most recent first.

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

<!-- FCTL_REVIEW_SUMMARY -->
---

> [!NOTE]
> **Low risk.** It only changes the order in which the web app lists a
session's pull requests, with a unit test; no data or API changes.
>
> **What it does.** `pullRequests` now lists a session's open, draft and
queued pull requests first, then those not yet looked up, then merged
and closed ones, each group in the order the agent found them. Sessions
with many pull requests therefore keep the ones still under way visible
when a list cuts off its end.
>
> <sub>[fctl
review](https://app.fctl.sh/s/ses_01M67NF732Z1C722BJ2SRBWNJB)'s first
look at
[`8051709`](8051709)
· 2 files, +32 −3 · [Review agent
settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub>

<!-- /FCTL_REVIEW_SUMMARY -->

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
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