You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: compaction should keep a Code Mode step's return value, not just its code #58717
Code Mode collapses N tool calls into one step: the transcript keeps a code block and one return value, the sandbox does the rest. I cannot predict what compaction does with that, and the answer changes how I write the programs.
Two specific unknowns:
When compaction decides what to keep, does a Code Mode step weigh as one message or as its tokens? A step with 40 lines of code and a 200-byte return is cheap in the transcript and may represent a lot of work. If the accounting is by message, that step survives on almost no budget while six ordinary tool calls get dropped.
What does keep.tokens count? If it counts tokens of the kept transcript, one large code block can eat the whole budget alone. If it counts messages, everything the program learned can disappear in a single cut.
Why this is not theoretical here: my average context is 126,169 tokens per request with auto: true and the V2 fields (keep.tokens, buffer). Sessions run long enough that compaction fires regularly. When it does, the return value of the last Code Mode step is the one thing I cannot reconstruct cheaply. Re-running a program costs the same tokens it cost the first time; a summary of what it printed does not.
What would help
Document the accounting: does a Code Mode step count as one message, and does keep.tokens measure message tokens or parts?
Keep the returned value verbatim, the way tool results are kept, and let the code block be summarized. Code is reproducible from a description; the output is not. If the program returned [{url, ok, mention}], that array is the finding, and the 40 lines that produced it are not.
I am not asking for the sandbox to survive compaction. I am asking that the result of the work survives it.
Related: #58708 (budget and per-tool breakdown), and #58463 for the separate ceiling problem between buffer and the output reservation.
Thanks for the detailed write-up! You're asking for two things: clear docs on how compaction counts a Code Mode step and what keep.tokens measures, and for compaction to keep an execute step's returned value word for word while the code that produced it can be summarized.
On the first part, from the current code: the recent part of the conversation that compaction keeps word for word is measured in estimated tokens of message text (keep defaults to 15,000), not as a count of messages. So a Code Mode step costs its code plus its result, measured in tokens. When older exchanges are shortened for the summary, tool outputs are trimmed first and later left out, so a Code Mode return value isn't currently protected.
Plugins can't do this today. The compaction hook can only return a summary string (see #50862), so it can't pin particular tool results to be kept as they are. Maintainers will consider the request.
Activity
opencode-agent commentedon Oct 24, 2026
Thanks for the detailed write-up! You're asking for two things: clear docs on how compaction counts a Code Mode step and what
keep.tokensmeasures, and for compaction to keep anexecutestep's returned value word for word while the code that produced it can be summarized.On the first part, from the current code: the recent part of the conversation that compaction keeps word for word is measured in estimated tokens of message text (
keepdefaults to 15,000), not as a count of messages. So a Code Mode step costs its code plus its result, measured in tokens. When older exchanges are shortened for the summary, tool outputs are trimmed first and later left out, so a Code Mode return value isn't currently protected.Plugins can't do this today. The compaction hook can only return a summary string (see #50862), so it can't pin particular tool results to be kept as they are. Maintainers will consider the request.
Related issues:
keep.tokensnot being honoured, and the fix for thatbufferand output-reservation ceilings