Skip to content

Give HTTP chat context management: windowing, compaction, and a compaction event#561

Merged
tobocop2 merged 7 commits into
mainfrom
feat/http-chat-compaction
Jul 19, 2026
Merged

Give HTTP chat context management: windowing, compaction, and a compaction event#561
tobocop2 merged 7 commits into
mainfrom
feat/http-chat-compaction

Conversation

@tobocop2

@tobocop2 tobocop2 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Problem

The TUI manages conversation context before every turn: it windows history to a token budget and, with chat_compaction on, folds the overflow into a rolling summary. The HTTP surface had none of this. History went to the model verbatim, so long conversations eventually overflowed the context window, and any HTTP client wanting compaction would have had to rebuild it from scratch.

What changed

/api/chat and /api/chat/stream now window incoming history to the same budget the TUI uses, and run the same compaction when the toggle is on and the conversation is over the trigger.

ChatRequest gains two optional fields: summary, the carry-forward notes folded into the prompt, and session_id, the session that receives a fresh summary when a turn compacts. A deleted session is tolerated, matching the TUI.

How clients see it

Streaming turns announce the work: a compacting event fires before the condensing model calls start (same idea as warming/warm), then a compaction event carries the new summary plus how many turns were condensed and how many were dropped without notes. The non-stream route reports the same result on a new optional compaction field of the response.

Notes

The history budget fraction moved out of the TUI screen into the shared compaction module, so both surfaces derive it from one place. With compaction off nothing new is emitted; the only behaviour change is that history is now windowed instead of overflowing.

@tobocop2 tobocop2 changed the title Give HTTP chat the TUI's context management: windowing, compaction, and a compaction event Give HTTP chat context management: windowing, compaction, and a compaction event Jul 19, 2026
@tobocop2
tobocop2 merged commit e0afc60 into main Jul 19, 2026
33 of 34 checks passed
tobocop2 added a commit that referenced this pull request Jul 20, 2026
…at-window clamp with #561

Main's #561 centralized the generation reserve and window margin into providers/base.py as prompt_token_budget(); this branch had rewritten the same _fit_chat_context lines to add the over-reservation clamp. Resolved by re-expressing the clamp via prompt_token_budget: a num_predict past the default shrinks the budget, and when the windowed prompt then does not fit, it falls back to the default budget (wider) instead of being rejected. Removed the branch's now-deleted _DEFAULT_GENERATION_RESERVE/_CONTEXT_WINDOW_MARGIN constants, corrected base.py's 'enforces and rejects' comment to note the clamp, and dropped a merge-duplicated probe-failure test in favor of main's canonical #540 pair.
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