Repository navigation
fix(core): refuse a compaction reply that calls a tool - #49
Open
TaewoooPark wants to merge 1 commit into
Open
TaewoooPark wants to merge 1 commit into
TaewoooPark wants to merge 1 commit into
Conversation
The summary request tells the model not to call a tool. A model that keeps working instead answers with one line of intent and a call, such as "Let me check the current state first." With the call stripped, that line was not empty, so it became the summary and replaced the whole transcript: the next turn started with the task and one sentence. A reply that calls a tool, as a parsed tool call or as an inline <tool_call> block, is now a failed compaction. The loop already handles that case: it keeps the full transcript, warns, and compacts again once the next request crosses the limit.
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.
Problem
When the context reaches
compactAt,summarizeTranscriptasks the model for a handoff summary and tells it not to call a tool. A model that is in the middle of work does not always stop. It may answer the way it answers any turn: one line of intent, then a tool call.The tool call is dropped. The line that came with it is not empty, so it passes the "no summary" check and becomes the summary.
buildCompactedHistorythen replaces the transcript with the person's messages and that one sentence. The next turn starts with no record of what was done, decided or planned, and the model has to rebuild all of it from the working tree.The docstring already states the intent: a model that answers with a tool call has not written a summary, and the caller should treat that as a failed compaction. The code enforced this only when nothing was left after removing inline
<tool_call>blocks, and it did not look at tool calls the server had already parsed intotoolCalls.Change
fix(core): refuse a compaction reply that calls a tooltoolCalls, or with an inline<tool_call>block, now throws: "the model called a tool instead of writing a summary".compaction failed … continuing with the full transcriptnotice, and compacts again once the next request crosses the limit.Why this rule
What it costs. A reply that wrote a real summary and then also called a tool is now refused too, where before its text was kept. That costs one more summary request on a later turn, and the transcript stays whole in the meantime. Taking a one-line preamble as the summary costs the whole transcript. Compaction starts at
compactAt(below 1), so the window has room for the turns until the next attempt.Alternatives considered:
summarizeTranscript. It adds code for what the loop's next-turn retry already does.Tests
pnpm typecheck,pnpm test(1677 passed),pnpm lint:toolsandpnpm buildall pass.Both tests below fail on
main:summarizeTranscriptrefuses an empty reply, as before. It now also refuses an inline<tool_call>reply and a reply with parsedtoolCalls. This replaces the old expectation that a tool call is dropped and the text kept.