Skip to content

fix(proxy): TURN-COUNT FINALIZE BREAKER fires periodically, not every turn (v1.64.4)#277

Merged
DammianMiller merged 2 commits into
masterfrom
fix/turn-count-breaker-periodic
Jun 25, 2026
Merged

fix(proxy): TURN-COUNT FINALIZE BREAKER fires periodically, not every turn (v1.64.4)#277
DammianMiller merged 2 commits into
masterfrom
fix/turn-count-breaker-periodic

Conversation

@DammianMiller

Copy link
Copy Markdown
Owner

Problem — the client kept stopping mid-task

_count_agent_tool_turns is derived from the only-growing conversation, so once a session crossed PROXY_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_state resets 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 forced end_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 (new SessionMonitor field, 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

t and others added 2 commits June 25, 2026 17:49
… 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>
@DammianMiller DammianMiller merged commit 1e85ad5 into master Jun 25, 2026
11 checks passed
@DammianMiller DammianMiller deleted the fix/turn-count-breaker-periodic branch June 25, 2026 07:57
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