Skip to content

feat(core): provenance data model β€” source hash, event actor/evidence chain (#1172) - #1184

Merged
ajianaz merged 2 commits into
developfrom
feat/1172-provenance-model
Sep 5, 2026
Merged

feat(core): provenance data model β€” source hash, event actor/evidence chain (#1172)#1184
ajianaz merged 2 commits into
developfrom
feat/1172-provenance-model

Conversation

@ajianaz

@ajianaz ajianaz commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

What

Phase 1 of the memory evolution plan (#1172): the provenance data model, additive schema v17 β†’ v18, zero data loss.

  • memories.source_hash (TEXT, nullable) β€” SHA-256 of the content, recorded automatically in the single shared creation path (remember_precomputed, which backs remember/remember_typed/consolidation). Auditors recompute the hash of current content to detect post-write tampering.
  • timeline_events.actor (TEXT) + timeline_events.evidence_json (TEXT, JSON array) β€” who performed an event and what evidence supports it. Written via Store::add_timeline_event_with_provenance; existing add_timeline_event callers are untouched (NULL actor/evidence).
  • Uteke::provenance(id) β†’ ProvenanceReport (exported): provenance fields (author_type, source, source_type, timestamps), TrustTier classification, source_hash (at write) vs content_hash_now (live-recomputed), deprecated, and the full event chain newest-first.
  • Uteke::set_source_hash(id, Option<&str>) β€” public for repair/backfill tooling on legacy rows.
  • Bug fixed en route: column_exists_in allowlist did not include timeline_events, so the helper silently returned false for that table β€” the v18 migration would have double-ALTERed. Allowlist now includes it, and the migration additionally ensures the table exists with the fresh shape (defensive for partially-repaired stores).

Surfaces (HTTP / CLI / MCP for provenance) land in the follow-up PR β€” this PR is the schema + core API layer.

Why

#1172 item 1 (per the OSS/cloud triage decision): provenance is the correctness primitive everything else builds on. Fase 2 (contradiction evidence chain + undo) writes its resolution rationale as provenance-bearing timeline events; the audit surfaces read them through this model.

Testing

  • New (embedder-free per CI constraint): provenance_chain_and_source_hash β€” hash recorded at write matches live recomputation; direct DB content tampering breaks the match (tamper-evidence property); event chain contains created; unknown ID β†’ Ok(None).
  • New: timeline_events_carry_provenance β€” provenance-bearing event stores actor + evidence (readable back via Uteke::timeline), plain events keep the old shape (backward compat).
  • Migration: existing test_author_type_migration_v15_to_v16 (legacy v15 DB β†’ v18) and test_migration_v11_to_v12_from_v04x_db (fixture without timeline_events) both pass after the defensive CREATE + allowlist fix; fresh-store version stamping asserted at 18.
  • cargo fmt --all βœ“ Β· cargo clippy --workspace --all-targets -- -D warnings βœ“ Β· cargo test -p uteke-core --lib 548 passed / 0 failed Β· server handler suite 23/23 βœ“ Β· cora review --staged βœ“ (No issues found).

… chain (#1172)

Phase 1 of the memory evolution plan (#1172). Additive schema v17 β†’ v18,
zero data loss:

- memories.source_hash: SHA-256 of content recorded automatically at
  write time (single shared remember_precomputed path) β€” auditors
  recompute it to detect post-write tampering
- timeline_events.actor + evidence_json: who performed an event and what
  evidence supports it (e.g. contradiction resolution, Fase 2 consumer)
- Uteke::provenance(id) β†’ ProvenanceReport: provenance fields, trust
  tier, live-recomputed content hash, and the full event chain
- column_exists_in allowlist gains timeline_events (was silently always
  false, which would double-ALTER in v18 migration)

Migration is guarded (column_exists / CREATE IF NOT EXISTS) so legacy
stores, fresh stores, and partially-repaired stores all converge to the
same shape. Backward compatible: new columns nullable, old binaries
unaffected.
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

πŸ” Cora AI Code Review

βœ… No issues found. Code looks good!


Review powered by cora-code Β· BYOK Β· MIT

Exposes the phase-1 provenance model on every surface:

- GET /provenance?id= β€” full report (fields, trust tier, hash
  comparison, event chain); 404 unknown id, 400 missing param
- uteke provenance <id> β€” human-readable audit output with hash
  verdict (βœ“ matches / βœ— MISMATCH / β€” pre-v18 row), --json for tooling
- uteke_provenance MCP tool β€” JSON report for agents

Docs: cli-reference (uteke provenance section), api-reference
(regenerated), CHANGELOG.
@ajianaz
ajianaz merged commit 16f1186 into develop Sep 5, 2026
16 checks passed
@ajianaz
ajianaz deleted the feat/1172-provenance-model branch September 5, 2026 15:19
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