Skip to content

fix(truncation): honor configured output cap on truncated tool-call retry - #56619

Open
fabsch221977 wants to merge 1 commit into
NousResearch:mainfrom
fabsch221977:fix/output-truncation-runtime-cap
Open

fabsch221977 wants to merge 1 commit into
NousResearch:mainfrom
fabsch221977:fix/output-truncation-runtime-cap

Conversation

@fabsch221977

Copy link
Copy Markdown

Summary

  • Preserve custom provider max_output_tokens/max_tokens in config normalization and provider conversion
  • Pass runtime output caps through CLI agent setup and route signatures
  • Retry truncated tool-call responses using the configured/requested cap instead of the 4k/8k ladder
  • Persist a synthetic assistant marker when truncated tool-call retries are exhausted

Validation

  • Live Hermes session on custom:hyperspace-responses / gpt-5.5 / codex_responses wrote a 16,247-byte Day 4 briefing validation file via write_file on first try; no truncation ladder or Response truncated failure
  • bash scripts/run_tests.sh tests/test_output_truncation_runtime.py
  • bash scripts/run_tests.sh tests/test_ctx_halving_fix.py tests/cli/test_cli_provider_resolution.py -q

…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.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists labels Jul 1, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-4688 is a sibling truncation path for routers that report incomplete tool JSON with finish_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.py tests the helper directly, but does not drive run_conversation through 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-5003 is 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants