fix(opencode): converge overflow compaction instead of replaying the same message forever - #41
Merged
Merged
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Collaborator
Author
|
CI note: |
An overflow compaction replays the overflowing user message but computed the retained tail from the history before it, so filterCompacted kept the original next to the replay and every retry was as large as the failure (REPL-31509: 2,161 identical cycles). The marker now retains nothing before itself when it replays, so the next context is [marker, summary, replay]. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A message that still overflows after compaction replayed it can never fit; a second consecutive overflow now ends the turn with ContextOverflowError instead of compacting again. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
PierrotAWB
force-pushed
the
andrew/repl-31509-overflow-replay
branch
from
September 4, 2026 16:40
a8c53ff to
3156f19
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a message is too large for the model, opencode compacts the conversation and re-sends the message. The retained window kept the original copy right next to the re-sent one, so the retry was exactly as large as the failure and the loop never ended. One production session repeated this 2,161 times over 12.8 hours. After this change the retry carries a single copy, and a turn that still overflows after one compaction stops with an error instead of compacting again.
Context
.htmlattachment (96% one base64 image, ~580k tokens) was sent, stopped, and re-sent, so the context held two copies and Anthropic rejected it. Every compaction cycle then summarized the history before the message and appended a fresh copy of it, whilefilterCompactedstill returned the original, so each retry was ~1.21M tokens.anomalyco/opencodedev(a935432, 2026-09-03) has the sameoverflowreplay code and the samefilterCompacted, so this cannot be picked up by a base bump. Worth upstreaming after it bakes here.Changes
Retained window on an overflow replay (
session/compaction.ts).processCompactioncomputestail_start_idfrom the history before the message it is about to replay, which always leaves that message inside the retained window. When a replay is emitted, the marker now retains nothing before itself, so the next model context is[marker, summary, replay]: one copy.One overflow compaction per turn (
session/prompt.ts). A message that still overflows after compaction replayed it can never fit. The second consecutive overflow ends the turn withContextOverflowErroron the assistant message instead of compacting again. A finished model step resets the counter.Testing Done
bun test test/session/compaction.test.ts test/session/prompt.test.ts test/session/message-v2.test.ts: 150 pass.[marker, summary, replay]with the re-sent original gone. It fails ondev(two extra copies retained) and passes here.ContextOverflowError/finish: "error".bun run typecheck(tsgo) clean.Rollout
Cut
v1.17.14-11fromdevafter merge, then bumpOPENCODE_VERSIONinapps/daytona-snapshot/Dockerfileandsandbox-packages/sandbox-upgrader/src/opencode-version.tsin andytown in one PR.🤖 Generated with Claude Code
Summary by cubic
Fixes the overflow compaction loop that retried an oversized message forever, because the original copy was retained next to the replay. Now the retained window only keeps the replay, and a second consecutive overflow ends the turn with
ContextOverflowErrorinstead of compacting again. This addresses the runaway loop from REPL-31509.compaction.ts, the compaction marker now retains nothing before itself when replaying, so the next context is[marker, summary, replay].prompt.ts, the loop stops after one overflow compaction per turn and marks the assistant message as failed withContextOverflowError.Written for commit 3156f19. Summary will update on new commits.