Repository navigation
fix: one tool call per id from grokv streams; headless runs exit after the turn - #161
Merged
Merged
Conversation
…r the turn
Two bugs that made turns look stuck.
1. Tool calls split in two. grokv repeats `id` + `name` on every
chunk of a call (`{index:0,id,name,arguments:""}` then the same id
with the full arguments). ToolCallAssembler opened a new call per
start, so every call ran twice: once with empty arguments ("Missing
required parameter `path`"), auto mode retried that failure twice,
and the model got a "tool failed" nudge and an extra step. A start
whose id is already open now continues that call (a cumulative repeat
replaces the buffer). Same task against grok-4.6-cyber-high: 6 steps
/ 22-24 s with failing duplicates before, 5 steps / 11 s and zero
retries after.
2. `whycodes generate` never exited after a turn that ran bash. With no
long-lived sink, the agent parks a clone of the turn sender in its
background-job listener, so the CI event drain waited for a channel
that never closed (seen: >10 min after `turn.done`). The drain now
ends on a done signal and still flushes queued events in order.
Same run now exits 0 in 18 s with the JSON result.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
3 tasks done
mrnasil
added a commit
that referenced
this pull request
Oct 11, 2026
…ck (#162) * fix: three flaky or hanging tests, two of them real bugs 1. config: write_atomic removed the destination before the rename. Two parallel saves raced on that remove (NotFound, flaky in Coverage on #161), and a crash between remove and rename left no config.toml. rename replaces atomically on Unix and Windows (MOVEFILE_REPLACE_ EXISTING), so it is now rename-only with the one retry. Parallel-save test: 30/30 on Linux, 15/15 on Windows. 2. agent: StdinPrompter / StdinQuestionPrompter read the process stdin inside the async ask. The read blocks the runtime thread, so the tests' 2 s timeout could not cancel it; with stdin left open (a terminal or a pipe) the tests never ended and other tests queued on the stdin lock — `cargo test -p whycodes-agent` hung. The prompters take an AnswerInput (default: locked process stdin); tests pass an empty reader and still go through `ask`. With stdin held open: 3/3 runs in 32 s, was hung on the first. 3. agent: rate_limit_retries_same_model_on_next_credential and failover_api_key_walks_named_credentials both set and restore the credential env vars; run in parallel, one restored the other's vars mid-turn and the 429 failover found no second key (flaky in Coverage on #154 and #161). Both now hold CREDENTIAL_ENV_LOCK. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(config): keep write_atomic's retry on the line floor Rename-only saves no longer lose a remove race, so tests never took the 'first rename failed, retry succeeded' arm and config fell to 2406/2407. The same logic as two always-run lines: let-else on the first rename, map_err on the retry. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Merged
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.
Summary
Found while investigating "the TUI feels frozen". Two bugs made turns slow or stuck.
1. Every tool call ran twice (grokv)
Raw SSE from
grok.claude.gg(captured):OpenAI sends
id/nameonly on the first chunk; grokv repeats them.ToolCallAssembler::on_tool_useopened a new call per start, so each call became an empty-argument call ("Missing required parameterpath") plus the real one. Auto mode then retried the failure twice, and the model got a "tool failed, correct your approach" nudge and an extra LLM step. The log had 6,257auto mode retrying failed toollines.Fix: a start whose id is already open continues that call. Argument fragments append; a cumulative repeat (fragment starting with the whole buffer) replaces; an object replaces; an empty name is filled once. Parallel calls keep distinct ids.
Measured (same task,
grok-4.6-cyber-high,generate): before, 6 steps / 22–24 s with failing duplicates on every step; after, 5 steps / 11 s and 0 retries.2.
whycodes generatenever exited after using bashrun_headless_turn(and the parallelgeneratepath) awaited the CI event drain until the channel closed. Without a long-lived sink,wire_background_turn_listenerparks a clone of the turn sender in the background-job registry for the life of the agent (schedulemoves one into a delayed task), so the channel never closed. Seen live: the process sat idle for more than 10 minutes afterturn.donewithout printing its result.Fix:
spawn_event_drain/finish_event_drain. The drain ends on a done signal and still flushes queued events in order (biased select). Same run now exits 0 in 18 s with the JSON result.Test plan
tool_stream: grokv-style repeated starts for two parallel calls → 2 calls with correct args; fragments/cumulative/object/name mergeshelpers: drain ends on signal while a sender clone is alive, events in order; a self-closing channel still endsgenerateexits 0 in 18 s, tests OK🤖 Generated with Claude Code