Skip to content

fix(tui): gate auto-compact on the capped history the request sends - #2066

Merged
will-lamerton merged 1 commit into
mainfrom
fix/tui-auto-compact-capped-gate
Nov 11, 2026
Merged

will-lamerton merged 1 commit into
mainfrom
fix/tui-auto-compact-capped-gate

Conversation

@will-lamerton

Copy link
Copy Markdown
Member

What was wrong

The TUI conversation loop sends capMessagesForModel(messages, maxMessages) to the model, but its auto-compact gate measured the full updatedMessages. In a long session with sessions.maxMessages set, old rows that the cap already drops from every request still counted toward the threshold. Compaction could fire, and spend an LLM summary call, while the request was well under the limit. run/--plain (plain/conversation.ts) and the subagent executor already gate on the capped view, so the TUI was the odd one out.

Fix

Gate on capMessagesForModel(updatedMessages, maxMessages). The result is adopted only when compaction actually ran (compacted !== compactGateInput), the same as the other two loops. Otherwise maybeAutoCompact hands back the capped view, and taking it would discard history.

There is one behaviour difference, and it matches plain and subagents. When compaction does run, the compacted capped view replaces the history, so rows beyond the cap are no longer kept in memory. Previously the whole history was compressed and kept. Those rows were never sent to the model, but they did end up in the autosaved session. Flagging it in case a maintainer prefers to keep the dropped prefix. I didn't do that here: with the LLM summary strategy, the shorter compacted tail would pull the old, uncompacted prefix back into the next request's window.

Dead code removed alongside (item 9 of the review), both trivially safe:

  • The modeOverrides ternary. Both branches built the same object; when nonInteractiveMode is false, nonInteractiveAlwaysAllow is already [].
  • The try/catch around maybeAutoCompact. That function catches everything from performAutoCompact itself, and the only other call in it, getAppConfig(), has already run at the top of the loop.

Testing

New conversation-loop.spec.ts case: maxMessages: 2, a context limit the capped view fits under, and two large old rows that only the full history counts. It asserts that no compaction notice is queued and that the full history plus the reply is kept. It fails on main and passes with the fix. The existing auto-compaction specs, which use the default cap, still pass.

Passing locally: tsc --noEmit, biome check and conversation-loop.spec.ts.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the area:tui Terminal UI label Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

nc-review could not produce a verdict this run (agent exit 1). This is a problem with the review agent, not with your pull request. A maintainer can retry with /re-review.

@will-lamerton
will-lamerton force-pushed the fix/tui-auto-compact-capped-gate branch from 2054db1 to adec59b Compare November 11, 2026 15:04
The TUI loop measured the full history against the auto-compact
threshold while the request only sent capMessagesForModel(messages,
maxMessages), so rows the cap already drops could trigger compaction.
Gate on the capped view and adopt the result only when compaction ran,
matching run/--plain and the subagent executor.

Also drop the modeOverrides ternary whose branches built the same
object, and the try/catch around maybeAutoCompact, which never throws.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@will-lamerton
will-lamerton force-pushed the fix/tui-auto-compact-capped-gate branch from adec59b to eeeb9d0 Compare November 11, 2026 15:08
@will-lamerton
will-lamerton merged commit ff0c1ef into main Nov 11, 2026
17 checks passed
@will-lamerton
will-lamerton deleted the fix/tui-auto-compact-capped-gate branch November 11, 2026 15:08
jay23606 added a commit to jay23606/nanocoder that referenced this pull request Nov 12, 2026
…ano-Collective#2066)

The TUI loop measured the full history against the auto-compact
threshold while the request only sent capMessagesForModel(messages,
maxMessages), so rows the cap already drops could trigger compaction.
Gate on the capped view and adopt the result only when compaction ran,
matching run/--plain and the subagent executor.

Also drop the modeOverrides ternary whose branches built the same
object, and the try/catch around maybeAutoCompact, which never throws.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tui Terminal UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant