fix(agent): auto-compact no longer silently drops head content past the 80K slice - #1061
Closed
shadowinlife wants to merge 1 commit into
Closed
fix(agent): auto-compact no longer silently drops head content past the 80K slice#1061shadowinlife wants to merge 1 commit into
shadowinlife wants to merge 1 commit into
Conversation
…he 80K slice _auto_compact() serialized the head with a hard json.dumps(head)[:80000] slice. Once the head exceeded that slice, everything past the cut was neither fed to the summarization LLM nor kept in the preserved tail — silent information loss that contradicts the method's own "zero info decay" contract. Fold the head through the summarization LLM in budget-sized, message-boundary chunks instead: the first pass starts from the previous summary (or the structured template) and each later pass folds the next chunk into the running summary. Every head message reaches the summarization LLM exactly once, and a single oversized message forms its own chunk rather than being dropped. Closes HKUDS#1055 Signed-off-by: shadowinlife <shadowinlife@gmail.com> Co-Authored-By: OpenCode <noreply@opencode.ai> AI-Model: alibaba-cn/qwen3.8-max AI-Contributed/Feature: 65/65 AI-Contributed/UT: 115/115
shadowinlife
marked this pull request as draft
August 11, 2026 06:58
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.
Summary
AgentLoop._auto_compact()reported in [Bug] Auto-compaction can silently drop conversation content during summarization #1055: the head is now folded through the summarization LLM in budget-sized, message-boundary chunks instead of being hard-sliced at 80,000 serialized characters.Why
_auto_compact()built its summarization prompt with:headis everything not kept in the ~20K-token tail (TAIL_TOKEN_BUDGET). Oncejson.dumps(head)exceeded 80,000 characters, everything past the cut was neither seen by the summarization LLM nor preserved in the tail — silent information loss with no exception, contradicting the docstring's "zero info decay" guarantee.Verified against
main@ c33133f with the issue's reproduction script: messages[7..13]were present in neither the summarization prompt nor the reconstructed conversation.Closes #1055
Changes
agent/src/agent/loop.py_chunk_messages_for_summary(): splits messages into chunks whose serialized JSON stays under the budget; message boundaries are never broken; a single oversized message forms its own chunk rather than being dropped.COMPACT_HEAD_CHAR_BUDGET = 80_000(same per-pass budget as the old slice)._auto_compact()replaces the single truncated pass with a fold: the first pass starts from the previous summary (or the structured template, keeping prior behavior), and each subsequent pass folds the next chunk into the running summary via the existing_ITERATIVE_UPDATE_PROMPT. Single-chunk heads behave exactly as before.agent/tests/test_auto_compact_no_silent_loss.py— regression tests:Note for maintainers: this touches the protected
src/agent/path. The issue author asked which remediation direction was intended (overflow preservation vs. chunked summarization). This PR implements chunked summarization, since it is the only option that keeps the "every message is either summarized or preserved verbatim" contract without growing the retained tail unboundedly; happy to reshape if a different direction is preferred.Test Plan
pytest --ignore=agent/tests/e2e_backtest --tb=short -q) — 10079 passed, 76 skippedagent/tests/test_auto_compact_no_silent_loss.pyChecklist
src/agent/,src/session/,src/providers/) without prior discussion — touchessrc/agent/loop.py; flagged above for maintainer direction, per the question raised in [Bug] Auto-compaction can silently drop conversation content during summarization #1055_auto_compactdocstring updated