fix(provider): thinking-mode prefill rejection + error misclassification#90
Merged
yishuiliunian merged 1 commit intomainfrom Apr 6, 2026
Merged
Conversation
…ror misclassification (#89) When thinking mode is active, Anthropic's API rejects assistant-message prefill ("conversation must end with a user message"). The auto-continuation flow in turn_exec records an assistant message then loops back, violating this constraint. The error was also misclassified as ContextOverflow because `invalid_request_error` matched too broadly. - Narrow ContextOverflow detection to exclude generic `invalid_request_error` - Add `ThinkingCapability::forbids_prefill()` (true only for Anthropic) - Add `needs_continuation_injection()` gating on capability + thinking state - Inject synthetic user message at all 3 continue points when needed - Fix stop-hook feedback path: create proper User message instead of appending to (wrong-role) last message via `append_warnings_to_last_user` - Preserve assistant-prefill for non-Anthropic providers (OpenAI, Google)
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
invalid_request_error(was misclassifying prefill rejection as context overflow)debug_assertviolation in release builds)Changes
loopal-provider/anthropic/mod.rs+loopal-error/helpers.rs— remove overly broadinvalid_request_errormatch from ContextOverflow/is_retryableloopal-provider-api/thinking.rs— addThinkingCapability::forbids_prefill()(Anthropic-only)loopal-runtime/agent_loop/llm_params.rs— addneeds_continuation_injection()gating on capability + thinking stateloopal-runtime/agent_loop/turn_continue.rs— new:push_continuation_if_thinking()+push_stop_feedback()helpersloopal-runtime/agent_loop/turn_exec.rs— wire helpers into 3 continue pointsthinking_continue_test.rs,thinking_capability_test.rs, prefill rejection error testTest plan
bazel test //crates/loopal-error:loopal-error_test— error classificationbazel test //crates/loopal-provider-api:loopal-provider-api_test— forbids_prefillbazel test //crates/loopal-runtime:loopal-runtime_test— auto-continuation + thinkingbazel build //... --config=clippy— zero warningsbazel build //... --config=rustfmt— format check