Skip to content

fix(compaction): adjust instructions and structure to be more clear to smaller models like dsv4 flash - #42045

Merged
rekram1-node merged 10 commits into
devfrom
compaction-fixes
Aug 12, 2026
Merged

fix(compaction): adjust instructions and structure to be more clear to smaller models like dsv4 flash#42045
rekram1-node merged 10 commits into
devfrom
compaction-fixes

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #41801
Closes #41268

…o smaller models like dsv4 flash

Co-authored-by: akenra <37288280+akenra@users.noreply.github.com>
@rekram1-node
rekram1-node merged commit dab2637 into dev Aug 12, 2026
8 of 9 checks passed
@rekram1-node
rekram1-node deleted the compaction-fixes branch August 12, 2026 19:36
sepo-eng added a commit to Draugur-AI/opencode that referenced this pull request Aug 13, 2026
…#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 <bot@opencode.ai>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manual /compact with DeepSeek V4 Flash degenerates into thousands of repeated lines /compact 命令上下文丢失问题

1 participant