fix(session): prevent double compaction after auto-compact#26484
fix(session): prevent double compaction after auto-compact#26484sgfvamll wants to merge 1 commit into
Conversation
|
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. |
|
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
|
I'm not sure if the root cause analysis is right. But it fixed the issue I encountered. May serve as a workround. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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