Skip to content

fix(cli, query): Reset retry counter on first successful event#492

Merged
JeanMertz merged 1 commit intomainfrom
prr59
Mar 27, 2026
Merged

fix(cli, query): Reset retry counter on first successful event#492
JeanMertz merged 1 commit intomainfrom
prr59

Conversation

@JeanMertz
Copy link
Copy Markdown
Collaborator

Previously, StreamRetryState::reset() was called only when a streaming cycle completed with Event::Finished. This meant a stream that emitted content and then hit a rate limit mid-response — before ever reaching Finished — would permanently consume the retry budget. On a second identical mid-stream failure, the budget would be exhausted and jp would hard-fail even though each attempt successfully produced output.

The fix introduces a received_provider_event flag in the turn loop's inner streaming cycle. The retry counter now resets on the very first successful event in a new streaming cycle, ensuring partial-but-retried streams don't accumulate against the budget. A new integration test (test_retry_counter_resets_on_successful_event) verifies the scenario with max_retries = 1 and two mid-stream failures followed by success.

On TTY terminals, retry notifications now also overwrite in-place using \r\x1b[K rather than printing a new line per attempt. The notification line is erased when the first successful event arrives or when a fatal error is printed, preventing stale status text from lingering on screen.

Previously, `StreamRetryState::reset()` was called only when a streaming
cycle completed with `Event::Finished`. This meant a stream that emitted
content and then hit a rate limit mid-response — before ever reaching
`Finished` — would permanently consume the retry budget. On a second
identical mid-stream failure, the budget would be exhausted and jp would
hard-fail even though each attempt successfully produced output.

The fix introduces a `received_provider_event` flag in the turn loop's
inner streaming cycle. The retry counter now resets on the very first
successful event in a new streaming cycle, ensuring partial-but-retried
streams don't accumulate against the budget. A new integration test
(`test_retry_counter_resets_on_successful_event`) verifies the scenario
with `max_retries = 1` and two mid-stream failures followed by success.

On TTY terminals, retry notifications now also overwrite in-place using
`\r\x1b[K` rather than printing a new line per attempt. The notification
line is erased when the first successful event arrives or when a fatal
error is printed, preventing stale status text from lingering on screen.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
@JeanMertz JeanMertz merged commit 98e7588 into main Mar 27, 2026
12 checks passed
@JeanMertz JeanMertz deleted the prr59 branch March 27, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant