fix(truncation): honor configured output cap on truncated tool-call retry - #56619
Open
fabsch221977 wants to merge 1 commit into
Open
fabsch221977 wants to merge 1 commit into
fabsch221977 wants to merge 1 commit into
Conversation
…etry - Extract _next_truncated_tool_call_cap: pick max(configured, requested) instead of scaling from a small base. A session with max_tokens=100k no longer retries at 8k/12k when the prepared request is stale or provider-normalized to a smaller cap. - Persist synthetic assistant marker on truncated-tool-call failure before persist_session/return so the session DB records the failure reason and post-recovery replays see a consistent conversation. - Plumb max_output_tokens through custom provider normalizer -> runtime route -> _init_agent -> AIAgent constructor, and add it to the route signature so cached agents rebuild when the cap changes. Fixes the '~4000 char write truncation' loop hit on custom:hyperspace-responses with codex_responses api_mode.
teknium1
reviewed
Jul 15, 2026
teknium1
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for tracing the retry-cap behavior. The core premise still holds on current main: agent/conversation_loop.py:2021-2027 can clamp a configured 100,000-token cap to 32,768 when the prepared request retains a 4,096-token cap.
Problems
agent/conversation_loop.py:4660-4688is a sibling truncation path for routers that report incomplete tool JSON withfinish_reason='tool_calls'. It currently returns the truncation error directly, so this PR's retry-cap policy would not cover that documented case.tests/test_output_truncation_runtime.pytests the helper directly, but does not driverun_conversationthrough a truncated tool call with a configured 100,000-token cap and stale 4,096-token request cap. A production-path assertion on the retry request is needed.
Suggested changes
- Cover or deliberately unify the router-rewritten incomplete-JSON path with the bounded retry behavior.
- Add the production-path regression above; current
tests/run_agent/test_run_agent.py:4975-5003is related coverage but exercises text continuation, not this tool-call condition.
Automated hermes-sweeper review.
| shell.acp_command = None | ||
| shell.acp_args = [] | ||
| shell._credential_pool = None | ||
| shell.max_tokens = 100000 |
Collaborator
There was a problem hiding this comment.
This tests the helper directly. Please also drive run_conversation through a truncated tool call with agent.max_tokens=100000 and a stale prepared 4096-token cap, then assert the retry request uses 100000; current main's production loop clamps that case to 32768 at agent/conversation_loop.py:2021-2027.
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
Validation