Skip to content

fix(session): defer auto-compaction until the next model input - #38901

Closed
wishiweresaitama wants to merge 1 commit into
anomalyco:devfrom
wishiweresaitama:agent/defer-auto-compaction
Closed

fix(session): defer auto-compaction until the next model input#38901
wishiweresaitama wants to merge 1 commit into
anomalyco:devfrom
wishiweresaitama:agent/defer-auto-compaction

Conversation

@wishiweresaitama

@wishiweresaitama wishiweresaitama commented Jul 25, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

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

What does this PR do?

Automatic compaction was being scheduled immediately after an assistant step exceeded the context threshold. This could trigger compaction after a final subagent response even when no further model input was needed.

This PR removes the post-step-finish overflow check from SessionProcessor. The existing check in SessionPrompt now handles compaction before the next model request.

As a result, the completed response is returned without starting unnecessary compaction. If the user sends another message, or the parent agent needs another model call, the context is compacted before that request.

The related processor test was updated, and a regression test was added for the next-user-message case.

How did you verify your code works?

Added regression coverage for both parts of the behavior:

  • An assistant response exceeding the context threshold does not immediately request compaction.
  • After the next user message, compaction runs before the next assistant response.

Tests:

bun test packages/opencode/test/session/processor-effect.test.ts
bun test packages/opencode/test/session/prompt.test.ts

Screenshots / recordings

Not applicable.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No "Type of change" checkbox is checked. Please select at least one.
  • No issue referenced. Please add Closes #<number> linking to the relevant issue.
  • Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jul 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

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

Based on my search, I found one potentially related PR:

Related PR:

This PR (38901) appears to be addressing a refinement to compaction behavior that was previously tackled in PR #37584. Both PRs deal with controlling when compaction occurs relative to model input and avoiding unnecessary compaction cycles.

However, PR #38901 is the current PR (the one being checked), so it's not a duplicate of itself. The PR #37584 is a related but distinct fix that addresses a similar problem area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant