Repository navigation
feat: the conversation compacts itself past the threshold, and a reply refused for its length is answered again - #148
Merged
Merged
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ismin(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
/compactuse 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.