fix(session): prevent double compaction after auto-compact#26484
Open
sgfvamll wants to merge 1 commit into
Open
fix(session): prevent double compaction after auto-compact#26484sgfvamll wants to merge 1 commit into
sgfvamll wants to merge 1 commit into
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PR Found:
This PR appears to be related as it also addresses double compaction issues in sessions. You should verify if PR #26235 overlaps with the fix in PR #26484 or if they address different scenarios of the same problem. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
e0aeead to
5c8b307
Compare
After compaction, filterCompacted retains tail assistant messages with stale cumulative token counts. The backward scan picks up these retained tails as lastFinished, and the overflow pre-check fires a second compaction immediately. Add a guard: only trigger auto-compaction when lastFinished is newer than the last compaction user message. Retained tails have older IDs, so they fail this check. Resolves anomalyco#26230 Resolves anomalyco#20621
5c8b307 to
d5316de
Compare
Author
|
I'm not sure if the root cause analysis is right. But it fixed the issue I encountered. May serve as a workround. |
3 tasks
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.
Issue for this PR
Resolves #26230
Resolves #20621
Type of change
What does this PR do?
After auto-compaction,
filterCompactedretains tail assistant messages that carry stale cumulative token counts (~100K). The backward scan in the prompt loop picks up these retained tails aslastFinished, and the overflow pre-check immediately fires a second compaction — every single time. This wastes tokens and doubles Copilot request consumption.Root cause: The backward scan at
prompt.ts:1418-1426searches from the end offilterCompacted's output and breaks as soon as it findslastUser+lastFinished. After compaction, the output is:The scan finds
lastUser=[21] andlastFinished=[20] (a retained tail), then breaks — never reaching the compaction part at [0]. Sincetasksis empty, the compaction task handler is skipped. The pre-check then seeslastFinishedwith stale 103K tokens,isOverflowreturns true, and a second compaction fires.Fix: Add a guard that only triggers the overflow pre-check when
lastFinishedis newer than the last compaction user message. Retained tails have IDs older than the compaction user, so they fail this check.4-line production change in
packages/opencode/src/session/prompt.ts.How did you verify your code works?
filterCompactedfunction and traced the exact output ordering and backward scan behaviorbun typecheck— cleanbun test test/session/prompt.test.ts --test-name-pattern "double-compact"— 1 passScreenshots / recordings
N/A — no UI changes.
Checklist