Repository navigation
Description
What is wrong
A session stopped "after being idle" while its agent was in the middle of a turn, and the turn's work was cut off. The agent had started six review subagents and ended its turn to wait for them. When their reports came in, Claude Code started a turn on its own to hand them to Claude, as it does for background work (#87). Claude worked through them for twelve minutes, calling tools every few seconds. All that time fctl-agent counted the session as waiting: the session said so, and ten minutes after the last subagent ended, the idle timeout stopped it. Claude Code was waiting for an API response at the time. The transcript ends with the last tool call and "Stopped after being idle", with no "Turn finished". When the person's next message resumed it, Claude Code closed the cut-off turn with a synthetic "No response requested." message.
How it works now
From this session's journal (~/.fctl/state/journal.jsonl; fctl-agent 0.18.0, Claude Code 2.1.308, all times UTC):
- 18:52:43 A
resultends the turn that took the first subagent's report. Five subagents still run, so fctl-agent makes the session idle, "Waiting for 5 background tasks". - 18:53:12 The second subagent's
task_notificationarrives, and Claude Code starts a turn on its own:system/init,system/status(requesting), then Claude's messages and tool calls. Noresultfollows before the stop. - 18:55:10 The last subagent's
task_notificationarrives. fctl-agent says "Waiting for a message", andset_statusstarts the idle clock (idle_since). - 19:05:07 Claude Code sends its next API request. Its own transcript (
~/.claude/projects/…) records theapi-requestand no response. - 19:05:10 The last journal event. Ten minutes after 18:55:10, the idle timeout ends Claude and the host stops the sandbox.
In crates/fctl-agent/src/supervisor.rs, on_claude_message ends a turn on every result. Since #91 it notices a turn Claude starts on its own in one of two ways:
- From
session_state_changedrunning, when Claude Code reports its states (CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS). - Otherwise, from the turn's first message (
tasks::in_turn).
The first session_state_changed sets reports_turns, which turns the second way off for good. From then on, a turn Claude starts on its own counts only if Claude Code reports running for it. Here, fctl-agent saw no running for the turn that started at 18:53:12: it would have marked the session running and stopped the idle clock.
Claude Code 2.1.308 describes that message's idle as one that "fires after heldBackResult flushes and the bg-agent do-while exits — authoritative turn-over signal" (its stream-json schema). That suggests its state stays running from the turn that started the subagents until they have all reported and the last turn ends. So the results in between don't end its run, and no new running comes for the turns that take their reports.
a_turn_claude_starts_on_its_own_counts in supervisor.rs assumes the order of earlier versions:
runningtask_startedresultidle, at once, while the task still runsrunningagain for the turn that takes its report
What should happen
- fctl-agent notices a turn Claude Code starts on its own from its messages too, even when Claude Code reports its states. A
system/init, or the conversation's first message after aresult(tasks::in_turn), starts one; itsresult, oridle, ends it. - Where Claude Code reports its states, the idle clock doesn't start while its last reported state is
running, and starts once it reportsidlewith no background task left. - A test replays Claude Code 2.1.308's order of events, taken from this session's journal:
runningtask_startedfor two subagentsresulttask_notificationfor one, thensystem/initand Claude's messages, with noresultyettask_notificationfor the other- after that, the session doesn't stop for idleness
- The comment in
crates/fctl-agent/src/tasks.rsand "Idle sessions" indocs/architecture.mdsay how fctl-agent tells such turns.
Compatibility
This changes fctl-agent only, which hosts install with their own version: it needs a release, and no protocol change. Hosts and the control plane go on seeing a session that runs or waits.
Activity