Repository navigation
fix(agent): keep sessions running while Claude takes subagents' reports - #217
Merged
kalaspuff merged 1 commit intoOct 22, 2026
Merged
Conversation
Claude Code 2.1.308 says `running` from the turn that starts subagents in the background until they have all reported and the last turn that takes their reports has ended, so those turns start without a `running` of their own. fctl-agent read Claude Code's state as a report of each turn, and stopped reading turns from messages once it had one: it missed those turns, said the session waited, and started the idle clock when the last subagent ended, in the middle of a turn. fctl-agent now tells a turn Claude Code starts on its own by its first message (`system/init`, or the conversation's first message after a `result`) whether or not Claude Code reports its state, and the idle clock waits for Claude Code's `idle` as well as for background tasks, an hour after the last turn at most. fake-claude says `running` as Claude Code 2.1.308 does for a subagent in the background and starts each turn with `system/init`, and the smoke test leaves a subagent working in the background too and checks that the session runs for the turns that take the results. Fixes #213
kalaspuff
approved these changes
Oct 22, 2026
kalaspuff
deleted the
fctl/143-fix-https-github-com-hyperstructure-fctl
branch
October 22, 2026 20:20
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.
Sessions stopped "after being idle" in the middle of a turn that Claude Code started on its own to hand Claude its background subagents' reports (#213).
What was wrong
fctl-agent learned of the turns Claude Code starts on its own from
system/session_state_changed(running). Since #91 it also stopped reading turns from their messages once Claude Code had reported its state. Claude Code 2.1.308 doesn't report each of those turns. From a turn that starts subagents in the background, it saysrunninguntil they have all reported and the last turn that takes their reports has ended, and only thenidle. The turns in between start withsystem/initand norunning. fctl-agent took them for waiting: when the last subagent ended mid-turn, it said "Waiting for a message" and started the idle clock, and the idle timeout stopped the session while Claude was still calling tools.Background shell commands aren't affected: 2.1.308 still says
idleafter each turn andrunningbefore the turn that takes a command's result.I captured 2.1.308's order of events by running it against a stand-in for the Messages API on localhost, with dummy credentials (
ANTHROPIC_BASE_URLin my test harness only), so nothing reached Anthropic or used anyone's plan. With two subagents in the background:Claude Code's own code says the same: its schema describes
idleas firing "after heldBackResult flushes and the bg-agent do-while exits", and it sendsrunningonly when its state wasidle.CLAUDE_CODE_BG_TASKS_REPORT_RUNNING=0brings back anidleafter each turn, but that switch is undocumented, so fctl-agent doesn't rely on it.What changed
system/init, which starts each turn, or the conversation's first message after aresult(tasks::in_turn, which now countssystem/init). Itsresultends it, oridle. 2.1.308 sends neither outside a turn: I checked that it sends nothing at startup or when it resumes a conversation, and that an interrupted turn's last messages come before itsresult.idleas well as for background tasks. A session between a subagent's last report and the turn that takes it doesn't count as idle. If Claude Code went on sayingrunningwith no turn and no task, the session stops as with background work: an hour after its last turn, or after the idle timeout when that is longer.runninguntil the turn that takes its report has ended) and starts each turn withsystem/init, socargo xtask devshows this flow.crates/fctl-agent/src/tasks.rs, "Idle sessions" in docs/architecture.md, and fake-claude and the smoke test in docs/development.md.No protocol change: hosts and the control plane see a session that runs or waits, as before. The fix reaches hosts with the next release.
How I verified it
A unit test replays 2.1.308's order above (
turns_that_take_subagents_reports_count_without_running): the session runs from the turn'ssystem/init, keeps running when the second subagent ends mid-turn, and starts the idle clock only at Claude Code'sidle. On main's code it fails where the session should run: it still says "Waiting for a background task". Two existing tests changed with the behavior, and a new one covers the hour limit.Real Claude Code 2.1.308 under fctl-agent, in
cargo xtask dev: a second runner ran the realclaudeagainst the stand-in, in a project with a one-minute idle timeout. The agent started subagents A and B in the background. The turn that took A's report ran 14 short commands over 85 seconds, and B ended 8 seconds into it.resultcargo xtask dev --smokepasses, and fails with main's fctl-agent at the new step: the session stays idle through the turns that take the command's and the subagent's results.cargo xtask checkpasses.Fixes #213
Session: https://app.fctl.sh/s/ses_01M5JGVTF2ZK9GF69TFR7VHG4J