Skip to content

[ADR-004] Event Observable and Provenance Model #316

@ohdearquant

Description

@ohdearquant

Summary

Align event storage/query/runtime hooks with observable event payloads, deterministic ordering, payload versions, event filters, and provenance fields needed by later proposal/event consumers.

Source ADRs

  • F024 ADR-004 (MAJ): Storage Event has outcome, data, duration_us, and target_id; it has no payload or session_id. (from audit-foundation/e2/ADR-004.md)
  • F025 ADR-004 (MAJ): Event index is idx_events_ns_created ON events(namespace, created_at DESC) with no event ID tiebreaker. (from audit-foundation/e2/ADR-004.md)
  • F113 ADR-022 (CRIT): KhiveRuntime::list_events accepts namespace: Option<&str> and passes an EventFilter directly to storage (from audit-platform/e3/ADR-022.md)
  • F114 ADR-022 (MAJ): EventFilter has ids, verbs, substrates, actors, namespaces, after, and before (from audit-platform/e3/ADR-022.md)
  • F115 ADR-022 (CRIT): SqlEventStore::query_events orders only by created_at DESC (from audit-platform/e3/ADR-022.md)
  • F181 ADR-032 (MAJ): The event record has verb, outcome, optional data, and target_id, but no EventKind, payload_schema_version, profile_state_version, or guaranteed served_by_profile_id payload contract. (from audit-rest/r2/ADR-032.md)
  • F214 ADR-041 (MAJ): The migration ledger contains versions 1-4 only (from audit-rest/r6/ADR-041.md)
  • F215 ADR-041 (MAJ): EventFilter exposes only ids, verbs, substrates, actors, namespaces, after, and before (from audit-rest/r6/ADR-041.md)
  • F216 ADR-041 (MAJ): The runtime exposes DispatchHook::on_dispatch(&Event) over raw storage events (from audit-rest/r6/ADR-041.md)
  • F217 ADR-041 (MAJ): append_event inserts only into events; append_events wraps multiple event inserts in a transaction but still inserts only event rows (from audit-rest/r6/ADR-041.md)
  • F225 ADR-042 (MAJ): Event model has a generic verb string and EventOutcome (from audit-rest/r1/ADR-042.md)
  • F241 ADR-046 (MAJ): The typed event model has verb, substrate, actor, outcome, data, duration_us, and target_id; it has no EventKind, proposal payloads, AggregateRef, or aggregate columns. (from audit-rest/r6/ADR-046.md)

Files affected

  • crates/khive-storage/src/event.rs (93 sampled LOC)
  • crates/khive-db/src/stores/event.rs (645 sampled LOC)
  • crates/khive-runtime/src/operations.rs (3728 sampled LOC)
  • crates/khive-db/src/migrations.rs (506 sampled LOC)
  • crates/khive-runtime/src/pack.rs (2677 sampled LOC)
  • crates/khive-types/src/event.rs (159 sampled LOC)
  • crates/khive-runtime/src/lib.rs (55 sampled LOC)

Acceptance criteria

  • All source findings listed above are addressed exactly once in this cluster.
  • Public types, handlers, schema, and docs touched by the affected files agree on the ADR contract.
  • Regression tests cover happy path and edge cases for the changed public APIs or schema behavior.
  • cargo test -p khive-types -p khive-storage -p khive-db -p khive-runtime passes.
  • cargo clippy --workspace -- -D warnings passes.
  • make ci passes.

Dependencies

  • Depends on: #[ADR-001] Entity Kind and Type Contract
  • Depends on: #[ADR-002] Edge Ontology, Lifecycle, and Bulk Link Semantics
  • Depends on: #[ADR-004] Note Kind, Storage, and Curation Operations
  • Depends on: #[ADR-005] Storage Capabilities, Sparse Store, and Vector Contract
  • Blocks: #[ADR-007] Namespace Token and Runtime API Migration
  • Blocks: #[ADR-003] Runtime Backend and Substrate Coordinator
  • Blocks: #[ADR-008] Query Layer Contract
  • Blocks: #[ADR-004] HandlerDef Pack Contract
  • Blocks: #[ADR-017] Pack Verb Registry, Wire Names, and Introspection
  • Blocks: #[ADR-016] Request Execution Modes and Presentation Envelope
  • Blocks: #[ADR-023] Dynamic Pack Loading, Template, and Pack Binary Inclusion
  • Blocks: #[ADR-004] GTD Pack Schema Plan and Lifecycle Audit
  • Blocks: #[ADR-043] Embedding Model Registry and Vector Engine Migration
  • Blocks: #[ADR-025] Event-Sourced Proposals
  • Blocks: #[ADR-015] Schema Migration Ledger

LOC estimate

~330 lines added/120 removed; 7 existing affected file(s) sampled at 7863 current LOC via wc -l, plus 0 new/planned path(s).

Risk notes

  • Same-file dependencies must merge first; dependency list includes the exact overlapping paths.
  • Contains CRIT findings; do not defer without owner approval.

Auto-generated by ADR alignment triage

Metadata

Metadata

Assignees

No one assigned

    Labels

    adr-alignmentADR v1 series alignment workadvancedAdvanced layer (ADR-031..046)foundationFoundation layer (ADR-001..015)platformPlatform layer (ADR-016..030)

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions