Skip to content

fix(loop): detect repeats before committing assistant turn - #62

Merged
maruakshay merged 1 commit into
mainfrom
fix/loop-detect-dangling-tool-use
Jul 2, 2026
Merged

fix(loop): detect repeats before committing assistant turn#62
maruakshay merged 1 commit into
mainfrom
fix/loop-detect-dangling-tool-use

Conversation

@maruakshay

Copy link
Copy Markdown
Owner

When the loop detector fired after pushing the assistant message, the persisted history ended on a tool_use with no matching tool_result. On session resume the next request carried that dangling pair and was rejected by the model API.

Move repeat detection ahead of the history.push so a detected repeat returns history without committing the turn. Skip the check on truncated calls, which are already steered to splitting via splitWriteHint; a repeat on the next turn there means 'try again smaller', not 'loop detected'.

Adds a vitest suite pinning the tool_use -> tool_result block-ordering invariant and the various guard paths (truncation, unknown tool, denied permission, invalid input, leaked text call, repeated tail).

When the loop detector fired after pushing the assistant message, the
persisted history ended on a tool_use with no matching tool_result.
On session resume the next request carried that dangling pair and was
rejected by the model API.

Move repeat detection ahead of the history.push so a detected repeat
returns history without committing the turn. Skip the check on
truncated calls, which are already steered to splitting via
splitWriteHint; a repeat on the next turn there means 'try again
smaller', not 'loop detected'.

Adds a vitest suite pinning the tool_use -> tool_result block-ordering
invariant and the various guard paths (truncation, unknown tool,
denied permission, invalid input, leaked text call, repeated tail).
@maruakshay
maruakshay merged commit c3c8251 into main Jul 2, 2026
2 checks passed
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