Skip to content

Fix compaction splitting tool-use/result pairs#326

Open
wangle201210 wants to merge 2 commits into
shareAI-lab:mainfrom
wangle201210:fix/snip_compact
Open

Fix compaction splitting tool-use/result pairs#326
wangle201210 wants to merge 2 commits into
shareAI-lab:mainfrom
wangle201210:fix/snip_compact

Conversation

@wangle201210
Copy link
Copy Markdown

Summary

Fixes #325.

This updates context compaction so it preserves complete tool rounds instead of trimming raw message slices.

The bug was that snip_compact and reactive_compact could separate an assistant message containing tool_use blocks from the following user message containing tool_result blocks. That leaves orphaned tool results in history and can break the next model request.

Changes

  • add message-span helpers in s08_context_compact, s09_memory, and s20_comprehensive
  • make snip_compact trim by complete tool rounds instead of raw message count
  • make reactive_compact retain a safe tail instead of messages[-5:]
  • update s08_context_compact docs and generated site docs to describe the constraint correctly

Validation

  • python3 -m py_compile s08_context_compact/code.py s09_memory/code.py s20_comprehensive/code.py

@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@wangle201210 is attempting to deploy a commit to the crazyboym's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Gui-Yue
Copy link
Copy Markdown
Collaborator

Gui-Yue commented May 30, 2026

@wangle201210
Hi! The issue itself is valid, but the current PR implementation is too heavy. The current changes noticeably increase the complexity of the teaching code and make the README examples harder to read.This problem is better suited for a small boundary fix, rather than introducing a relatively heavy span/window helper system separately into s08/s09/s20.

@wangle201210
Copy link
Copy Markdown
Author

wangle201210 commented Jun 1, 2026

@wangle201210 Hi! The issue itself is valid, but the current PR implementation is too heavy. The current changes noticeably increase the complexity of the teaching code and make the README examples harder to read.This problem is better suited for a small boundary fix, rather than introducing a relatively heavy span/window helper system separately into s08/s09/s20.

@Gui-Yue 现在简化了很多写法,用来做学习应该问题不大了
主要是这个问题要是不修,之前的代码很可能跑不通

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.

Compaction can split tool_use/tool_result pairs and break follow-up requests

2 participants