Skip to content

fix: halt stream on terminal AssistantMessage errors#52

Merged
guess merged 1 commit into
mainfrom
fix/terminal-error-infinite-loop
May 22, 2026
Merged

fix: halt stream on terminal AssistantMessage errors#52
guess merged 1 commit into
mainfrom
fix/terminal-error-infinite-loop

Conversation

@guess

@guess guess commented May 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • When the CLI hits an unrecoverable error (rate limit, auth failure, billing), it enters an infinite loop emitting synthetic UserMessage/AssistantMessage pairs. The SDK stream never terminates because it only halts on ResultMessage.
  • Detect AssistantMessage with a non-nil error field and synthesize a ResultMessage with is_error: true, preserving the error type as subtype and the error text as result.
  • All existing consumers (query/2, final_text/1, collect/1) handle the synthesized error result correctly with no changes needed.

Closes #49

Test plan

  • New test: RateLimitLoopAdapter simulates 10 iterations of the rate-limit loop, asserts stream terminates with %ResultMessage{is_error: true, subtype: :rate_limit}
  • New test: BillingErrorAdapter verifies other error types also terminate correctly
  • Full test suite passes (1493 tests, 0 failures)
  • mix quality passes (compile, format, credo, dialyzer)

When the CLI encounters an unrecoverable error (rate limit, auth failure,
billing), it enters an infinite loop emitting synthetic UserMessage/
AssistantMessage pairs. The stream never terminates because it only halts
on ResultMessage.

Detect AssistantMessage with a non-nil error field and synthesize a
ResultMessage with is_error: true, preserving the error type as subtype
and the error text as result. This ensures all existing consumers
(query/2, final_text/1, collect/1) handle the error correctly.

Closes #49
@guess
guess merged commit ce727de into main May 22, 2026
2 checks passed
@guess
guess deleted the fix/terminal-error-infinite-loop branch May 22, 2026 17:15
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.

Infinite loop when cluade is out of tokens and using Strucuted Output

1 participant