Skip to content

fix(context-compact): fix L1 truncation bug on consecutive tool results - #465

Closed
lelewang520 wants to merge 1 commit into
shareAI-lab:mainfrom
lelewang520:patch-1
Closed

fix(context-compact): fix L1 truncation bug on consecutive tool results#465
lelewang520 wants to merge 1 commit into
shareAI-lab:mainfrom
lelewang520:patch-1

Conversation

@lelewang520

Copy link
Copy Markdown

Summary

Fixes a hidden context truncation bug in the L1 snip_compact pipeline where consecutive tool_result messages (often generated by parallel tool execution) would cause a validation failure, leading to broken tool/result pairings and API crashes.

The Problem

In the original snip_compact implementation, the tail boundary alignment (tail_start) was guarded by a single if statement:

if (tail_start > 0 and tail_start < len(messages)
        and _is_tool_result_message(messages[tail_start])
        and _message_has_tool_use(messages[tail_start - 1])):
    tail_start -= 1

### Summary
Fixes a hidden context truncation bug in the L1 `snip_compact` pipeline where consecutive `tool_result` messages (often generated by parallel tool execution) would cause a validation failure, leading to broken tool/result pairings and API crashes.

### The Problem
In the original `snip_compact` implementation, the tail boundary alignment (`tail_start`) was guarded by a single `if` statement:
```python
if (tail_start > 0 and tail_start < len(messages)
        and _is_tool_result_message(messages[tail_start])
        and _message_has_tool_use(messages[tail_start - 1])):
    tail_start -= 1
@Bill-Billion
Bill-Billion force-pushed the main branch 2 times, most recently from 934b526 to 581241c Compare July 28, 2026 12:24
@Bill-Billion

Copy link
Copy Markdown
Collaborator

Thanks for finding the consecutive tool_result boundary case.

#470 covers this tail-boundary fix and also corrects max_messages accounting and small-limit behavior. The multi-result case handled here is included there, so we’ll keep the work in one PR and close this one as superseded.

Thanks for the focused fix and explanation.

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.

2 participants