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
Commit 27a17c0
Browse filesBrowse the repository at this point in the historyBrowse files
authored
feat(compaction): clearer summary prompt structure for smaller models (#58)
Hand-merged from anomalyco/opencode@dab2637217 ("fix(compaction):
adjust instructions and structure to be more clear to smaller models
like dsv4 flash", anomalyco#42045). Their patch didn't cherry-pick cleanly --
it conflicts with TKT-379 (the compaction summary must NOT hide that
context was compacted; hiding it measurably drops history_search's
call rate from 100% to 20%) and with our own splitPrefix/splitSuffix/
retainedCount extension to select(). Reapplied by hand, taking the
genuinely good parts and explicitly not the rest:
TAKEN:
- New SUMMARY_UPDATE_INSTRUCTIONS block: explicit guidance for
combining a <prior-summary> with new <conversation> content
(carry forward objectives/constraints/decisions, conversation wins
on conflict, move Active->Completed, update Objective/Next Move).
- buildPrompt() restructured to wrap the actual conversation content
in explicit <conversation> tags up front, before the instructions,
instead of spreading context items loose at the end of the prompt
array. This is the actual "clearer to smaller models" improvement.
- Tag renamed <previous-summary> -> <prior-summary> to match. Fixed
every place that tag name is asserted or referenced, including in
the SECOND compaction pipeline (packages/opencode/src/session/
compaction.ts) that turns out to share this same buildPrompt() --
and its own agent system prompt (packages/core/src/plugin/agent.ts
PROMPT_COMPACTION / packages/opencode/src/agent/prompt/
compaction.txt), which told the model to look for the old tag name.
NOT TAKEN, deliberately (Sean: "don't take their side"):
- Upstream's version of this same instruction says "Do not mention
the summary process or that context was compacted" -- the exact
opposite of TKT-379's fix. Kept our version unchanged. Added a
test pinning this so a future upstream sync can't silently
reintroduce it via a cleaner-looking cherry-pick.
- Upstream's select() also drops splitPrefix/splitSuffix (character-
level splitting of a message straddling the retention boundary) in
favor of whole-message-only slicing. Our fork extended that same
logic with retainedCount (feeds
SessionEvent.Compaction.Ended.retainedTailMessages) -- left
entirely untouched.
NOT TOUCHED, flagged to feedback instead (anomalyco#227): PROMPT_COMPACTION's
own "do not mention... compacting" sentence (a second, separate
instance of the same class of bug TKT-379 fixed) and the
packages/core/src/v1/config/config.ts tail_turns docstring clarity
change -- both belong to the second compaction pipeline, whose
liveness relative to the first is TKT-377's still-open question, not
something to resolve as a side effect of this hand-merge.
Co-authored-by: opencode <[email protected]>
Co-authored-by: Claude <[email protected]>
Copy file name to clipboardExpand all lines: packages/core/src/plugin/agent.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ const PROMPT_COMPACTION = `You are an anchored context summarization assistant f
34
34
35
35
Summarize only the conversation history you are given. The newest turns may be kept verbatim outside your summary, so focus on the older context that still matters for continuing the work.
36
36
37
-
If the prompt includes a <previous-summary> block, treat it as the current anchored summary. Update it with the new history by preserving still-true details, removing stale details, and merging in new facts.
37
+
If the prompt includes a <prior-summary> block, treat it as the current anchored summary. Update it with the new history by preserving still-true details, removing stale details, and merging in new facts.
38
38
39
39
Always follow the exact output structure requested by the user prompt. Keep every section, preserve exact file paths and identifiers when known, and prefer terse bullets over paragraphs.
Copy file name to clipboardExpand all lines: packages/core/src/session/compaction.ts
+22-6Lines changed: 22 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,15 @@ Rules:
64
64
"compaction" case), and that marker must stay -- TKT-379, diary 2610: hiding it drops
65
65
history_search's call rate from 100% to 20% because the model receives no cue that older detail
66
66
might exist at all.`
67
+
constSUMMARY_UPDATE_INSTRUCTIONS=`The <prior-summary> summarizes everything that happened before the <conversation>. Construct a new summary that combines both. The <prior-summary> is discarded after this: anything you do not carry into the new summary is lost.
68
+
69
+
When combining:
70
+
- Carry forward objectives, constraints, user directives, decisions, and parallel workstreams from the <prior-summary> even when the <conversation> does not mention them. Drop only what is finished and no longer needed.
71
+
- The <conversation> is more recent than the <prior-summary>. Where they conflict, the conversation wins: state the corrected fact and drop the old claim.
72
+
- Add new progress, decisions, constraints, and context from the conversation.
73
+
- Move completed work from "Active" to "Completed".
74
+
- If a blocker has been resolved, update the summary to reflect that while keeping any details still needed to continue the work.
75
+
- Update "Objective" and "Next Move" to reflect the current work state.`
? `Update the anchored summary below using the conversation history above.\nPreserve still-true details, remove stale details, and merge in the new facts.\n<previous-summary>\n${input.previousSummary}\n</previous-summary>`
257
-
: "Create a new anchored summary from the conversation history.",
expect(prompt).toContain("that marker must stay -- TKT-379")
74
+
expect(prompt).not.toContain("Do not mention the summary process or that context was compacted.")
75
+
})
76
+
44
77
test("exceedsCapacity applies the estimator safety factor to the estimated portion -- a request the raw estimate clears still exceeds capacity once inflated by 1.2x (TKT-377, diary 2584/2594: char/4 under-counts structured tool output by up to 31%)",()=>{
45
78
// context=100000, buffer=1000 -> usable capacity is 99000. estimatedTokens=90000 clears that
46
79
// raw (90000 <= 99000), but 90000 * 1.2 = 108000 exceeds it -- exactly the gap the live
Copy file name to clipboardExpand all lines: packages/opencode/src/agent/prompt/compaction.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ You are an anchored context summarization assistant for coding sessions.
2
2
3
3
Summarize only the conversation history you are given. The newest turns may be kept verbatim outside your summary, so focus on the older context that still matters for continuing the work.
4
4
5
-
If the prompt includes a <previous-summary> block, treat it as the current anchored summary. Update it with the new history by preserving still-true details, removing stale details, and merging in new facts.
5
+
If the prompt includes a <prior-summary> block, treat it as the current anchored summary. Update it with the new history by preserving still-true details, removing stale details, and merging in new facts.
6
6
7
7
Always follow the exact output structure requested by the user prompt. Keep every section, preserve exact file paths and identifiers when known, and prefer terse bullets over paragraphs.
0 commit comments