OpenProgram Docs

Compaction tiers

WhenStepActionLLMBreaks cacheStatus
When a result is madeBudget ReductionBounds one tool result over its weight cap, onceNoNoBuilt
Before a turn, at the auto-compact share; or /compactAuto-CompactOne rolling summary per chainOnceYesBuilt
Between a turn's steps, at the auto-compact shareMid-turnAuto-Compact of the history before the turn; once per turnOnceYesBuilt
Provider reports overflowReactiveAuto-Compact, then the same request again; once per request, twice per turnYesYesBuilt
Each provider request, over budgetRequest checkpointOne checkpoint of the older prefix, in that request onlyBoundedYesBuilt
Still over, about 90%Context CollapseSegment summaries, originals keptPer segmentYesNot built

Summary semantics: Compaction. Claude Code's version of this ladder: Claude Code compaction. /context shows the token distribution.

Budget Reduction
AspectRule
ScopeTool results only, not user or assistant messages
Thresholdspill.result_cap(): a weight of 10,000 (or the model's tool_output_weight), at most 30% of the window; applied once, when the result is made. Old results are never aged: they stay whole until Auto-Compact
MethodKeeps head and tail about 60/40 on line breaks, keeps the whole text in a file and names the lines to read
Codeagent/loop/tool_dispatch.py _as_stored, state/store/session/files/spill.py bound_text
Auto-Compact and Reactive

Auto-Compact is the pipeline in Compaction. /compact [tokens] takes how many recent tokens to keep. Mid-turn and Reactive run in the agent loop (Overflow recovery) on the branch the turn runs on; a Stop ends the summary request.

Context Collapse (design)
  • Trigger: still over, about 90%; blocking at 95%.
  • 5–10 turns per segment, each summarized in about 100–300 tokens; LLM calls equal segments (30 turns in 3 segments: 3 calls).
  • Originals stay in a collapse store through read-time projection.

Function-call nodes

A DAG addition with no Claude Code counterpart.

Node stateContextCompaction
RunningInside: subtree fully expanded. Callers: expose=io by default, input and output only. Controlled by render_context callers, subcalls and exposeInner tool outputs get Budget Reduction.
Completed or errorexpose=io hides the subtree with no extra step; children stay inspectable in the DAG and readable through toolsInput and output are treated like a conversation node

Rolling summary

Beyond Compaction:

  • Always retain the latest complete user turn, and by default the latest two; the token budget may allow fewer than twenty top-level messages.
  • A posted report is a boundary too, so a run of reports can be folded even with no user message between them; only the tail that fits stays.
  • A large completed tool-heavy turn must not make compaction ineffective, so the cut moves to the next complete user boundary. An active user turn is never split, and its tool evidence is not discarded without entering the summary.
  • Summary input and covers_ids describe the same range.
  • Estimates include summary markers and tool results. The completion event reports both token counts and whether a summary was applied.
  • Historical incorrect summaries are not rewritten; nothing is migrated or deleted.
  • Session-graph compaction scope uses the same message snapshot, so a repeat during loading stays consistent.
Acceptance
  • With large tool results among sixteen top-level messages, coverage includes complete older turns and context shrinks.
  • The summary receives every replaced user request and visible tool result; recent turns are unchanged.
  • Equal or longer summaries, cancellation, provider errors and edits during the call write nothing.
  • Repeated compaction, branch switching, occupancy statistics and final requests render consistently.

Request checkpoint scope

Rules: Request checkpoint. Beyond those:

  • Measured after message conversion, memory injection and actual-tool resolution; rechecked on every send and for fallback models.
  • Cache belongs to the current AgentContext and never spans function views.
  • It serves calls that cannot compact durably. It does not replace DAG summaries or promise lossless semantics or exact agreement with provider counts.

Request checkpoints

StageBehaviourBoundary
BudgetCounts system prompt, tools, response schema, output reserve, historyRecalculated for fallback models
CheckpointOlder complete text-only prefix becomes a task summaryNever splits tool groups or discards multimodal or unresolved content
Summary requestAll source text in budgeted chunks with rolling summariesCancellation, errors and exhausted budgets keep the original
ContinueSends only a verified smaller requestRaw messages and DAG nodes unchanged

Adapted from Codex local compaction, which keeps user messages and replaces execution history. OpenProgram copies no Rust source, truncates no user instructions, adopts no remote encrypted compaction and keeps the DAG. The checkpoint text is assistant data, never system instructions.

Acceptance
  • AgentLoop continues after long assistant text and tool arguments exceed a model window.
  • Every retained tool call has its result; the latest execution and user messages are exact.
  • Summary calls fit the window, cover the full source and recover from provider overflow without dropping input.
  • Cancellation, changed prefixes, model switches and non-text evidence do not reuse incompatible summaries.
  • Open: installed-App acceptance.
A long session, 200K context
  1. 0–30%: Budget Reduction only.
  2. paper_agent runs: its tool calls expand inside, oversized outputs are truncated; on completion expose=io hides them.
  3. The share is reached: Auto-Compact replaces older turns with one summary.
  4. A long tool run inside one message: Mid-turn compacts the history before it.
  5. The provider overflows: Reactive, then the same request again.
  6. A call that cannot compact durably: request checkpoint.
Last updated · 2026-11-25