Skip to content

fix: keep fake-claude sessions running while they answer queued messages - #85

Merged
kalaspuff merged 1 commit into
mainfrom
fctl/41-can-you-fix-https-github-com-hyperstruct
Oct 18, 2026
Merged

kalaspuff merged 1 commit into
mainfrom
fctl/41-can-you-fix-https-github-com-hyperstruct

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

In cargo xtask dev, when a message reached fake-claude while it was on a turn, the session showed idle while fake-claude answered it. After a result, fctl-agent keeps a session running when queued_turn_count is above 0; Claude Code sets it to the sends still waiting in its command queue. fake-claude answers each waiting message as a turn of its own, but its result didn't carry the field, so the session went idle after the first answer and stayed idle through the next.

Now every result fake-claude writes, errors included, carries queued_turn_count: the user turns it has read from stdin but not started. Its stdin thread counts a user turn before handing it to the main loop, and the main loop takes it off the count when the turn starts, so the count never drops below zero. The Claude Agent SDK has the field on both SDKResultSuccess and SDKResultError. fake-claude's module docs and docs/development.md describe it. fctl-agent already reads the field, so nothing that ships to hosts or the control plane changes.

Verification

  • A new test, crates/fake-claude/tests/stream_json.rs, runs the binary, writes three user turns at once and checks that the three results report 2, 1 and 0 turns waiting. Without the fix it fails ([Null, Null, Null]). It passed 60 runs out of 60, with six running at once on four CPUs.

  • cargo xtask check passes.

  • cargo xtask dev, both cases from the issue. These are from fctl logs playground#N --json, with the stream events left out.

    A message during a slow turn:

    17:40:49 user_message "slow"
    17:40:49 status running
    17:40:52 user_message "hello mid-turn"
    17:40:56 assistant "Let me think about this carefully. …"
    17:40:56 result success queued_turn_count=1
    17:40:57 assistant "I'll take a look at that. You asked: \"hello mid-turn\". …"
    17:40:57 result success queued_turn_count=0
    17:40:57 status idle "Waiting for a message"
    

    A message during a limit pause, which fctl-agent sends right after its own message when the limit resets:

    17:40:44 user_message "limit"
    17:40:45 status paused "Waiting for the usage limit to reset"
    17:40:45 result error_during_execution queued_turn_count=0
    17:40:45 user_message "hello while paused"
    17:41:35 status running "Resuming after the usage limit reset"
    17:41:36 assistant "I'll take a look at that. You asked: \"The usage limit has r…"
    17:41:37 result success queued_turn_count=1
    17:41:37 assistant "I'll take a look at that. You asked: \"hello while paused\". …"
    17:41:37 result success queued_turn_count=0
    17:41:37 status idle "Waiting for a message"
    

    In the issue's transcript, status idle came between the two answers.

  • I also sent an interrupt during a slow turn while a message waited. The interrupted turn's result reported 1, fake-claude answered the message, and only then did the session go idle.

Fixes #63

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

fake-claude answers each user turn that arrives during another as a turn
of its own, but its result didn't say any were waiting. fctl-agent keeps
a session running while a result's queued_turn_count is above 0, as
Claude Code sets it, so dev sessions showed idle while fake-claude
answered a message sent during a turn.

Each result now counts the user turns read from stdin that haven't
started. A test drives the binary with three turns at once.

Refs #63
@kalaspuff
kalaspuff merged commit 6f58dff into main Oct 18, 2026
4 checks passed
@kalaspuff
kalaspuff deleted the fctl/41-can-you-fix-https-github-com-hyperstruct branch October 18, 2026 17:56
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.

fake-claude doesn't report queued turns, so dev sessions look idle while answering

1 participant