Repository navigation
feat(cli): context compaction in chat, resume and mission - #456
Merged
Merged
Conversation
…440) tole_core::compaction: compact() summarizes the settled turns before the kept tail with the session's provider and commits one `compaction` entry together with the summary call's usage row (atomic, append-only; the transcript is never rewritten). view() is what the provider sees: the transcript as is, or the latest summary followed by the kept tail; the turn loop now sends view(). due() only looks at calls made after the last compaction, so the summary call never re-triggers it. Inactive until the CLI wires a policy (follow-up PR).
Security review: a model-written summary of possibly-injected tool output reached the wire as prose in the user's voice. The marking is now structural: the summary goes inside the same untrusted-content fence as tool results (forged fence markers neutralized), introduced as a record, not instructions. The system role was not used: it would raise the summary's authority.
chat, resume and mission compact between turns once a prompt reaches --compact-at (default 0.8; config compact_at) of the context window: TOLE_CONTEXT_WINDOW / config context_window, else the window the provider's /models reports for the session's model, looked up lazily (only past 8k prompt tokens, at most once per process). No window: off, said once. A failed summary call is reported and the session continues uncompacted. --no-compaction / config no_compaction turn it off; tole status lists each compaction.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
Merged
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.
What
Part 2/2 of #440: wires the core compaction (#455) into
chat,resumeandmission, with the context window from an explicit setting or the provider's/models.Closes #440.
Why
Long missions and chats hit the model's context window regardless of remaining budget; #455 added the mechanism, this decides when and against which window.
Changes
tole-cli/src/compaction_host.rs(new):Compactor::before_turnruns between settled turns. Window:TOLE_CONTEXT_WINDOW/ configcontext_windowwhen set (owner decision: an explicit setting wins over detection), elseGET /modelsfor the session's model (pinnedfact/modelwins, like the provider) — LAZY: only once a prompt passes 8k tokens, at most once per process (cached, also when none is reported). No window → off, said once. Due →compaction::compact; a failed summary call is reported and the session continues uncompacted.status_linesfortole status.tole-core/src/openai.rs:context_window_of(readscontext_length,context_window,max_context_length,max_model_len,max_input_tokens,top_provider.context_length) andfetch_context_window(same base URL / credentials as chat).--compact-at <0..1](validated),--no-compaction; configcontext_window,compact_at,no_compaction(range-checked, layered with the user config, shown bytole config checkwith sources); envTOLE_CONTEXT_WINDOW> config.chat(only in the settled branch before a new message),resume(before a new instruction; never before completing an unsettled turn),mission(after the budget checks, before each chained turn; the summary call's tokens count toward the budget).tole status: one line per compaction.docs/epics.md(also corrects the feat(sessions): global session index + sessions --all #439 line:resumenames the owning project's command),docs/threat-model.md(the/modelslookup).Testing
/modelsfield parsing;Compactor— no lookup below 8k, detected window triggers once and is fetched once, the summary call does not re-trigger, explicit window wins, no window = off (looked up once), disabled = nothing; status lines; config range checks; settings resolution flag > env > config > default.run+resume×2 compacts before the third turn withTOLE_CONTEXT_WINDOW=10000and with the window from/models; the third request carries the fenced summary and turns 2–3 but not turn 1, while the session file keeps turn 1;--no-compaction, no window, and--compact-at 1.0leave the wire whole;--compact-at 1.5is refused.cargo fmt, clippy (workspace all-targets, bare, shell-tools, mcp, tole-core bare),cargo test --workspace: green. Cora agent review (prepare + finalize): 0 findings,should_block: false.