Skip to content

fix(ai): stop compacting the chat on a context window we never measured - #286

Merged
EtienneLescot merged 1 commit into
mainfrom
fix/no-auto-compaction
Aug 5, 2026
Merged

fix(ai): stop compacting the chat on a context window we never measured#286
EtienneLescot merged 1 commit into
mainfrom
fix/no-auto-compaction

Conversation

@EtienneLescot

@EtienneLescot EtienneLescot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Every turn began by measuring the history against DEFAULT_BUDGET_TOKENS = 80_000 and, past 70% of it, blocking on a whole extra summarizer call before
the user's request was even sent — a call that also pays the reasoning budget,
so on a thinking model it is not a cheap one.

That 80k was invented. The app cannot ask a provider how big its context
window is, so the number could not be right for anything: it discards context
at 5% fill on a 1M-token Gemini, and would be far too generous elsewhere. It
is the same mistake getTranscript made with its 800 segments, and it gets
the same answer — a guessed limit is deleted, not retuned. Until the app can
learn a real window, the only honest trigger is a person deciding they want
one, which is the button that already exists.

The same guess also gated the manual path: compactSessionNow went through
the identical heuristic, so on any ordinary conversation pressing Compact did
nothing at all, silently. Pressing it is now the decision. The one refusal
left is "fewer than 4 messages", which is not a guess about anyone's context
window — folding a single exchange into a summary cannot make it shorter —
plus the existing measured guard that refuses a summary no smaller than what
it replaces.

compactionBlocked goes with it: it existed only to stop the automatic path
re-buying the same useless summary, and nothing retries on its own any more.
DEFAULT_BUDGET_TOKENS survives as the context pill's denominator and nothing
else; both it and its renderer twin now say in writing that they must never
regain a decision.

Verified by ablation: re-adding the automatic trigger turns four of the six
compaction tests red, including the one that pins that a turn never summarizes
anything by itself.

Summary by CodeRabbit

  • New Features

    • Context compaction is now triggered explicitly rather than automatically during chat.
    • Manual compaction works across supported conversation lengths and preserves the active user turn.
    • Conversation history is split at sensible user-message boundaries when possible.
  • Bug Fixes

    • Failed or ineffective summaries no longer alter the chat session.
    • Context budget estimates no longer incorrectly control compaction decisions.

Every turn began by measuring the history against `DEFAULT_BUDGET_TOKENS =
80_000` and, past 70% of it, blocking on a whole extra summarizer call before
the user's request was even sent — a call that also pays the reasoning budget,
so on a thinking model it is not a cheap one.

That 80k was invented. The app cannot ask a provider how big its context
window is, so the number could not be right for anything: it discards context
at 5% fill on a 1M-token Gemini, and would be far too generous elsewhere. It
is the same mistake `getTranscript` made with its 800 segments, and it gets
the same answer — a guessed limit is deleted, not retuned. Until the app can
learn a real window, the only honest trigger is a person deciding they want
one, which is the button that already exists.

The same guess also gated the manual path: `compactSessionNow` went through
the identical heuristic, so on any ordinary conversation pressing Compact did
nothing at all, silently. Pressing it is now the decision. The one refusal
left is "fewer than 4 messages", which is not a guess about anyone's context
window — folding a single exchange into a summary cannot make it shorter —
plus the existing measured guard that refuses a summary no smaller than what
it replaces.

`compactionBlocked` goes with it: it existed only to stop the automatic path
re-buying the same useless summary, and nothing retries on its own any more.
`DEFAULT_BUDGET_TOKENS` survives as the context pill's denominator and nothing
else; both it and its renderer twin now say in writing that they must never
regain a decision.

Verified by ablation: re-adding the automatic trigger turns four of the six
compaction tests red, including the one that pins that a turn never summarizes
anything by itself.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cbd539c7-0dc2-4a26-b12f-642972aea249

📥 Commits

Reviewing files that changed from the base of the PR and between 135c360 and 74b7003.

📒 Files selected for processing (5)
  • electron/ai-edition/chat-compaction.test.ts
  • electron/ai-edition/chat-compaction.ts
  • electron/ai-edition/chat-service.compaction.test.ts
  • electron/ai-edition/chat-service.ts
  • src/components/ai-edition/chatBudget.ts

📝 Walkthrough

Walkthrough

Chat compaction is now caller-controlled. Automatic pre-turn compaction was removed. Split planning no longer uses token budgets. Manual compaction validates summaries and preserves session state when compaction does not reduce history.

Changes

Chat compaction behavior

Layer / File(s) Summary
Compaction split planning
electron/ai-edition/chat-compaction.ts, electron/ai-edition/chat-compaction.test.ts, src/components/ai-edition/chatBudget.ts
compactionSplitIndex replaces shouldCompact. It selects a midpoint or later user boundary without token-budget gating. The budget value is documented as display-only.
Explicit service compaction
electron/ai-edition/chat-service.ts, electron/ai-edition/chat-service.compaction.test.ts
Chat turns no longer compact automatically. Manual compaction uses the split index, rejects non-reducing summaries without session mutation, and preserves transcript and current-turn behavior. Tests cover large and ordinary histories, retries, payload summaries, and repeated manual compaction.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: arhxam

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/no-auto-compaction

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@EtienneLescot
EtienneLescot merged commit 90ae294 into main Aug 5, 2026
14 of 15 checks passed
@EtienneLescot
EtienneLescot deleted the fix/no-auto-compaction branch August 5, 2026 14:30
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.

1 participant