Skip to content

feat: ask before fctl host uninstall stops the sessions on a host - #75

Merged
kalaspuff merged 7 commits into
mainfrom
fctl/29-uninstall-host
Oct 18, 2026
Merged

kalaspuff merged 7 commits into
mainfrom
fctl/29-uninstall-host

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

fctl host uninstall stopped the host's service and said "Configuration and sandboxes are kept", with nothing about the sessions that ran there. Agents are detached from the host on purpose, so uninstalling left them working in their sandboxes without reaching fctl. Ten minutes later their sessions showed as stopped, and a follow-up could then resume one on another runner while its old agent was still at work. This is the third item of #56, as decided there.

What changes

  • No sessions on the host: fctl host uninstall works as before.
  • Sessions on the host: it lists them, says what happens to them, and asks before it stops them ("Stop them and uninstall now? [y/N]"). Without a terminal it refuses unless given one of:
    • --wait: drain the runner, wait until no session runs there, then uninstall.
    • --force: stop the sessions now, then uninstall.
  • Stopping goes through the control plane. POST /api/v1/runner/drain gains stop_sessions, sent with the runner token. FleetDO then:
    • marks each session "Stopping: studio is being uninstalled";
    • asks the host to stop it (StopReason::Shutdown), so its agent pushes its work, and the session shows as stopped right away;
    • forgets the runner as the home of every session whose sandbox it has, so a message resumes them on another runner rather than on a host that is going away.
  • A host that isn't connected: FleetDO stops its sessions at once ("Stopped: studio was uninstalled. A message resumes the session on another runner."), and the CLI stops the sandboxes on the machine with the driver.
  • When the control plane can't be reached: the CLI refuses while sandboxes of sessions still run on the machine, unless given --force.
  • The runner keeps draining after an uninstall, and the CLI says so: after installing the host again, fctl host undrain lets it take sessions.
  • Docs: docs/cli.md, docs/architecture.md (Draining a runner), ADR 0016, and docs/self-hosting.md, which now uninstalls the hosts before deleting the control plane, so that their sessions still stop properly.

Compatibility

  • DrainRequest.stop_sessions is a new optional field. Hosts and agents need no change: stopping uses the existing StopSession.
  • The new fctl host uninstall needs a control plane with feat: drain runners so they take no new sessions #74 and this change. Against an older one, it can't ask which sessions run, and refuses while sandboxes of sessions run on the machine, unless given --force.
  • Scripts: those that ran fctl host uninstall while sessions ran now fail until they choose --wait or --force.

How I verified it

cargo xtask check passes. End to end with cargo xtask dev and a second process-driver host (dev-host-2), running the CLI with its config:

  1. No sessions on the host: it uninstalled right away.
  2. One idle session on the host:
    • Without a terminal: it listed the session and failed with "1 session runs on this host. fctl host uninstall --wait lets it finish first; --force stops it now." (exit 1).
    • In a terminal, answering n: "Nothing changed. fctl host uninstall --wait lets it finish first."
  3. --force:
    • "Stopping…", "✓ No sessions run here.", then the uninstall.
    • The transcript showed stopping - Stopping: dev-host-2 is being uninstalled, then stopped - Stopped because the host is shutting down.
    • A message to the session then resumed it on dev-host, in a new sandbox ("The earlier conversation went with the old sandbox").
  4. --wait: it drained the host, waited 67 seconds for the idle session to stop, then uninstalled.
  5. dev-host-2's daemon killed (the runner offline) while its session's agent still ran, then --force:
    • The session showed "Stopped: dev-host-2 was uninstalled. A message resumes the session on another runner."
    • The CLI stopped the leftover sandbox, and its fctl-agent process was gone.

Refs #56

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

fctl-sh Bot added 6 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
…ost, and ask

fctl host uninstall used to stop the host's service and leave the
sessions it ran to their agents, which kept working in their sandboxes
without reaching fctl until the control plane gave up on them.

- With sessions running, it lists them, says what happens to them, and
  asks before stopping them. Without a terminal it refuses unless given
  --wait (drain the host and uninstall once none runs) or --force.
- Stopping goes through the control plane (POST /api/v1/runner/drain
  with stop_sessions): their agents stop and push their work, the
  sessions show that their host is being uninstalled, and FleetDO forgets
  the runner as their home, so a message resumes them on another runner.
- A host that isn't connected gets its sessions stopped by the control
  plane at once, and the sandboxes here stopped by the driver.

Refs #56
Base automatically changed from fctl/29-drain-runners to main October 18, 2026 15:59
# Conflicts:
#	crates/fctl-client/src/api.rs
#	crates/fctl-control/src/api/runners.rs
#	crates/fctl-control/src/do_fleet.rs
#	crates/fctl-control/src/internal.rs
#	crates/fctl-proto/src/api.rs
#	crates/fctl/src/cmd/host.rs
#	docs/adr/README.md
#	docs/architecture.md
#	docs/cli.md
#	web/src/gen/DrainRequest.ts
@kalaspuff
kalaspuff merged commit fb77024 into main Oct 18, 2026
5 checks passed
@kalaspuff
kalaspuff deleted the fctl/29-uninstall-host branch October 18, 2026 16:06
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