Skip to content

fix: trigger auto-compaction at the configured threshold#18951

Open
jamestotah wants to merge 1 commit intoanomalyco:devfrom
jamestotah:totah/auto-compaction-threshold
Open

fix: trigger auto-compaction at the configured threshold#18951
jamestotah wants to merge 1 commit intoanomalyco:devfrom
jamestotah:totah/auto-compaction-threshold

Conversation

@jamestotah
Copy link

@jamestotah jamestotah commented Mar 24, 2026

Issue for this PR

Closes #11314
Refs #15533

Type of change

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

What does this PR do?

This reuses the existing session compaction flow to compact proactively once a completed assistant turn crosses a configurable context threshold.

It adds compaction.threshold, triggers threshold-based auto-compaction in the backend after completed assistant turns, dedupes compaction requests while a session is already compacting, and adds a Server -> Sessions settings surface in the app/Desktop UI.

How did you verify your code works?

  • npm exec -- bun test test/session/compaction.test.ts
  • npm exec -- tsgo --noEmit in packages/opencode
  • npm exec -- tsgo -b in packages/app
  • manually set the threshold to 5% in the app and verified a fresh session auto-compacted after crossing it

Screenshots / recordings

Sessions settings screenshot

Checklist

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

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 24, 2026
@github-actions
Copy link
Contributor

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

Based on my search, here are the potentially related PRs (excluding PR #18951, which is the current PR):

Related/Duplicate PRs:

  1. PR feat(session): add custom compaction thresholds along with prevention of continuous compaction #10123 - feat(session): add custom compaction thresholds along with prevention of continuous compaction

  2. PR fix(session): prevent infinite loop in auto-compaction when assistant ended its turn #15532 - fix(session): prevent infinite loop in auto-compaction when assistant ended its turn

  3. PR feat(compaction): configurable threshold and model (global + per-model) #11931 - feat(compaction): configurable threshold and model (global + per-model)

  4. PR fix(session): preserve wait-for-user state after compaction #18941 - fix(session): preserve wait-for-user state after compaction

These PRs should be reviewed to ensure PR #18951 doesn't duplicate existing work, particularly #10123 and #11931 which explicitly address configurable compaction thresholds.

@jamestotah
Copy link
Author

I checked the existing compaction flow before implementing this. This PR does not add a separate compaction mechanism - it reuses the current backend summarize/compaction path and makes it trigger proactively at the configured threshold while deduping in-flight compactions to avoid loops.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 24, 2026
@github-actions
Copy link
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.

Feature Request: Configurable Context Compaction Threshold

1 participant