# Milestones

- Implementation started from 59826ec818aa8883329a74c62000d18aa1e1dbfe; clean working tree. Planning baseline: 896 tests, TypeScript, and existing context gate passed.
- Inspection found context capture counted all registered tools while omitting SDK snippets/guidelines; drafting/compaction fixtures did not actually drive those lifecycle states.
- Activity derivation measured locally at p50 0.107 ms/1k, 1.181 ms/10k, 18.816 ms/100k events.

- Corrected the measurement harness before runtime changes. It now uses actual active schemas, SDK tool snippets/guidelines, complete conversation records, goal-tool/custom messages, and isolated auditor/Oracle requests. Drafting and compaction fixtures now invoke their real lifecycle paths. The baseline is original HEAD in an isolated checkout with the identical corrected measurement harness.
- Added version 2 per-goal ledger indexes, bounded activity/recent projections, retained audit/Oracle state, incremental appends, and UTF-8 checkpoint offsets. Fixed a first-warm-append double-count when checkpoint bootstrap already included the appended event. Explicit history remains authoritative JSONL.
- Preserved original persisted revisions across buffered changes. Conflicting writers reject speculative updates before audit. Lock contention retains the pending transaction, including across focus changes; a later flush cannot steal focus back. Immediate task batches read/validate the fresh disk tree under the lock, including external edits that did not increment a revision.
- Added lossless 4,000-character detail pages with source-bound cursors, atomic ordered task updates, lifecycle-dependent active tools, bounded objective/current/next-three-task context, and content-keyed task presentation caches. Existing single-task calls, verbose/history reads, ordinary tools, drafting, recovery, and saved record formats remain supported.
- Compatibility tests initially failed because they asserted the previous fixed five-tool surface. Updated those expectations for valid lifecycle states. Added paging/Unicode/stale-cursor, rollback, child-parent ordering, competing writers, external task edits, locked focus switches, cache invalidation, and corrupt checkpoint tests.
- The first cold-rebuild benchmark regressed. Removed duplicate reconstruction/recent-tail scans, avoided a second object allocation per parsed ledger event, used binary insertion only for out-of-order activity timestamps, and avoided formatting distinct activity records while indexing. Timing samples and filesystem counts are measured separately from V8 allocation sampling.
- SDK request cross-checks now compare six real outgoing payloads (four executor profiles with conversation content, auditor, Oracle) before network dispatch. This exposed incorrect isolated child-system measurement and Oracle session-manager/resource configuration; fixed both. Child sessions share the metered runtime, honor cancellation, and dispose resources.
- Live fallback selection preceded the user's reply: GLM task execution and Sisyphus/compaction pairs passed. The first audit/rework attempt stalled; the harness deadline did not reach the separate audit controller. Terminated it, reserved its entire 12-request maximum ($0.924576), and fixed child cancellation. A second GLM attempt was stopped promptly on the user's DeepSeek selection; its pending $0.077048 reservation is retained.
- User steering: use DeepSeek V4 Flash on OpenCode. The authenticated connection is `opencode-go`; `opencode` itself has no configured authentication. Kept the US$5 campaign cap across models and used identical high reasoning settings and eight-request ceilings per paired DeepSeek run. All six DeepSeek runs produced correct artifacts; both rework cases independently rejected the missing artifact. Only the optimized task case finished the complete audited lifecycle within the limit. Incomplete cases are reported explicitly; this sample cannot establish statistical equivalence.
- Confirmed 911 full-suite tests pass after the added regression coverage. TypeScript, lint, 24-fixture context gate, historical performance gates, and the SDK 0.84 serial compatibility suite passed. SDK 0.83 passed TypeScript and the serial tests except a missing copied shell-harness fixture; copying that fixture and rerunning its test passed. All six provider cross-checks passed on SDK 0.83 as well. Final runtime gate and evidence are recorded in RESULTS.md.

## Context baseline rationale

The previous baseline excluded active-tool filtering and SDK guidance and did not actually exercise several named states. Replacing it is a measurement correction plus an intentional interface update, not a claim against those earlier incomplete counts. CONTEXT-BEFORE.json and CONTEXT-AFTER.json use identical corrected capture code against original HEAD and the candidate. The committed main context baseline tracks final behavior; historical benchmark campaigns remain untouched.

## Delivery

Changes are recorded on `codex/runtime-token-optimization` in three local commits: measurement corrections (`882178a`), runtime improvements (`b3e6364`), then model-facing changes and final evidence. The runtime-only staged tree was independently extracted and passed TypeScript, its full test suite, and a freshly captured context gate before committing, so that phase can be inspected or reverted separately. The final acceptance gate passes: 38.0% lower active-workflow extension context; 100k-event activity p50 12.203 → 0.010 ms; cold rebuild p50 68.135 → 64.959 ms. No changes were pushed remotely.
