Skip to content

feat(core): audit-grade timeline — history survives forget, deprecated events, MCP tool (schema v20) - #1280

Merged
ajianaz merged 2 commits into
developfrom
feat/timeline-audit
Sep 18, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/timeline-audit

Conversation

@ajianaz

@ajianaz ajianaz commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

What

  • Schema v20 (crates/uteke-core/src/memory/schema.rs): rebuild timeline_events WITHOUT the REFERENCES memories(id) ON DELETE CASCADE FK — deleting a memory no longer wipes its history. Defensive path for stores that never materialized the table. Fresh-store DDL in store.rs aligned (no FK).
  • Created backfill: the migration inserts created events (actor='backfill', timestamped at the memory's own created_at) for memories lacking one — ~9.7k in the PROD store (pre-timeline-schema rows + import path).
  • Deprecated event (new TimelineEventType::Deprecated variant, append-only enum): deprecate_with_reason now records a deprecated event with the reason. Idempotent re-deprecation writes no duplicate. This wires the fleet's dominant delete traffic (1.4k deprecations since 2026-09-06, previously zero events).
  • Forgot tombstone: hard forget() writes a forgot event BEFORE the delete — and only when the memory actually exists (no spurious tombstones for unknown IDs). On post-v20 stores the tombstone persists as an orphan; on pre-v20 stores it was the only chance to record anything.
  • New MCP tool uteke_timeline (crates/uteke-mcp/src/lib.rs): id + optional limit (default 100, cap 1000), mirrors uteke_provenance. Works as a tombstone lookup for forgotten memories too.

Why

Owner decision 2026-09-18 (contract doc kontrak-core-cloud/03): the timeline is the audit layer ("history jangan dihapus"). Forensics (uteke-cloud#90 cmt 2836): PROD had 15.342 events = 100% created, 0 lifecycle events, actor NULL everywhere, ~62% of memories without any event, and the FK CASCADE actively destroyed history at the moment audit needs it most.

Atomicity: each batch runs in one SQLite implicit transaction and the migration dispatcher wraps the whole step in its own transaction, stamping v20 only on success — an interrupted run rolls back entirely.

Known gap (explicitly deferred): created events still carry a NULL actor; threading caller identity (CLI/MCP/HTTP) through try_timeline_event is the next small PR.

Testing

  • New test test_migration_v19_to_v20_history_survives_delete_and_backfills_created: v19 DB (with FK) → migrate → rows preserved, backfill exactly-once, delete memory → events survive, pragma_foreign_key_list = 0.
  • New test test_timeline_deprecate_and_forget_events: soft forget → deprecated event present; hard forget → forgot tombstone recorded AND still present after the row is gone.
  • Fixed stale assertion in test_author_type_migration_v15_to_v16 (hardcoded v19 → CURRENT_SCHEMA_VERSION, breaks every bump otherwise).
  • cargo test -p uteke-core: 567 passed, 0 failed; clippy clean on uteke-core + uteke-mcp; cargo fmt applied. Cora pre-commit review: No issues found (after fixing 2 MAJORs from round 1: spurious tombstones for nonexistent IDs; migration atomicity documentation).

…d events, MCP tool (schema v20)

Owner decision 2026-09-18 (contract doc kontrak-core-cloud/03):
timeline is the audit layer and must survive memory deletion.

- migration v19->v20: rebuild timeline_events WITHOUT the FK
  ON DELETE CASCADE (defensive: creates the table if an old store
  never materialized it) + backfill `created` events (actor=backfill)
  for memories lacking one (~9.7k in PROD)
- deprecate_with_reason now records a `deprecated` event with reason
  (the fleet's dominant delete traffic — 1.4k deprecations — was
  previously unwired); idempotent re-deprecation writes no duplicate
- hard forget() writes a `forgot` tombstone BEFORE the delete so the
  audit trail exists even on pre-v20 stores
- new TimelineEventType::Deprecated variant (append-only enum rule)
- new MCP tool uteke_timeline (id + limit, mirrors uteke_provenance)
- tests: migration preserves rows/drops FK/backfills once; soft and
  hard forget event assertions (7 timeline tests + 567 lib tests green)

Next up (separate PR): actor plumbing from caller identity (CLI/MCP/
HTTP) — Created events still default to a NULL actor.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 4cc1c13 into develop Sep 18, 2026
15 checks passed
ajianaz added a commit that referenced this pull request Sep 29, 2026
- mcp.md: 46 -> 49 tools; add uteke_timeline, uteke_verify, uteke_repair
  rows (shipped in #1280/#1272, tool table had not caught up)
- architecture.md: schema history v15 -> v20 (v16 author_type #1083,
  v17 deprecated_at #1086, v18 provenance #1172, v19 rooms.description
  #1202, v20 audit-grade timeline #1280)

Co-authored-by: CMO <[email protected]>
@ajianaz
ajianaz deleted the feat/timeline-audit branch October 13, 2026 00:57
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