PR #5018 — v0.26.8: Harness Context Compaction Protocol
The Broader Goal at the End of the Previous PR
Coming out of v0.26.7 (Vizor Interactive write-path), the stated direction for the next
cluster of work was the Harness Context Compaction Protocol: give every harness a way to
survive /clear//compact without losing session state, and give the project a way to
measure whether compaction actually saves tokens rather than just assuming it does. The
design spec (docs/superpowers/specs/2026-10-31-harness-context-compaction-protocol-design.md)
and implementation plan were both landed as their own docs-only PRs first, per the
Design → Plan → Build sequence.
Strategic Shifts in This PR
The original plan scoped context_compaction to register against the Configurability
Framework — a FeatureSpec that would let the feature be toggled per-project once that
framework shipped. On 2026-11-01, scope was explicitly reduced: this feature ships
unconditionally in v0.26.8/Dev Preview, with the Configurability Framework (along
with Companion v2 and Herdr Customizations) deferred to a separate "Expansion
Capabilities" goal/release. CONTEXT_COMPACTION_SETTINGS_SCHEMA is kept as a plain
module constant so a later backfill has a ready shape to register against, but nothing
in this PR imports or calls synlynk.features.registry. This was a deliberate
de-scoping to get the core mechanism shipped without waiting on an unrelated framework.
What This PR Shipped
The plan's 11 tasks were split into two dispatched phases sharing one branch lineage:
- Phase 1 (Tasks 1–6,
dispatch/agy/job-f9bfb0ff): thesynlynk/context_compaction.pymodule skeleton; a shared_gather_snapshot()helper collecting story/goal state, git HEAD/dirty-status, and recent telemetry once per call site;compute_dirty_hash()for dirty-tree marker keying; identity-keyed marker build/parse (SYNLYNK_CONTEXT_COMPACTION_RESUME, keyed by(story_id, head_sha)or(story_id, head_sha, dirty_hash)when dirty); the idempotentcheckpoint()devlog writer; and the 5-part context-pack content model pluspack(). - Phase 2 (Tasks 7–11,
dispatch/agy/job-7c3f3b0a, stacked on Phase 1): thesynlynk context checkpoint/pack/injectCLI subcommand group; thecost_entries.compaction_event_typeschema column ("checkpoint" | "pack" | NULL) for before/after token-spend comparison; andpack_token_budgettruncation oninject().
Two real regressions surfaced during Phase 2 verification and were fixed before merge:
log_cost_entry() had been written against raw SQL and the wrong column names
(tokens_in/tokens_out instead of the production schema's input_tokens/
output_tokens), violating the single-sanctioned-write-path rule (_insert_cost_row is
the only function allowed to write cost_entries); and the two new CLI commands were
missing COMMAND_TAXONOMY entries, which test_docs_sync.py catches by diffing the
generated docs/reference/commands.md against the taxonomy. Both were fixed, the
generated docs regenerated, and the full suite re-run clean (5169 passed at merge time,
now 5381 collected post-release-ceremony) before opening the PR.
Because Phase 2's branch was stacked directly on Phase 1's, merging PR #5018 landed both
phases' work on main in a single squash commit (44cfd324 → 1fd2552d) — no separate
PR was needed for Phase 1.
The PR's own review-and-merge cycle was itself a useful exercise of the Hardened PR
Review Policy: Codex posted a genuine cross-harness QA approval (verified independently
via gh pr view --json reviews, not trusted from the job status label alone), a first
merge attempt was correctly blocked by GitHub when CI failed on a test later confirmed
to be a pre-existing flake on main's own tip commit (same SHA, both pass and fail CI
runs — unrelated to this branch's diff), and a pr update-branch cycle followed by a
second merge dispatch cleared it.
Brainstorm Visuals Used
None — this work proceeded directly from the committed design spec and plan without a separate brainstorm session.
What This Achieved on the Path to Autonomy
This PR is instrumentation for the dispatch loop itself, not a user-facing feature: the
compaction_event_type column exists specifically so a future synlynk capability report (gh:#1993) can measure whether checkpoint/pack compaction actually reduces token
spend per session, rather than assuming it does. It also doubled as a live test of the
Hardened PR Review Policy's reviewer-performs-merge rule under a real CI flake — the
policy held (two bounded update-branch cycles, no bypass, no silent retry past a denial)
and surfaced two process findings (gh:#5011 capability-probe reroute, gh:#5012 Agy
credit exhaustion) now tracked separately rather than lost in dispatch noise.
Strategic Note: The Goal at the End of This PR
v0.26.8 ships the compaction mechanism unconditionally; the next goalpost is the deferred "Expansion Capabilities" cluster (Configurability Framework, Companion v2, Herdr Customizations), plus closing out gh:#5011 and gh:#5012's dispatch-process findings before they're folded into the next harness-capability reassessment pull.