Skip to content

fix(provider): thinking-mode prefill rejection + error misclassification#90

Merged
yishuiliunian merged 1 commit intomainfrom
fix/thinking-prefill-continuation
Apr 6, 2026
Merged

fix(provider): thinking-mode prefill rejection + error misclassification#90
yishuiliunian merged 1 commit intomainfrom
fix/thinking-prefill-continuation

Conversation

@yishuiliunian
Copy link
Copy Markdown
Contributor

Summary

  • Fix auto-continuation failure when thinking mode is active: Anthropic API rejects assistant-message prefill, but the turn loop sends conversation ending with assistant message on MaxTokens/PauseTurn/stream-truncation continue paths
  • Narrow ContextOverflow error detection to exclude generic invalid_request_error (was misclassifying prefill rejection as context overflow)
  • Fix stop-hook feedback appending to wrong-role message (debug_assert violation in release builds)

Changes

  • loopal-provider/anthropic/mod.rs + loopal-error/helpers.rs — remove overly broad invalid_request_error match from ContextOverflow/is_retryable
  • loopal-provider-api/thinking.rs — add ThinkingCapability::forbids_prefill() (Anthropic-only)
  • loopal-runtime/agent_loop/llm_params.rs — add needs_continuation_injection() gating on capability + thinking state
  • loopal-runtime/agent_loop/turn_continue.rsnew: push_continuation_if_thinking() + push_stop_feedback() helpers
  • loopal-runtime/agent_loop/turn_exec.rs — wire helpers into 3 continue points
  • Tests: thinking_continue_test.rs, thinking_capability_test.rs, prefill rejection error test

Test plan

  • bazel test //crates/loopal-error:loopal-error_test — error classification
  • bazel test //crates/loopal-provider-api:loopal-provider-api_test — forbids_prefill
  • bazel test //crates/loopal-runtime:loopal-runtime_test — auto-continuation + thinking
  • bazel build //... --config=clippy — zero warnings
  • bazel build //... --config=rustfmt — format check
  • CI passes

…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)
@yishuiliunian yishuiliunian merged commit 44f4ecc into main Apr 6, 2026
3 checks passed
@yishuiliunian yishuiliunian deleted the fix/thinking-prefill-continuation branch April 6, 2026 09:53
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