fix(proxy): TURN-COUNT FINALIZE BREAKER fires periodically, not every turn (v1.64.4)#277
Merged
Merged
Conversation
… turn
`_count_agent_tool_turns` is derived from the only-growing conversation, so once a
session crosses PROXY_HARD_FINALIZE_TURNS the breaker stripped tools on EVERY
subsequent request — permanently denying tools and stalling a legitimately long
agentic task. Observed live: msgs 206→208→…→214 with the breaker firing each turn,
then the client gives up ("keeps stopping" mid-task). reset_tool_turn_state resets
the state machine but not the conversation-derived count, so it never helped.
Gate on `count >= last_hard_finalize_turn_count + ceiling` (new SessionMonitor
field, recorded on each fire) so it fires at the ceiling, 2x, 3x… as a PERIODIC
checkpoint with tools restored in between — the agent keeps progressing and long
tasks complete, while a true runaway is still bounded (and the contamination /
prune / cycle breakers catch faster, looping runaways). Softens the breaker
message from "STOP now" to a progress-checkpoint nudge. Adds 4 tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem — the client kept stopping mid-task
_count_agent_tool_turnsis derived from the only-growing conversation, so once a session crossedPROXY_HARD_FINALIZE_TURNS, the TURN-COUNT FINALIZE BREAKER stripped tools on every subsequent request — permanently denying tools and stalling a legitimately long agentic task.reset_tool_turn_stateresets the state machine but not the conversation-derived count, so it never helped.Smoking gun (live):
msgs=206 → BREAKER → 208 → BREAKER → 210 → BREAKER → 212 → BREAKER → 214 → BREAKER → (client gives up). The client tolerates an occasional forcedend_turn(it re-drives — hence msgs climbing) but not permanent tool denial. Raising the ceiling 40→80 only delayed the wall.Fix
Gate on
count >= last_hard_finalize_turn_count + ceiling(newSessionMonitorfield, recorded on each fire) so the breaker fires at the ceiling, 2×, 3×… as a periodic progress checkpoint with tools restored in between. Long tasks make progress between nudges and complete; a true runaway is still bounded, and the contamination/prune/cycle breakers catch fast loops. Message softened from "STOP now" to a checkpoint nudge.Tests
tools/agents/tests/test_turn_count_breaker_periodic.py(4): fires at [80, 160, 240] not every turn; no re-fire between crossings; first fire at the ceiling; never fires below it.Pairs with the operational ctx raise (131072→163840) that removed the separate prune death-spiral. Bumps to v1.64.4.
🤖 Generated with Claude Code