Skip to content

fix(opencode): skip overflow check on compaction summaries#15129

Open
marklubin wants to merge 1 commit intoanomalyco:devfrom
marklubin:fix/compaction-headless-exit
Open

fix(opencode): skip overflow check on compaction summaries#15129
marklubin wants to merge 1 commit intoanomalyco:devfrom
marklubin:fix/compaction-headless-exit

Conversation

@marklubin
Copy link

Issue for this PR

Closes #13946

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

In headless mode (opencode run), the process exits cleanly after compaction when the compaction model generates a large response. The root cause is in processor.ts line 282: isOverflow() runs on the compaction model's own response tokens. When that response exceeds the overflow threshold, needsCompaction is set to true, the processor returns "compact" instead of "continue", the synthetic continuation message is never created, and the prompt loop exits.

The fix is a one-line guard: skip the isOverflow() check when input.assistantMessage.summary === true (i.e., the current message is already a compaction summary). Re-compacting a compaction is never the intended behavior.

This was 100% reproducible in my testing — across 82 compaction events, all 11 "deaths" (clean exits after compaction) correlated with compaction responses where total tokens exceeded the overflow threshold.

How did you verify your code works?

  • All 109 session tests pass (bun test packages/opencode/test/session/)
  • Full test suite: 1157/1158 pass (1 pre-existing failure in write.test.ts — environment-specific umask issue, unrelated)
  • Manual verification: ran multiple headless sessions with compaction — no more premature exits

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When running in headless mode (`opencode run`), the process exits after
compaction when the compaction model's response exceeds the overflow
threshold. This is because `isOverflow()` in processor.ts runs on the
compaction model's own response, returning "compact" instead of
"continue", so the synthetic continuation message is never created and
the prompt loop exits.

The fix adds a guard to skip the overflow check when the current message
is already a compaction summary (`summary === true`), since re-compacting
a compaction is never the intended behavior.

100% reproducible across 82 compaction events — all 11 deaths correlated
with compaction responses exceeding the overflow threshold.

Closes anomalyco#13946
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #14245: fix: compaction bugs #13946 and #13980
#14245

This PR directly addresses issue #13946, which is the same issue that current PR #15129 claims to close. PR #14245 appears to be an earlier attempt to fix the same compaction-related bugs. You should verify whether #14245 has already been merged or if it's still pending, as it may already contain a solution to this problem.

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.

Bug: opencode run exits after compaction when compaction model's token usage exceeds overflow threshold

1 participant