# Milestone 4 · Agent Memory (✅ COMPLETE 2026-02-21) Milestone spec, thesis, UAT scenario, and per-phase acceptance criteria: [ROADMAP · Milestone 4](../ROADMAP.md). Status row: `m4: Agent Session Layer`. > **These are backfilled records, not the original plans.** M4 shipped in the > squashed commit `39ada28` (2026-02-21) before this project kept per-milestone > planning directories, so the four phase docs here were written after the fact > (2026-08-30) from the ROADMAP acceptance criteria, the shipped source tree, and > the M4 test suite. Every claim below names the artifact that proves it. Where > the shipped surface diverges from the ROADMAP text, the phase doc says so > rather than restating the plan. ## What the milestone proves An agent — not a human clicking a UI — can own a scoped memory lane inside the same embedded process: open a session bound to a `(user, agent, policy)` triple, write short-lived signals that the schema-declared policy accepts or rejects, read a live snapshot of that session's decayed state, blend the session into a `RETRIEVE` ranking, then close it and read the frozen archive. No Redis, no feature store, no policy middleware. ## Phases | Phase | Name | Record | |-------|------|--------| | m4p1 | Session Schema and Lifecycle | [phase-1.md](phase-1.md) | | m4p2 | Session Signal Engine | [phase-2.md](phase-2.md) | | m4p3 | Policy Enforcement and Audit | [phase-3.md](phase-3.md) | | m4p4 | Session-Aware Ranking and M4 UAT | [phase-4.md](phase-4.md) | The four phases were strictly sequential (each needed the previous phase's write path), and all four landed in one commit; the phase split below is therefore a split of the *delivered surface*, traced from the ROADMAP's phase definitions to the modules and tests that implement each one. ## Shipped surface (verified against the working tree) | Concern | Artifact | |---------|----------| | Session types | `tidal/src/session/types.rs` — `SessionId`, `AgentId`, `SessionHandle` | | Live session state | `tidal/src/session/state.rs` — per-session accumulators | | Session signal decay | `tidal/src/session/signal_state.rs` | | Snapshot / archive read model | `tidal/src/session/snapshot.rs` | | Policy evaluation | `tidal/src/session/policy.rs` | | Audit log | `tidal/src/session/audit.rs` | | Archive serialization | `tidal/src/session/serde/mod.rs`, `serde/start_record.rs` | | Policy declaration in schema | `tidal/src/schema/validation/policies.rs` — `AgentPolicy` | | `db.*` session API | `tidal/src/db/sessions.rs` | | WAL durability | `WalCommand::SessionStart` / `SessionSignal` / `SessionClose` in `tidal/src/wal/writer.rs` | ## Evidence | Claim | Proof | |-------|-------| | Full agent workflow works end to end | `tidal/tests/m4_uat.rs` — 12 `#[test]` steps, "M4 User Acceptance Test: Agent Session Layer". Added by `39ada28`, the M4 commit. | | Sessions survive a crash | `tidal/tests/session_durability.rs` — 10 tests incl. `active_session_state_restored_after_crash`, `metadata_survives_crash`, `wal_replay_restores_signal_counts_exactly`. Added one commit later by `192c473` (M5), so read it as M4-surface hardening rather than M4 itself. | | Session semantics still hold after later reworks | `tidal/tests/review_pass2_zone_a_sessions.rs`, `tidal/tests/review_pass2_query_for_session.rs` — added by `9728194` (M0–M10 review pass 2, 2026-06-09) | | Sessions survive M7 crash hardening | `tidal/tests/m7_crash_m6.rs`, `tidal/tests/m7_crash_invariant.rs` (session-touching cases) | | Recorded at close | ROADMAP status row: 607 lib + 12 m4_uat + prior UATs passing | All 49 M4 acceptance criteria in [ROADMAP · Milestone 4](../ROADMAP.md) are marked `[x]`. ## Naming drift worth knowing The ROADMAP's M4 text names errors `LumenError::PolicyViolation` / `LumenError::SessionExpired`. The shipped enum is `TidalError` — the `Lumen` prefix is a pre-rename artifact left in the planning prose. Real variants: `TidalError::PolicyViolation` and `TidalError::SessionExpired` (`tidal/src/schema/error.rs:123,130`), plus the session-internal `PolicyViolation { kind: PolicyViolationKind }` re-exported from `tidal/src/lib.rs`. ## What M4 deliberately did not do The ROADMAP's "Deferred to Later Milestones" list for M4 held nine items. Their real fates: - Cross-session aggregation → shipped in m6p4 (see [milestone-6/phase-4.md](../milestone-6/phase-4.md)). - Session signal influence on the global preference vector → shipped in m6p4. - Semantic hint matching → M4 shipped keyword matching; embeddings arrived with M5. - RLHF training-data export, per-agent QPS rate limiting, session TTL sweeper → shipped in M7 (m7p2/m7p4). - User revocation of agent-contributed signals, multi-agent sessions → shipped in M9/M10; the read-path and profile-override fields on `AgentPolicy` (`allowed_read_signals`, `denied_read_signals`, `allowed_user_attributes`, `denied_user_attributes`, `allowed_profile_overrides`) were added by commit `d8e4083` for that work, not by M4. - Session forking and merging → still not built. No commit, no test, no issue; it remains an open idea, not a shipped feature.