fix: improve compaction continuation to prevent agent from stopping#16073
Open
guazi04 wants to merge 1 commit intoanomalyco:devfrom
Open
fix: improve compaction continuation to prevent agent from stopping#16073guazi04 wants to merge 1 commit intoanomalyco:devfrom
guazi04 wants to merge 1 commit intoanomalyco:devfrom
Conversation
After compaction, the synthetic continuation message gave the model
permission to stop ('or stop and ask for clarification'), causing the
agent to frequently stop working instead of resuming the task.
Changes:
- Replace ambiguous continuation message with assertive directive
that instructs the model to continue from where it left off
- Enhance compaction summary prompt with sections for current status,
remaining tasks, next actions, and open questions
- Inject session todo list into compaction prompt so the summary
agent faithfully captures remaining work
- Include incomplete todos in continuation message to give the model
explicit next steps after compaction
Closes anomalyco#13217
Contributor
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #13217
Type of change
What does this PR do?
After compaction, the agent frequently stops working instead of continuing. This affects all providers and has been confirmed by 8+ users.
Root cause: Two issues combine:
The synthetic continuation message after compaction says "Continue if you have next steps, or stop and ask for clarification" — this gives the model explicit permission to stop. After seeing a compressed summary, models frequently choose to stop.
The compaction summary prompt doesn't ask for remaining tasks or next actions. Without clear direction in the summary, the model has nothing to continue with.
Fix (single file,
compaction.ts, +47/-2 lines):Replaced the continuation message with an assertive 3-line directive that tells the model to read the summary and take the next concrete step. It still allows asking questions when genuinely blocked on missing info.
Enhanced the summary prompt with 4 new sections: current status, remaining tasks, next actions, and open questions — so the summary captures what to do next.
Inject session todos into the compaction prompt unconditionally (even when a plugin provides a custom prompt), so the summary agent faithfully captures remaining work.
Include incomplete todos in the continuation message with an explicit instruction to resume the in-progress item.
I identified this by studying how oh-my-opencode's plugins (compaction-context-injector, todo-continuation-enforcer) solve this same problem — they enrich the compaction context and aggressively prevent the model from stopping. This PR brings the core fix upstream without requiring plugins.
How did you verify your code works?
bun typecheckpasses cleanlyexperimental.session.compacting) continues to work as beforeScreenshots / recordings
N/A — backend logic change, no UI impact.
Checklist