design: use knox state to improve compaction #28

Open
opened 2026-11-05 03:53:53 +00:00 by david · 0 comments
Owner

Compaction is where a long session loses its thread: the transcript is summarised generically, and decisions, open questions and evidence provenance are the first things to go.

knox already holds the structured version of what a compaction is trying to reconstruct — entries, threads with motivation, claim-ledger state, recent observations — and it is now fresh at turn start.

Hook contract (verified in the V2 docs)

compaction is a session request hook:

  • messages — the transcript being summarised
  • system — mutable, same as context
  • result?: SessionCompactionResult — set it to record the compaction yourself and skip the model call

So there are two shapes:

A. Augment (safe, recommend first) — push a system part carrying knox state, let the model write the summary as usual. The summary keeps its usual quality and gains structure. No risk of replacing summarisation with something worse.

B. Replace (powerful, risky) — generate the compaction from knox alone. Cheap and deterministic, but any detail knox never ingested is silently lost, and a bad compaction poisons the rest of the session.

Proposed v1 (A)

  1. On compaction, query knox for: open threads (title + motivation), claims currently due, and the last N observations in this project.
  2. Push a bounded system part (~400 tokens): "durable state you should preserve".
  3. Session-gated: only for sessions in a project knox knows.
  4. KNOX_COMPACTION=augment|off, default off until observed.

Why not ship it live today

Compaction only fires on long sessions, so it cannot be exercised by a unit test or a short run. The failure mode is a session that continues confidently with a wrong summary — the same class of error this repo keeps hitting, but self-inflicted and hard to notice.

Verification path: enable augment on one long session, diff the resulting summary against one produced without it, and only then consider defaults.

Open questions

  • Should the injected state be project-scoped or session-scoped? Project-scoped risks leaking unrelated work into a summary.
  • Replace-mode needs a fallback: if the knox query fails or returns nothing, fall through to the model rather than writing an empty summary.
Compaction is where a long session loses its thread: the transcript is summarised generically, and decisions, open questions and evidence provenance are the first things to go. knox already holds the structured version of what a compaction is trying to reconstruct — entries, threads with motivation, claim-ledger state, recent observations — and it is now fresh at turn start. ## Hook contract (verified in the V2 docs) `compaction` is a session request hook: - `messages` — the transcript being summarised - `system` — mutable, same as `context` - `result?: SessionCompactionResult` — set it to record the compaction yourself and **skip the model call** So there are two shapes: **A. Augment (safe, recommend first)** — push a system part carrying knox state, let the model write the summary as usual. The summary keeps its usual quality and gains structure. No risk of replacing summarisation with something worse. **B. Replace (powerful, risky)** — generate the compaction from knox alone. Cheap and deterministic, but any detail knox never ingested is silently lost, and a bad compaction poisons the rest of the session. ## Proposed v1 (A) 1. On `compaction`, query knox for: open threads (title + motivation), claims currently due, and the last N observations in this project. 2. Push a bounded system part (~400 tokens): "durable state you should preserve". 3. Session-gated: only for sessions in a project knox knows. 4. `KNOX_COMPACTION=augment|off`, default **off** until observed. ## Why not ship it live today Compaction only fires on long sessions, so it cannot be exercised by a unit test or a short run. The failure mode is a session that continues confidently with a wrong summary — the same class of error this repo keeps hitting, but self-inflicted and hard to notice. Verification path: enable `augment` on one long session, diff the resulting summary against one produced without it, and only then consider defaults. ## Open questions - Should the injected state be project-scoped or session-scoped? Project-scoped risks leaking unrelated work into a summary. - Replace-mode needs a fallback: if the knox query fails or returns nothing, fall through to the model rather than writing an empty summary.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/knox#28