Skip to content

Sessions stop as idle in the middle of a turn Claude starts for background work's results #213

Closed

Description

@fctl-sh

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 result ends 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_notification arrives, and Claude Code starts a turn on its own: system/init, system/status (requesting), then Claude's messages and tool calls. No result follows before the stop.
  • 18:55:10 The last subagent's task_notification arrives. fctl-agent says "Waiting for a message", and set_status starts the idle clock (idle_since).
  • 19:05:07 Claude Code sends its next API request. Its own transcript (~/.claude/projects/…) records the api-request and 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_changed running, 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:

  1. running
  2. task_started
  3. result
  4. idle, at once, while the task still runs
  5. running again 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 a result (tasks::in_turn), starts one; its result, or idle, 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 reports idle with no background task left.
  • A test replays Claude Code 2.1.308's order of events, taken from this session's journal:
    1. running
    2. task_started for two subagents
    3. result
    4. task_notification for one, then system/init and Claude's messages, with no result yet
    5. task_notification for the other
    6. after that, the session doesn't stop for idleness
  • The comment in crates/fctl-agent/src/tasks.rs and "Idle sessions" in docs/architecture.md say 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.

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

Activity

  1. added
    bug
    agents
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentsbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions