Skip to content

fix: resume a session for messages that come as it stops - #73

Merged
kalaspuff merged 1 commit into
mainfrom
fctl/29-messages-while-stopping
Oct 18, 2026
Merged

kalaspuff merged 1 commit into
mainfrom
fctl/29-messages-while-stopping

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

When an agent stopped for being idle just as a message came, before the session object knew it was stopping, the agent left the message (a stopping agent takes no messages) and the session ended stopped with the message never handled. Nothing resumed it until someone sent another message. #67 made idle stops ten minutes apart instead of two hours, so this window comes up more often. Draining a runner (#56) stops idle sessions too, and needs this to be right.

What changes

  • A session whose agent stops on its own while messages wait in its outbox resumes for them. SessionObject sees the agent's own stop when its uplink reports stopping while the session was idle (or running). FleetDO starts the new run once the last one has ended (feat: stop idle sessions after ten minutes and resume them for a message #67), and the new run gets the messages from the outbox.
  • Messages for a session that stops wait for its next run instead of going over the uplink to the agent that stops. That agent wouldn't take them, and if it hadn't heard about the stop yet it could start a turn that the stop then interrupts. A message still resumes the session, as since feat: stop idle sessions after ten minutes and resume them for a message #67.
  • An interrupt for a session that stops, or has stopped, is dropped. There is nothing to interrupt, and an interrupt kept in the outbox would reach the next run first, where it drops the messages the agent queued before Claude was ready.
  • FleetDO marks a session stopping before it asks the host to stop it, so messages sent in between also wait for the next run.

No protocol change, no host release: control plane only.

How I verified it

cargo xtask check --quick, and end to end with cargo xtask dev and a 1-minute idle timeout:

  • The race, reproduced on main and fixed here. A script froze the host daemon (kill -STOP) 50 seconds into a session's idle minute, sent fctl send … "write race.md", and let the daemon go (kill -CONT) 75 seconds in. The message reached the session while it looked idle, and the agent stopped without taking it.
    • On main the transcript ends user 'write race.md', stopping - Stopped after being idle, stopped - Stopped after being idle, and the session stays stopped.
    • With this change it goes on: queued - Resuming, queued - Starting again once the last run has stopped, provisioning - Starting on dev-host, … and the agent handles the message.
  • Stop, then a message straight away: stopping - Stopping (FleetDO, first), stopping - Stopped (the agent), the message, queued - Resuming, Starting again once the last run has stopped, then the new run continues the same Claude conversation and handles the message. No delivery errors.
  • An interrupt for a stopped session (fctl interrupt) leaves nothing in the transcript, and the next message runs in the new run as usual.

Refs #56

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

When an agent stopped for being idle just as a message came, before the
session object knew it was stopping, the agent left the message and the
session ended stopped with the message never handled, until someone sent
another one.

- A session whose agent stops on its own while messages wait in its
  outbox resumes for them.
- Messages for a session that stops wait in the outbox for its next run
  instead of going to the agent that stops; an interrupt for one is
  dropped, since an interrupt kept for the next run could drop the
  messages that start it.
- FleetDO marks a session stopping before it asks the host to stop it,
  so messages sent meanwhile wait for the next run too.

Refs #56
@kalaspuff
kalaspuff merged commit 5574cb3 into main Oct 18, 2026
4 checks passed
@kalaspuff
kalaspuff deleted the fctl/29-messages-while-stopping branch October 18, 2026 14:33
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