Repository navigation
feat: drain runners so they take no new sessions - #74
Merged
Merged
Conversation
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
This was referenced Oct 18, 2026
5 of 7 tasks
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:   The session page's Pull requests section: | Before | After | |---|---| |  |  | ## 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was no way to take a runner out of rotation and still serve the sessions it runs.
fctl host uninstalland 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
fctl admin drain NAME/fctl admin undrain NAME(PATCH /api/v1/runners/{id}withdraining).fctl host drain [--wait]andfctl host undrain, with the runner token (POST /api/v1/runner/drain).--waitreturns once no session runs there.runner.drainedandrunner.undrained.fctl admin runners: the same, asdraining/drainedand a line.fctl host status: the runner and its sessions (GET /api/v1/runner).docs/architecture.md(Draining a runner),docs/cli.md, and ADR 0015.Compatibility
add_column.Runner.drainandUpdateRunnerRequest.draining. Older CLIs ignore them. Draining isn't a newRunnerStatus, which they would refuse.fctl host drain,undrainand the runner infctl host statusneed this release on the machine.How I verified it
fctl_domain::schedule:Wait::Drainingwhen every online runner drains.drain.cargo xtask checkpasses.cargo xtask devand a second process-driver host (dev-host-2, capacity 1), first on the branch as written and again after rebasing ontomain:fctl admin drain dev-host-2while session S idled there.fctl admin runnersshoweddrainingand "Dev Owner started draining it …: 1 session left".stopping - Stopping: dev-host-2 is draining, thenstopped, and the runner showeddrained.dev-host, thoughdev-host-2was the emptier runner.fctl send S "write drained.md"resumed S on the drainingdev-host-2, with the same Claude conversation (the samesession_idin bothinitevents), and it wrote the file.dev-host-2's config:fctl host statusshowedrunner: online, Dev Owner started draining it 1m ago: 1 session leftand the session.fctl host drain --waitprinted it and returned "✓ No sessions run here." after 58 seconds, when the drain had stopped S.fctl host undrainondev-host-2started it there. Drainingdev-hoststopped its two long-idle sessions at once.Screenshots
I took these with Playwright against
cargo xtask dev,mainbeside this branch. This session can't attach them (#40), and its sandbox's fctl (0.4.0) has nofctl publishyet, so here is what they show:dev-host-2has 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-hosthas Drain.Left for later
fctl host uninstallsaying 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