Repository navigation
Description
Background
Recent Claude Code compact analysis shows a stronger mechanism than a passive transcript summary. Claude Code treats compact as provider-visible history replacement layered on top of durable transcript/session state.
The important distinction for Maka is active-loop replacement: in Claude Code, each query() loop derives a provider-facing messagesForQuery before the next model call. That derived view can be sliced after a compact boundary, tool-budgeted, snipped, microcompacted, context-collapsed, or fully compacted before the provider request is sent.
For long Terminal-Bench tasks such as qemu-alpine-ssh, Maka currently needs this active-loop behavior, not only replay-time/prior-history pruning.
Claude Code mechanism to copy
The effective Claude Code pipeline is roughly:
- Start from durable/in-memory history.
- Slice after latest compact boundary.
- Strip UI-only tool payloads.
- Apply tool-result budgeting.
- Apply snip/microcompact/context-collapse projections.
- Optionally run proactive/predictive/reactive full compact.
- Replace the provider-facing request with compact output before the next model call.
- Persist durable boundary/summary/restored context for resume and transcript integrity.
Full compact output is installed as:
compact boundary -> compact summary -> kept messages -> restored attachments -> hook results
The summary/restored context are model-visible replacement content. The compact boundary is mostly durable/session structure plus UI/SDK signal.
Current Maka gap
Maka has active/current-turn tool-result prune, which is the right family of mechanism because AI SDK prepareStep can replace messages before the next model step.
But active tool-result prune is intentionally narrow:
- It replaces oversized current tool result payloads with archive placeholders.
- It does not summarize a long active attempt or contiguous runtime-event span.
- It does not create a durable active-loop compaction boundary covering raw RuntimeEvent IDs.
- It does not produce a benchmark/process-state summary that replaces the hot same-attempt transcript.
For qemu-alpine-ssh style runs, the token growth is not just one huge tool result. It is a chain of shell observations, VM state, file edits, failed hypotheses, retries, public/self-check output, and process state. That needs an active full-compact mode.
Proposal
Add a provider-visible active-loop full compaction mode for long benchmark/task runs.
At a high level:
- Detect a compact trigger before the next provider step in the same active run.
- Select a contiguous RuntimeEvent range or semantic phase to compact.
- Archive raw command output and other raw evidence outside the hot prompt.
- Generate a model-visible compact replacement summary.
- Persist a durable compaction event/boundary that covers the raw event IDs.
- Make the next provider request use the compact replacement instead of raw covered payloads.
- On replay/resume, project through the compaction event by default, with raw archive retrieval available on demand.
This should complement, not replace, current active tool-result prune:
activeToolResultPrune: cheap, local, single oversized tool-result defense.activeFullCompact: summarize and replace a larger active-loop span.staleReplayPrune: shrink prior/replayed history.replaySummaryCompact: summarize older completed turns/attempts.
Durable event shape
The compaction event should record enough to debug and replay the provider-visible truth:
- trigger and threshold reason
- task/attempt/turn/phase identifiers
- covered RuntimeEvent IDs
- archive refs for raw evidence
- compact summary message ID/ref
- preserved head/tail anchors, if any raw messages stay visible
- pre-active-context token estimate
- post-replacement token estimate
- next provider actual usage when available
- request-shape hash for the post-compact provider request
- whether the next step would immediately retrigger compaction
- compact-call usage if a summarizer model is used
Benchmark summary schema
For Terminal-Bench and especially QEMU-like tasks, the model-visible compact summary should be structured, not freeform only. It should preserve:
- current process and port state
- VM/guest boot state
- important artifact paths and files changed
- commands already tried and their outcomes
- latest public verifier or self-check failure
- known constraints from task prompt
- abandoned paths / failed hypotheses
- current hypothesis
- exact next action candidates
- archive refs for raw logs/output that can be reopened by tool
Acceptance criteria
- A long same-attempt run can compact before the next model step, not only between top-level attempts.
- The next provider-visible message list contains the compact summary/replacement and does not include raw covered oversized payloads by default.
- The raw evidence remains available through archive refs and can be retrieved explicitly.
- Resume/replay uses the compaction event to reconstruct compacted provider-visible history.
- Runtime trace/export shows covered RuntimeEvent IDs, archive refs, summary ref, and token estimates.
- Telemetry includes pre estimate, post estimate, compact-call usage, next provider actual usage, and saved-token/economic fields.
- A regression test proves current active tool-result prune and active full compact can compose in one AI SDK multi-step loop.
- A benchmark-style fixture, ideally modeled after
qemu-alpine-ssh, proves compaction preserves process/task state while removing raw high-volume output from the next provider request.
Notes
This issue is based on a Rive/Codex read of Claude Code compact behavior. The key lesson is not to copy every Claude-specific feature such as cached microcompact or Anthropic cache edits. The product requirement for Maka is provider-neutral active-loop replacement with durable evidence boundaries and clear token economics.
Activity
likun666661 commentedon Jun 27, 2026
Design framing update after comparing current Maka compaction with the #327 target:
The next design should not treat active full compact as a one-off special case. A cleaner framing is:
priorReplayprojection: builds the next large-turn/retry/resume provider history from persisted RuntimeEvents.activeStepprojection: reshapes the in-flight same-turn provider messages before a later model step.Suggested abstraction names for the implementation:
CompactionSource: prior history or active same-turn source.CompactionStage:priorReplayoractiveStep.CompactionPlan: selected coverage, preserved head/tail anchors, target token budget, and trigger reason.CompactionBoundary: rendered model-visible block plus coverage ids, archive refs, hashes, schema version, and validation status.CompactionProjection: the provider-visible messages/events after applying the boundary.CompactionDecision:unchanged | replaced | failedOpen, with diagnostics and token economics.This keeps existing prior-history mechanisms useful while making #327 the missing active projection stage. Stale prune, history compact, synthesis cache, archive retrieval, and active full compact can then converge toward one explainable coverage/boundary/diagnostic contract instead of remaining separate ad hoc prompt-shaping paths.
Proposed upstream PR sequence for #327 after reviewing the active full compact design:
Data model, ledger boundary, archive refs, and replay projection skeleton
packages/core/src/runtime-event.ts,packages/runtime/src/context-budget.ts,packages/runtime/src/model-history.ts,packages/runtime/src/ai-sdk-backend.ts, plus focused runtime helper/tests.Provider-visible active full compact in the AI SDK step builder
prepareStepafter tool availability and active tool-result prune; compose with active prune archive placeholders; preserve the current user task, incomplete tool continuity tail, and at least the latest complete tool-call/result pair; add anti-spiral gates and deterministic writer support.packages/runtime/src/ai-sdk-backend.ts,packages/runtime/src/model-adapter.ts,packages/runtime/src/active-tool-result-prune.ts, and a new active-full-compact runtime module.Benchmark/process-state summary builder and QEMU-style fixture
Replay/resume/export/inspection and telemetry economics
Optional follow-up: trigger policy and operational tuning
minStepNumber, high-water thresholds, target tokens,minCoveredEstimatedTokens, recent-tail preservation, failure limits, and Harbor/headless env flags after fixture data exists.Out of scope for the first sequence: Anthropic cache edits/cache references, Claude
context_management, UI transcript affordances, mutation of old RuntimeEvents, and replacement of the existing replay-only history compact/archive retrieval/synthesis cache paths. Those existing paths should be preserved, then gradually aligned behind the shared compaction boundary/projection contract where it actually reduces duplication.likun666661 commentedon Jun 28, 2026
Follow-up source read after the QEMU active-full-compact run hit the
max_block_tokenscliff.I used a separate Rive workflow to read the latest issue framing, the QEMU notes, the local Claude Code compact source, and the current Maka active-full-compact implementation. The important correction is that Claude Code does not appear to put exhaustive audit/source/coverage metadata into the provider-visible compact summary.
Source-backed conclusion:
Implication for Maka:
The QEMU
max_block_tokensfailure is likely Maka-specific. Our current active compact block format carries summary text plus growing provider-visible coverage/source/hash/sourceRef metadata, and subsequent active high-water attempts are not yet folding the provider projection onto the latest accepted active boundary/replacement. That combination makes the candidate compact block grow until validation fails open.Design update for this issue:
prepareStep/ active provider projection should start from the latest accepted active boundary and skip covered raw active entries before making high-water and candidate-block decisions.This slightly changes the PR ordering I would take from here: first implement boundary-aware active projection and off-prompt audit storage, then tune visible block budget/trigger policy. The old shared boundary/projection framing still holds; the sharper lesson is that provider projection and audit/provenance must be separated.