Skip to content

fix(control): keep events that newer ones overtook after a reconnect - #70

Merged
kalaspuff merged 2 commits into
mainfrom
fctl/30-keep-replayed-events
Oct 18, 2026
Merged

kalaspuff merged 2 commits into
mainfrom
fctl/30-keep-replayed-events

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

Testing #69 I froze a session's fctl-agent in the middle of a tool call and let it go again, and the tool's result never reached the transcript, though it was in the agent's journal and the journal replayed it. Events that newer ones overtook after a reconnect were dropped for good.

Why. When the host's link to fctl-agent breaks, the events the agent sends over it are lost and come again with the replay the host asks for on the next link. But the agent sends new events over a new link as soon as it connects, and the host's Replay arrives a moment later. So SessionDO got, say, events 9 and 10 live, then 8, 9 and 10 from the replay. It stored 9 and 10, moved the acknowledged agent_seq to 10, and skipped the replayed 8 as already stored. Its acknowledgement also told the agent it could drop 8 from its journal. The same happens when an uplink reconnects during a turn, which every deploy does: the uplink drops the events it can't send, the Welcome brings a replay, and newer events can overtake it.

What changed. SessionDO stores events in agent_seq order (fctl_domain::journal). An event that skips ahead is not stored or acknowledged: it waits for the replay that follows every reconnect, which brings the missing events and then it again. Every fctl-agent numbers its events one after another, and a resumed session's new sandbox starts right after what SessionDO has, so a skip means lost events. Should they never come, because a journal has lost them, SessionDO stops waiting after a minute and goes on without them, so the transcript doesn't stop for good. Both cases are logged.

The control plane alone fixes it, for every host and agent already out there. An agent that held new events until the host's Replay would avoid sending them twice, but it would reach sandboxes only as their agents restart.

How I verified it

  • Unit tests: journal::tests.
  • cargo xtask check --quick.
  • Against cargo xtask dev, playing a host's side of a session's uplink with a script while the dev host was stopped (SIGSTOP), so it didn't take the uplink back: with 11 events stored, the script sent events 13 and 14, as a new link does before the replay, then the replay of 12, 13 and 14.
    • Before (feat: show when a session's runner is away or can't reach its agent #69's branch, which handles events as main does): SessionDO stored 13 and 14 and acknowledged 14; 12 was lost.
    • After: it acknowledged 11 until the replay, then stored 12, 13 and 14 in order, and logged agent_seq 13 came before 12: waiting for the host's replay.
    • A gap that never fills: 13 and 14, then a minute later 15 alone. SessionDO stored 15 and logged agent_seq 12 to 14 never came; going on without them.
  • In feat: show when a session's runner is away or can't reach its agent #69's testing, five disruptions (an agent frozen for four minutes, a host killed, a host frozen three times) lost one event this way: the result of the tool call the agent was frozen in.

Refs #46

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

fctl-sh Bot added 2 commits October 18, 2026 14:12
After a link to the agent or an uplink closed, the agent could send newer
events over the new link before the host's replay of the older ones. SessionDO
stored the newer ones, acknowledged them, and then dropped the replayed older
ones as already stored, so they never reached the transcript, and the agent's
journal was told it could forget them.

SessionDO now stores events in agent_seq order: one that skips ahead waits for
the replay that follows every reconnect, for at most a minute, so that a
journal that lost events can't stop the transcript for good.

Refs #46
@kalaspuff
kalaspuff merged commit 55bb555 into main Oct 18, 2026
4 checks passed
@kalaspuff
kalaspuff deleted the fctl/30-keep-replayed-events branch October 18, 2026 14:17
kalaspuff pushed a commit that referenced this pull request Nov 11, 2026
#511)

## Summary

An autopilot now looks after the sessions people start in its project
(or workspace) too, not only its own. Its brief (`fctl autopilot brief`)
gains a *People's sessions* section: the ones at work and the ones
resting with a pull request still open, with who started each, how long
ago its agent last worked and how its pull requests' checks stand. Its
wake messages carry the ones that ended a turn with a pull request open,
without waking it for them. The briefing tells it those sessions are
theirs (it never messages, stops or takes one over), to plan around
them, and once one looks ready or stuck, to ask people with `fctl
autopilot ask` whether it should help get it merged; if they say yes, it
starts a session of its own to bring the pull request up to date,
resolve conflicts, get checks passing and merge it (or ask people to
merge it, without the merge power), and notes the answer in its plan so
it doesn't ask again. Review agents' and archived sessions stay out.

An autopilot's own session now opens its sidebar (the details sheet on a
phone) with the autopilot, as its tab shows it: where it stands, with
*Wake now* / *Pause* / *Resume* for those who steer it and what it asks
(each opens the tab to answer), its plan with its progress, and the
sessions it started. In an earlier session of its own it says which one
fctl wakes it in now. Changes show only once that session changed
something, and the retrospective and memory sections stay out there. The
tab's "Updated now ago" now says "Updated just now".

I checked it in `cargo xtask dev`: a person's session with an open pull
request (set in local D1, as dev has no GitHub) showed in the
autopilot's brief while one without stayed out; another ending a turn
with a failing check showed in the next wake message (below); and the
screenshots are from the autopilot's own session there. `cargo xtask
check --quick` passes, with new tests for the brief, the wake message,
the briefing, the pull request lines and the session page.

```text
People's sessions that ended a turn with a pull request open (theirs: ask people before you help get one merged):

- playground#2 “Gift cards”, Dev Owner's: ended its turn just now; pull request #70 (open, 1 check failed)
```

## Screenshots

An autopilot's own session's sidebar, before (Changes, Retrospective and
Memory, all empty) and after:


![before-rail-dark-top.png](https://app.fctl.sh/api/v1/published/EjBdup8e2zAKnIcT7aKtu4z8ESPhpj5Z9aTNGmqfhf3/before-rail-dark-top.png)
![after-rail-dark-top.png](https://app.fctl.sh/api/v1/published/MpWv9tiz6Ftvx0nvsz1F5xnrIr9RKRSJawyJFle1zWW/after-rail-dark-top.png)

The light theme, and the details sheet on a phone:


![after-rail-light-top.png](https://app.fctl.sh/api/v1/published/pRwnIvvu5SyROFStkc1zXcKV8FjREEwMa7GeCpwPAcz/after-rail-light-top.png)
![after-phone-dark.png](https://app.fctl.sh/api/v1/published/JR8k6gf8s8BM3LyGEdDzUkpEeAa2gk4EJcwiQwSrYeE/after-phone-dark.png)

## Worth confirming

- **Decision:** The autopilot always asks before it helps with someone
else's pull request, and helps through a session of its own on its
owner's subscription rather than by messaging the person's session,
which would spend that person's plan and steer a session it didn't
start.
- **Decision:** People's sessions don't wake the autopilot; they come
with its next wake (at the latest its check-in), as you said it should
look "occasionally".
- **Decision:** Its asks still notify the people who follow its own
session (its owner among them), not the person who started the session
it asks about.
- **Decision:** The sidebar shows the plan and its sessions but not its
direction, notes or log, which stay a click away on its tab (↗ in the
card's corner), to keep the sidebar short.

The design docs for the sidebar:

- hyperstructure/design#43

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

<!-- FCTL_REVIEW_SUMMARY -->
---

> [!NOTE]
> **Medium risk.** It changes what an autopilot's brief, wake messages
and briefing tell the agent, so its behavior toward people's sessions
and pull requests changes, and adds new SQL over sessions; the web part
is a contained UI addition.
>
> **What it does.** An autopilot now lists the sessions people start in
its project or workspace (at work, or resting with a pull request open)
in its brief and wake messages, and its briefing tells it to ask people
before helping get such a pull request merged. An autopilot's own
session now shows its autopilot, plan and sessions in the details rail,
reusing the controls from its Autopilot tab, and the plan's update time
now reads "just now" rather than "now ago".
>
> **Autopilot briefing.** The briefing now instructs autopilots to look
after people's pull requests and ask before starting sessions to merge
them.
>
> <sub>[fctl
review](https://app.fctl.sh/s/ses_01M756GF3HQSDW9NF5NBEBY3X5)'s first
look at
[`f667e44`](f667e44)
· 16 files, +901 −140 · [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