Skip to content

fix: auto-compact from the TUI when context reaches 80% of the window - #1881

Merged
avoidwork merged 2 commits into
mainfrom
fix/tui-auto-compact-threshold
Nov 18, 2026
Merged

avoidwork merged 2 commits into
mainfrom
fix/tui-auto-compact-threshold

Conversation

@avoidwork

Copy link
Copy Markdown
Owner

Description

Compaction was only reachable via /compact and the loop-detection third strike, so long sessions could pass 90% context without compacting. The TUI now calls handleCompact() when the status-bar token count reaches summarization.contextFraction (default 0.8) of the context window, checked before each new message and after each turn. No middleware is involved.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes)
  • Performance improvement
  • CI / build / tooling

Testing

Added 6 unit tests for shouldAutoCompact (exactly 80%, above, below, custom fraction, missing window or size, default constant) in tests/unit/tui/conversationArea.test.js. The full suite passes through the pre-commit hook. The autoCompactIfNeeded wiring inside the component has no direct test, since conversationArea.js is excluded from coverage and only its pure helpers are tested. Not yet exercised in a live multi-hour session.

Limitation: the check runs between turns, not mid-turn, so one long tool-heavy turn can still cross the threshold before it fires.

Coverage

  • Line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with maintained line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

Threat model: N/A. This is a UI-side trigger for an existing compaction path. It adds no new input, I/O or external calls.

Compaction was only reachable via /compact and the loop-detection third
strike. Add shouldAutoCompact and autoCompactIfNeeded, which recount the
context from the checkpointer and call handleCompact() once the status-bar
token count reaches summarization.contextFraction (default 0.8) of the
context window. Checked before each new message and after each turn.
Pass the resolved contextWindow from App into ConversationArea.
@avoidwork avoidwork added the bug Something isn't working label Nov 18, 2026
@avoidwork avoidwork self-assigned this Nov 18, 2026
@avoidwork avoidwork added the bug Something isn't working label Nov 18, 2026
@avoidwork
avoidwork merged commit 0c4d7ef into main Nov 18, 2026
2 checks passed
@avoidwork
avoidwork deleted the fix/tui-auto-compact-threshold branch November 18, 2026 03:07
avoidwork added a commit that referenced this pull request Nov 18, 2026
* fix: remove non-working summarization middleware

PR #1881 moved auto-compaction into the TUI but left the library-replacing
SummarizationMiddleware registered. Remove it, its onCompacted plumbing, and
the trigger/keep/enabled config. Keep keepMessages and contextFraction, and
make /compact and auto-compact honor keepMessages.

* docs: restore DOCKER.md summarization env var table

* fix: sync status bar color threshold with summarization.contextFraction

The status bar spinner turned red at a hardcoded 80% while auto-compaction
used config.summarization.contextFraction, so the two could drift apart.
Pass contextFraction through App and InputArea to StatusBar so red starts
exactly where auto-compaction fires. Take the fallback default from
SummarizationSchema instead of duplicating 0.8 in the TUI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant