opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Model in BUILD mode does not have enough context to continue after compaction

Open agladysh opened this issue 1 year ago • 7 comments

Compaction summaries are too basic, and do not include context sufficient information for the model to continue work when compaction happens in BUILD mode, leading to nonsensical changes and wasted work.

On compaction, ask the model to prepare a detailed handoff document for it to continue the work after the context window reset. Ask the model to prepare the list of documents and files defining the work being done, as well as files that were or would be changed during the work. Include these files and git status -sbu in the context after compaction.

P.S. I have a suspicion that AGENTS.md is not included in the context after compaction (it should), but I did not verify it rigourously.

agladysh avatar Oct 08 '25 06:10 agladysh

This issue might be a duplicate of existing issues. Please check:

  • #2945: Session automatically compacted, destroying the entire working context - describes same issue where compaction destroys working context in build mode
  • #2234: compact causes llm to forget convo - model forgets conversation context after compaction, leading to starting fresh
  • #940: Preload instructions after /compact - requests automatic preloading of instructions after compaction to maintain context
  • #1990: Add User Controls for Context Management - broader feature request for context management that could address compaction issues

Feel free to ignore if none of these address your specific case.

github-actions avatar Oct 08 '25 06:10 github-actions

P.S. I have a suspicion that AGENTS.md is not included in the context after compaction (it should), but I did not verify it rigourously.

It is included

rekram1-node avatar Oct 08 '25 17:10 rekram1-node

Compaction summaries are too basic, and do not include context sufficient information for the model to continue work when compaction happens in BUILD mode, leading to nonsensical changes and wasted work.

yeah the prompt could use some work

rekram1-node avatar Oct 08 '25 17:10 rekram1-node

P.S. I have a suspicion that AGENTS.md is not included in the context after compaction (it should), but I did not verify it rigourously.

It is included

there must be some use cases where it is not because i find myself reminding it over and over that there is an AGENTS.md in the root of the project 😄

tuxillo avatar Dec 21 '25 18:12 tuxillo

@agladysh I have a PR which will support custom prompts for compaction. I have been having great success with the following custom prompt (although, I have mostly used it with Opus 4.5, so bears testing for other models.)

---
description: Compact & hand over
compact: true
---

Curate a hand-over note from this conversation, so that a new agent can take over and continue aiding the user.

The new agent will have no context except what you provide in the note - so focus on informing them of everything they will need (while leaving out anything they won't need).

Pay attention to the vibe, the exact workflow. Record some interactions or habits that went well - put the abridged examples in the note. Show by example!

Make sure that the note contains all of:

- The goal of this work, keeping specific wording by the user as much as possible.
- The history of the conversation & work, especially open threads or things that may be useful going forward.
- Specific commands that will be useful, specific filenames that will be useful, other specific details.
- Briefly, any issues that were encountered and the solution, to save the new agent doing any debugging again.

If the last message was one from the user, please include it exactly, at the very end of the note.

Focus on including details that would not be recoverable, or that would take time to do so, but feel free to leave out anything that the new agent would easily discover themselves, and encourage them to do so.

Take the time and space to do a good job of representing the work & demonstrating to the new agent how to seamlessly continue it.

maxeonyx avatar Jan 12 '26 20:01 maxeonyx

Another potential improvement: include the last user prompt in the compaction replay message. Right now the model only sees the summary after compaction but loses the original request. Including it would give better continuity, especially during auto-compaction mid-task.

leohenon avatar Feb 17 '26 10:02 leohenon

To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

github-actions avatar Apr 19 '26 03:04 github-actions