claude harness: end the turn on the SDK's command lifecycle, not a result-per-prompt count - #945
Open
ReganBell wants to merge 1 commit into
Open
claude harness: end the turn on the SDK's command lifecycle, not a result-per-prompt count#945ReganBell wants to merge 1 commit into
ReganBell wants to merge 1 commit into
Conversation
…sult-per-prompt count A steer pushed while the Claude Agent SDK is mid-turn is folded into the running turn at the next tool boundary and shares that turn's single `result` message. The harness counted one `result` per prompt it pushed, so after a folded steer it waited for a second result that never came, sat idle until the turn wall clock fired, and surfaced "Claude turn exceeded Ns wall clock" to the user in place of the reply it had already streamed. With no wall clock configured the turn hung until the run reaper. Stamp every pushed user message with a uuid and track completion through the SDK's `command_lifecycle` events (advertised as the `msg_lifecycle_v1` capability on init): the turn ends when every command the harness pushed has reached a terminal state, whether it ran as its own turn or was folded into an earlier one. CLIs that do not advertise the capability keep the old one-result-per-prompt accounting through the same settle path. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Problem
Users on the Claude harness were seeing
I hit an error and couldn't finish — Claude turn exceeded 2000s wall clock(or whateverTURN_WALL_CLOCK_SECis set to) on turns that had in fact already produced their reply. With no wall clock configured the same turns hung until the run reaper.The trigger is a mid-turn steer. The Claude Agent SDK runs Claude Code as a child process with a streaming input queue. A user message pushed while a turn is in flight is folded into that running turn at the next tool boundary and shares its single
resultmessage. The harness assumed oneresultper prompt it pushed (pendingPrompts), so after a folded steer it waited for a secondresultthat never came, idled until the wall clock fired, and threw the wall-clock error in place of the reply it had already streamed.Verified against the real SDK (0.3.211 / CLI 2.1.259):
result, harness hungresults, harness fineFix
The SDK emits
command_lifecycleevents (queued→started→completed/cancelled) for every uuid-stamped inbound user message and advertises this as themsg_lifecycle_v1capability onsystem/init. The harness now:uuidinitdoes not advertise the capability (older CLIs)Tests
Agentsubagent call; the steer was absorbed into the reply and the turn returned in ~15s.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.