fix(compaction): place summary instruction after conversation history - #42012
fix(compaction): place summary instruction after conversation history#42012akenra wants to merge 1 commit into
Conversation
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Runtime verification (reported by PR author): Tested on OpenCode Desktop 1.18.16 (Windows) with opencode-go/deepseek-v4-flash (1M context). The same prompt-layout patch was applied directly to the Desktop bundle (app.asar) for testing. Result: a ~350K-token session that previously would not compact correctly (the model answered an old question from the conversation instead of summarizing) now produces the proper anchored summary (## Objective / ## Important Details / ## Work State / ## Next Move / ## Relevant Files) via /compact. This confirms the ordering fix resolves the reported behavior on the exact model/stack from #41801. |
03a7154 to
fe5962e
Compare
fe5962e to
5284e2d
Compare
|
Yeah the smaller models are having issues, ty for pr going to do a bit more cleanup but ill add u as a coauthor on my version |
|
going to go w/ this PR instead (added u as a coauthor): |
Issue for this PR
Closes #41801
Refs #41268
Refs #41358
Refs #36682
Type of change
What does this PR do?
/compact(and auto-compaction) sends the summarization request as one user message: summary instruction first, then the serialized conversation. The conversation is formatted as a chat log ([User]:/[Assistant]:) and ends with a real user question from the past session, so the model answers that old question (or reproduces the transcript) instead of producing the summary — the instruction at the start is diluted, especially on 1M-context models likeopencode-go/deepseek-v4-flashwhere the whole session fits.The summary template itself says "using the conversation history above", i.e. history-first was the intended layout; the call site inverts it.
Change: put the conversation first, then "End of conversation history.", then the summary instruction + template, ending with an explicit guard that the history is reference material only and only the anchored summary must be output. Applied to both paths:
packages/opencode/src/session/compaction.ts— manual/compactand CLI auto-compaction.packages/core/src/session/compaction.ts— runner/make()auto-compaction.The
experimental.session.compactingplugin hook still works; a plugin-providedpromptnow lands after the history.How did you verify your code works?
tsgo --noEmittypecheck passes forpackages/opencodeandpackages/core.session.compaction.process > places the summary instruction after the conversation historyinpackages/opencode/test/session/compaction.test.tsasserts the history precedes the instruction and that the guard line is the last content after any[User]:turn.test/session/compaction.test.ts(54 pass),test/session/revert-compact.test.ts(8 pass) andpackages/core/test/session-compaction.test.ts(2 pass) run green.oxlinton both changed source files: 0 warnings, 0 errors.opencode-go/deepseek-v4-flash(1M context):/compactnow returns the anchored summary instead of answering the last question from the session.Screenshots / recordings
Not a UI change.
Checklist