The harness state store persists immutable events, current projections, checkpoints, provider references, approvals, and tool attempts. Memory is a governed projection for future context, not raw history. Compaction reduces model-visible context while preserving source links and operational truth. Never compact away authorization, budgets, pending effects, or evidence required to resume safely.
You will design the state tables, write memory acceptance rules, and distinguish context summaries from durable records.
Use transactions or an outbox so state changes and emitted events cannot silently diverge.
Apply events in sequence to rebuild a projection. Reject duplicates by event ID and gaps by expected sequence. Snapshots accelerate replay but must include schema version and last event sequence.
Accept memory only when it has a purpose, scope, provenance, validation path, and retention rule. Separate user-declared preferences, verified business facts, generated summaries, and speculative inferences. Most speculative inferences should not become durable memory.
A compacted context should include goals, confirmed facts with source IDs, completed steps, pending questions, constraints, tool outcomes, and next safe action. The event store retains the full operational record. Store the compaction algorithm/version and source range.
Failure injection: Compact a conversation while an approval is pending. Resume must still know exact tool arguments, proposal hash, budget, and approval expiry from the checkpoint—not from a prose summary.
Test event replay, duplicate delivery, gaps, concurrent updates, snapshot migration, corrupted checkpoint hash, expired memory, deletion, and compaction equivalence on required facts.
Implement an in-memory event store and reducer with idempotent append, optimistic concurrency, snapshots, and a deletion tombstone test.