- Status: accepted
- Date: 2026-09-11
- Resolves:
docs/SCTXX-SPEC.md§19 item 2 (readability of Codexcompactedlines) - Affects: §3.4 (
--since-compact), §3.5 (show), §6.2 (Codex adapter), §7.2 (native compactions ledger), §8.5–8.6 (fold seeds, baseline prompt) - Evidence:
specs/006-m2-codex-adapter/research.md, read from thecodex/reference clone; ticket Determine whether Codexcompactedlines carry readable summaries
Terminology, added 2026-09-11. The title says "compaction algorithm" because that is what this decision was called when it was written. Codex has no single local algorithm to adopt: it dispatches between token-budget compaction, remote compaction (server-side), and local model summarisation, and its local summarisation path is a short prompt plus a model call. This ADR's decision is unaffected — it adopts a retention shape and the meaning of a
compactedmarker, and explicitly declines to port the loop. The accurate description of what sctxx reuses, with call sites, isdocs/CODEX-PROVENANCE-AUDIT.md.
sctxx and Codex solve different problems with the same word. Codex's compaction is an in-loop context-window mechanism: when the active context approaches the model's window, it replaces history with a short summary so the thread can continue. sctxx's extraction is post-hoc and offline: it reads a finished transcript and produces a handoff artifact for a different agent.
The spec (§2.1) assessed Codex's compaction path as "thin" and planned to reuse only the Phase-1
memory pipeline, tiered budgeting, rollback replay, truncation, redaction, and the apply_patch
grammar, using the compaction prompts purely as an eval baseline. That assessment was made against an
older revision. The reference clone now contains three compaction implementations, a window bookkeeping
layer, and a summarization-free "token-budget" path — enough that the boundary between reusable and
in-loop-only had to be drawn deliberately rather than assumed.
The blocking question (§19 item 2) was factual: do Codex's compacted lines carry readable summaries?
The answer decides what the M2 adapter emits and whether --since-compact can be built at all.
-
Readability is not guaranteed, and the adapter's current behaviour is correct. A
compacteditem carries readable text when a local summarization ran (message, plus a readablereplacement_history). It carries none when the summary is a server-side encrypted item (remote compaction) or when token-budget compaction ran, which writesmessage: ""by design. The adapter emitsNativeCompactionSummarywhen text exists andSystem { subtype: "native_compaction" }otherwise;str_fieldalready filters empty strings, so the empty-messagecase is handled correctly (src/adapters/mod.rs:272-277,src/adapters/codex.rs:90-103). -
A
compactedline has two meanings and the IR must say which.window_number == nulltogether with areplacement_historyis a legacy history reset: everything before it is gone and the replacement history is the surviving conversation.window_number != nullis a windowed re-anchor: the full transcript is intact and the item only marks a new context window and a reset token baseline.NativeCompactiongains a flag for this and the adapter populates it. -
Adopt Codex's retention shape, not its retention policy. Newest-first user-message fill under a token budget with the summary kept last as the anchor (20,000 tokens upstream) becomes the shape of the bounded
--since-compactseed. sctxx's artifact keeps rendering all user messages (spec §7.2): an artifact is not a context window, andexpandcan always recover detail. -
Do not port the in-loop loop. Triggers, window numbers, prefill baselines, fallback buffers, and world-state accounting exist to decide when to compact. Offline, sctxx only needs to know what a past compaction meant. This keeps the roadmap's "no live in-loop compaction before M6" invariant.
-
Token-budget compaction is treated as external validation, not as new scope. Codex now ships a path that performs no summarization at all and rebuilds the window from canonical context plus retained evidence. That is the same design as sctxx's
--llm noneartifact, and it needs no new mechanism here. -
Codex's Phase-1 tiered budgeting stays vendored as-is, with one explicit exception: its over-budget branch returns an empty evidence string, and sctxx must never degrade that way — budgets fail soft to the deterministic artifact.
- Port Codex's compaction loop. Rejected: wrong product boundary. sctxx reads a finished file; the loop is only meaningful inside a live agent, and the roadmap defers in-loop work to M6.
- Model Codex's
ResponseItemenum to parsecompactedfaithfully. Rejected again (spec D-2):serde_json::Valueprojections keep the adapter tolerant of format drift and keep the crate publishable without acodex-*dependency. - Treat every
compactedline as a hard history boundary. Rejected: on current Codex it would discard the entire pre-window transcript of a session that was never actually truncated — for a tool whose value is recovering exactly that history, the worst possible failure. - Replace sctxx's user-message rendering with Codex's 20,000-token retention. Rejected: it optimises for the wrong budget (model context) and would silently drop user constraints the artifact exists to preserve.
- Mirror
world_state/retained_context/guardian_historyin the IR. Rejected (Ponytail): sctxx's repo reconciliation and ledgers serve the same purpose more portably, from data any provider writes.
NativeCompactionchanges shape (architectural class):schemas/ir.v1.json, adapter snapshots, and the IR round-trip tests move in the same change.ir.v1is unfrozen until M7, so no version bump is required yet; the change follows the normal block lifecycle inspecs/006-m2-codex-adapter/(specify → plan → tasks → implement), not a direct edit.--since-compactbecomes well defined: prefer the newest legacy reset boundary; otherwise the oldest window boundary; seed with that item'smessageas a low-trust summary and say so on stderr.Session.native_compactionsmust actually reach the fold as low-trust seeds (spec §7.2/§7.3). Today it is populated and never read.docs/SCTXX-SPEC.md§19 item 2 is resolved by this ADR and annotated in place; §6.2'scompactedmapping stands unchanged.- Licensing follow-up: the reference clone cannot be verified as the pinned commit
(
818f1cca8ccf8899f0f4d59336baebaccf358eed). The pin is asserted inAGENTS.md, spec §2.3 and Appendix A,src/vendor/codex/README.md, and every vendored header, so it must be reconciled before M4 publishes. Tracked separately; it is a governance item, not an adapter blocker. - Revisit if a future Codex revision drops the legacy
replacement_historypath entirely: the windowed/legacy flag then collapses to a constant, and the adapter change becomes dead weight.