Skip to content

docs(plans): plan mid-run compaction (F03) and propose the retention contract (F20) - #91

Merged
lg2m merged 1 commit into
fix/eng-796-f11-snapshot-byte-budgetfrom
docs/eng-793-f03-mid-run-compaction-plan
Sep 21, 2026
Merged

lg2m merged 1 commit into
fix/eng-796-f11-snapshot-byte-budgetfrom
docs/eng-793-f03-mid-run-compaction-plan

Conversation

@lg2m

@lg2m lg2m commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Linear: ENG-793 (F03), ENG-803 (F20). Stack 3/3 — based on #90; retarget to main after #89 and #90 merge. Docs only; the ledger is the only overlapping file.

Neither finding is code-ready, and the audit's remaining order-2 items are otherwise accounted for: F24 is in review on another lane (ENG-805), F28 is a paid eval (ENG-807). This PR writes the two decisions down so they get made once, in review.

docs/plans/mid-run-compaction.md (F03)

A run whose turn N+1 no longer fits today stubs stale results and then fails (CompactionDisposition::BetweenRunsOnly). The plan proposes compacting and continuing the same run:

  • Safe boundary: turn persisted; no pending approval; no half-applied steering; no awaited child.
  • What the resumed turn sees: unchanged static prefix → summary (may cover this run's own oldest turns) → verbatim prompt → last K whole turns with the F23 projection → steering in place → one continuation notice. Accounting/budgets/children/cancellation carry over untouched.
  • Durable protocol: Decide → Mark (runs.compaction_resume_turn) → Summarize (F04 fold steps, cutoff may fall inside the run via cutoff_turn_ordinal) → Resume → Crash/Cancel semantics.
  • Slices MRC-0..5 with acceptance; MRC-0 is the ADR (reserved 0039).
  • Five open questions for that ADR (keep-K policy, steering in the summarized span, reactive vs proactive trigger, per-run compaction cap, owned-child results).
  • Why not: stub harder, auto-start a follow-up run, persist the assembled context.

docs/adr/0038-session-retention.md (F20, Proposed)

  1. Unit of retention is the session, never the row.
  2. Archive is a state (archived_at_ms), not a second store.
  3. Auto-archive is age/idleness-based on roots with their subtree; never size-based; never touches an active run; admitted under F07 headroom.
  4. Deletion is explicit and cascades — now including the session's events.
  5. Receipts are never trimmed.
  6. Cursors fail closed; next_sequence never rewinds.
  7. WorkspaceLimitApproaching at 80 % / 95 % plus WorkspaceSummary.limits.
  8. Export as JSONL of protocol types.

Two facts verified against the store while writing it, worth knowing regardless of the ADR's fate:

  • commands already has no reference to sessions, so receipts survive deletion by accident today.
  • delete_idle_session removes every session-scoped table except the session's rows in events — the event log grows regardless of deletion.

Also

ADR index entry; plans/README.md rows; progress/root.md reservations 0038/0039 (next free 0040), F03/F20 rows, dated entry.

Review asks

Decide on the ADR's eight points and the plan's five questions here. Accepting 0038 turns ENG-803 into a plan; accepting the boundary in the plan lets MRC-1/MRC-2 start in parallel.

…contract (F20)

Neither finding is code-ready. F03 needs a decision on where a run may
compact and what the resumed turn carries; F20 needs a retention contract
before any archival, export, or limit signal is built. This commit writes
both down so the decisions can be made once, in review, rather than
re-litigated inside an implementation PR.

`docs/plans/mid-run-compaction.md` (ENG-793): defines the safe turn boundary
(turn persisted, no pending approval, no half-applied steering, no awaited
child), what the resumed turn must see (static prefix, summary that may cover
the run's own oldest turns, verbatim prompt, the last K whole turns with the
F23 projection, steering in place, one continuation notice), a durable
Decide/Mark/Summarize/Resume/Crash/Cancel protocol built on F04's fold steps
with a `cutoff_turn_ordinal` qualifier, slices MRC-0..5 with acceptance, five
open questions for the ADR, and why stubbing harder or auto-starting a
follow-up run are worse. Reserves ADR-0039 for MRC-0.

`docs/adr/0038-session-retention.md` (ENG-803, Proposed): the unit of
retention is the session; archive is a state, not a location; automatic
archival is age-based on idle roots with their subtree and never size-based;
deletion is explicit and cascades, now including the session's events;
receipts are never trimmed; cursors fail closed; approaching-limit events at
80 % and 95 %; export as JSONL of protocol types. Two facts checked against
the store while writing it: `commands` already has no reference to
`sessions`, and `delete_idle_session` leaves a deleted session's rows in
`events`, so the event log grows regardless of deletion today.

Index and ledger: plans README rows, ADR index entry, ADR reservations 0038
and 0039 (next free 0040), F03 and F20 rows in `progress/root.md` and a dated
entry. No code.
@lg2m
lg2m added this pull request to stack #93 September 21, 2026 02:53
@lg2m
lg2m merged commit f652d36 into main Sep 21, 2026
4 checks passed
@lg2m
lg2m deleted the docs/eng-793-f03-mid-run-compaction-plan branch September 21, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant