fix: use structured reasoning field directly for thinking models - #4467
Closed
djt71 wants to merge 1 commit into
Closed
fix: use structured reasoning field directly for thinking models#4467djt71 wants to merge 1 commit into
djt71 wants to merge 1 commit into
Conversation
Thinking models (Kimi K2.5, DeepSeek-R1, etc.) consistently return their full response in the reasoning_content API field with an empty content field. The existing empty-content retry loop wastes 3 API calls per response before falling back to the reasoning text — retrying doesn't change deterministic model behavior. This adds an early exit: when the structured reasoning_content or reasoning field is populated (not inline <think> tags), use it immediately as the response instead of retrying. Also changes the macOS LaunchAgent KeepAlive from conditional (SuccessfulExit: false) to unconditional (true), so the gateway restarts after clean exits — not just crashes. Tested with Kimi K2.5 via OpenRouter over a 48-hour soak test where 28 think-block warnings and 22 wasted retry API calls were observed before the fix. After the fix: zero retries, correct response on first call. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Thanks for the detailed investigation and soak test data — that's solid work. However, the empty-content behavior from thinking models isn't deterministic — retrying can and does produce proper responses with content in the Closing this one, but appreciate the contribution! |
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
reasoning_contentAPI field with an emptycontentfield. The existing empty-content retry loop wastes 3 API calls per response before falling back to the reasoning text — retrying doesn't change deterministic model behavior.reasoning_contentorreasoningfield is populated (distinct from inline<think>tags in content), use it immediately as the response.KeepAlivefrom conditional (SuccessfulExit: false) to unconditional (true), so the gateway restarts after clean exits — not just crashes.Context
Discovered during a 48-hour soak test running Kimi K2.5 via OpenRouter as a cron-driven orchestrator. Analytical prompts (read a file + summarize findings) triggered the issue on nearly every execution:
The existing
#3444fix (thinking-budget exhaustion detection) and#3010(GLM reasoning-only handling) address related thinking-model edge cases but don't cover this specific pattern: a populatedreasoning_contentAPI field with emptycontent.Before
After
Test plan
python -c "import py_compile; py_compile.compile('run_agent.py', doraise=True)"passesreasoning_contentfield pattern expected)reasoning_contentfield → skip early exit, reach existing retry path as before)🤖 Generated with Claude Code