Skip to content

claude: attribute a host prompt's turn by command_lifecycle, not by the next result #308

Closed

Description

@xxchan

Found by Lookout verifying #307 (exists on main too; recorded twice against a mock provider). A host prompt() sent at the moment a background task ends (task_notification: a workflow, background Bash or a subagent) collides with the turn claude starts for that notification. Claude doesn't merge them. It runs its notification turn first (init, "The workflow finished…", result), then the host's prompt as a separate turn (init, the replayed user frame, the answer, result).

OAR today: the prompt is accepted, the notification turn's result becomes that prompt's turn_ended, and the host's real answer is reported as a spontaneous turn (turn_active). A host waiting for "my prompt's answer" gets "The workflow finished…". On main the second turn even shows idle until text arrives.

Claude's own signal: OAR writes user frames with uuid = inputId, and claude answers with command_lifecycle { command_uuid, state }. In the recording: queued (seq 58), then the notification turn, then started (seq 71), the replayed user frame with the same uuid (seq 74), and completed (seq 83). The host prompt's turn starts at started, not at the next system/init.

Change:

  • A prompt whose input carries a uuid becomes "active" only at its command_lifecycle started. A system/init/result pair before that is a spontaneous turn (turn_active … turn_ended), and does not end the prompt.
  • Without lifecycle frames (an input without a uuid, or an older claude), keep today's behaviour.
  • Fix the docs sentence "Claude omits it when a host prompt … already started the turn": the prompt was only queued.
  • Also fix the feat(claude): report workflow tasks and preserve idle status #307 docs sentence "Workflow spend arrives in a later result.modelUsage, after the agents have finished". Each call's spend appears in the first result written after that call completes, which can be the same turn's result if the agent finished first.

Tests: Lookout's collision recording as a replay fixture, plus live-vs-replay status equality.

Activity

  1. added 2 commits that reference this issue on Oct 10, 2026
    f766a4b
    2559cc8
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions