Skip to content

fix(session): compact finished overflowed turns#27730

Open
adao-max wants to merge 2 commits into
anomalyco:devfrom
adao-max:fix/auto-compact-finished-overflow
Open

fix(session): compact finished overflowed turns#27730
adao-max wants to merge 2 commits into
anomalyco:devfrom
adao-max:fix/auto-compact-finished-overflow

Conversation

@adao-max
Copy link
Copy Markdown

@adao-max adao-max commented May 15, 2026

Issue for this PR

Fixes #15533

Related: #20247

Type of change

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

What does this PR do?

Auto-compaction had two adjacent edge cases when the assistant had already finished normally:

  1. The prompt loop exited before checking whether the finished assistant turn had overflowed, so a finished turn over the compaction threshold could skip auto-compaction.
  2. When auto-compaction did run after a naturally finished turn, it could inject a synthetic Continue... prompt and start another agent response instead of waiting for the next real user message.

This PR moves the finished-turn overflow check before the normal loop exit and skips synthetic auto-continue when the last non-summary assistant has already finished with a non-tool-call finish reason.

How did you verify your code works?

  • bun test test/session/prompt.test.ts --timeout 30000
  • bun test test/session/compaction.test.ts --timeout 30000
  • bun run typecheck

Screenshots / recordings

N/A — not a UI change.

Checklist

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

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 15, 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 the search results, I found one related PR that may be worth reviewing alongside this one:

Related PR:

The other PRs found (#15130, #14743, #10123, #20491, #21567) are related to compaction more broadly but don't appear to be duplicates of the current PR's specific fix.

No true duplicate PRs found for this specific issue (the current PR #27730 is correctly excluded from the results). PR #20247 is the closest related work on overflow compaction logic.

@github-actions github-actions Bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Auto-compaction infinite loop when assistant ended its turn (finish !== tool-calls)

1 participant