Skip to content

feat: the conversation compacts itself past the threshold, and a reply refused for its length is answered again - #148

Merged
bencode merged 3 commits into
mainfrom
feat/auto-compaction
Oct 14, 2026
Merged

bencode merged 3 commits into
mainfrom
feat/auto-compaction

Conversation

@bencode

@bencode bencode commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Behavior

Long reading conversations compact automatically only when the model has a known context window of at least 128,000 tokens. Smaller and unknown windows keep manual /compact; a context-length refusal is shown without automatic recovery.

For supported models, compaction runs before sending, between tool turns, or after a context-length refusal. The trigger is min(512,000, max(window - 16,384, floor(window / 2))); the retention budget is min(40,000, floor(0.4 * threshold)). Built-in 1M models trigger at 512K; a 128K window triggers at 111,616 tokens. The retention budget does not guarantee a strict upper bound on the summary plus indivisible messages.

The transcript retains its original messages. A saved summary replaces older context only in subsequent model requests, and the existing message persistence records summaries produced between tool turns. A failure before sending or between turns is logged and the reply proceeds. After overflow, a successful compaction permits one retry; a second refusal stays visible.

Interaction

All three automatic triggers and manual /compact use the compacting state. Readers can edit drafts and prepare attachments, but cannot send during compaction or while stopping. Both the composer and controller enforce this, without clearing a rejected draft or consuming its attachments. Messages queued before an automatic compaction keep their existing delivery behavior.

Compaction can be stopped. Stopping before sending restores the unsent message to the draft. Cancellation is checked after summarization and persistence, so stopping while a summary is saved does not start the interrupted prompt or overflow retry. A summary already saved remains in the conversation. Between-turn status callbacks respect stopping, switching and the active agent.

Proxy

Provider diagnostics are not forwarded. Only HTTP 400 or 413 bodies matching pi-ai's overflow patterns, after excluding rate-limit patterns, become the fixed sentence The model provider rejected the request: context length exceeded. Other refusals retain their status and generic message, including bodies that fail to read.

Validation

  • pnpm check: Biome, TypeScript, unit tests and integration tests.
  • Controller tests verify real context reduction, preservation of the current question, one retry at most, disabled recovery for small/unknown windows, draft and attachment preservation, cancellation during summary persistence, and queued messages across tool-turn compaction.
  • Reader-agent tests cover window eligibility, compaction notifications, failure and cancellation.
  • A lightweight Workbench integration test checks the status, blocked Enter sending, draft editing and the stop button. The recovery test no longer renders a 150,000-character answer.
  • Server tests cover overflow classification, rate limits and private-diagnostic isolation.

… reply's tool calls once the context passes the threshold, and a reply refused for its length is answered again after compacting
…ver for a rate limit, and a refusal whose body fails keeps its status
@bencode
bencode merged commit f90d8f2 into main Oct 14, 2026
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