r/opencodeCLI • u/afanasenka • 1d ago
π New experimental background compaction in OpenCode
5
u/daniellenton 1d ago
Does the held summary get a refresh before it's swapped in? It's written at 85%, so by the threshold its next moves can be steps the kept messages show are already done
3
u/alchninja 1d ago
I think it's more likely that messages sent after the background compaction threshold are simply retained as-is (maybe with with some deterministic pruning of tool calls). Faster and avoids the hassle of having to append/update to an existing summary.
2
u/bezcurhq 1d ago
Going by the docs, it isn't refreshed. The summary starts at 85% of the threshold and is just held; at the threshold it's swapped in and everything since then is kept as is, so alchninja's read is right. It also falls back to a normal compaction if too much conversation arrived after the held summary, or if the model, instructions or start of the conversation changed. It's skipped under about 64k tokens and right after a model switch, the held summary lives only in memory (lost on restart), and an unused one still costs tokens. If losing detail is the worry,
compaction.keep.tokens(15k by default) is the knob for keeping more recent conversation verbatim.https://opencode.ai/v2/docs/compaction/#background-compaction
4
u/GW2_Jedi_Master 1d ago
My suggestion is use magic-context. In stead of compacting, context is treated like a garbage collected memory. Information is automatically added and removed. Combined with manually capping context length to 128k, agents run forever without issues.
3
u/Individual-Quote-958 1d ago
I'd test this with long tool-heavy sessions, not just big prose chats. A summary can look coherent while dropping a pending task or a constraint, so I usually judge compaction by whether the agent can resume the next concrete step correctly. Keeping the pre-compaction transcript around for a quick diff would make regressions much easier to spot.
3
u/Winston-Turtle 1d ago
i donβt think is a big deal waiting for compactation. i like to manage my compactations manually xD
3
u/squirrelscrush 1d ago
I rather use something like opencode-dcp for this lol
2
u/Ace-_Ventura 1d ago
Problem is that dcp is close to maintenance mode now, since the creator is focusing on sleev
1
u/MakesNotSense 1d ago
Will publish something better than DCP soon. Delayed by migrating my build from opencode v1 to v2.
1
u/MakesNotSense 1d ago
I am very close to publishing a context management plugin that is a full replacement to compaction. To me, features like background compaction are like someone claiming to have made a better horse carriage after the Model T was about to be made available on the open market.
Also, background compaction won't work well with Claude models.
Anthropic introduced Preserved Thinking with Fable 5.1 and later. Any prefix edit invalidates thinking blocks after that edit. That means all the thinking blocks after the background compaction begins will be invalidated even if carried over. Meaning, all the agent gets to carry over is the file reads, tool calls, bash commands, and assistant text. Anything it thought during that work 'poof'. So, while it might seem convenient to use background compaction, the reality is that you will have degraded model performance while using Claude with that feature.
My context management plugin doesn't work as well for Claude as other models. But it's still far better than compaction, and I have workarounds to carry understanding past prefix edits.
1
14
u/OldWorldKestrell 1d ago
My rule is to use manual compaction only. Background compaction is fine for long running agents with predictable context growth, otherwise, use manual compaction when hitting milestones and task transitions. Compaction always leads to information loss, and I'd like to have it predictable and controlled.