Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(events): correct event ordering to ensure causal consistency

Steven Enamakelc10b97cf41d7
diff --git a/crates/openhuman-core/src/core/events.rs b/crates/openhuman-core/src/core/events.rs
index 0a7cbb7955..366830a494 100644
--- a/crates/openhuman-core/src/core/events.rs
+++ b/crates/openhuman-core/src/core/events.rs
@@ -255,125 +255,8 @@ pub enum DomainEvent {
},
/// A memory recall query completed.
MemoryRecalled { query: String, hit_count: usize },
- /// The configured memory driver could not be bound, and the kernel fell
- /// back to the placeholder. Never silent — `docs/specs/kernel.md` §3.7.
- ///
- /// Carries driver *ids* and an operator-facing reason only: never an
- /// endpoint, a `credential_ref`, or user memory content. See
- /// `MemoryDriverConfig`'s manual redacting `Debug` impl for the same rule
- /// on the config side.
- MemoryDriverBindFailed {
- /// The driver id asked for in `[subsystems.memory] driver`.
- configured_driver: String,
- /// What was bound instead (today always `"null"`).
- bound_driver: String,
- /// Why the configured driver was refused.
- reason: String,
- },
- /// The user switched the memory engine (`memory.engine_set` /
- /// `memory.engine_migrate`) and the binding was rebound in process.
- ///
- /// Carries driver ids only — never an endpoint, credential or reference,
- /// same rule as [`Self::MemoryDriverBindFailed`].
- MemoryDriverChanged {
- /// The driver id that was active before the switch.
- from: String,
- /// The driver id that is configured now.
- to: String,
- },
- /// The memory policy guard refused a call before it reached the bound
- /// driver (`docs/specs/kernel.md` §3.4).
- ///
- /// Carries the driver id, the contract method, and an operator-facing
- /// reason — **never** a namespace key, a recall query, or memory content.
- /// Same rule as [`Self::MemoryDriverBindFailed`] above, and the reason
- /// [`Self::MemoryRecalled`] (which carries the raw query) is not reused for
- /// this: the guard sits on the hot path and must not put user text on the
- /// bus.
- ///
- /// Published on refusals only. A guard that published on success would emit
- /// one event per memory read.
- MemoryGuardDenied {
- /// The bound driver the call was headed for.
- driver_id: String,
- /// The contract method that was refused, e.g. `"core.store"` or
- /// `"tree.query_source"`.
- method: String,
- /// Why the guard refused it.
- reason: String,
- },
- /// A memory sync was requested for a specific channel or all channels.
- ///
- /// Published by `openhuman.memory_sync_channel` (channel_id = Some(...)) and
- /// `openhuman.memory_sync_all` (channel_id = None). No consumers exist yet —
- /// this variant is a hook for future ingestion subscribers to react to pull
- /// requests. See `crates/openhuman-core/src/memory/ops.rs` for the RPC handlers.
- MemorySyncRequested { channel_id: Option<String> },
- /// A high-level memory sync orchestration stage changed.
- ///
- /// Emitted by the `memory` domain so the frontend can surface progress
- /// across request → fetch → store → queue → ingest → complete.
- ///
- /// `source_id` is the originating memory-source id (from
- /// `memory_sources`) when the event can be attributed to a specific
- /// source row. The frontend prefers this over `connection_id` for
- /// per-row indicator matching (see RC#2, issue #3295). Set to `None`
- /// when the event originates from a non-memory-source sync path (e.g. a
- /// channel-provider ingest) — `connection_id` remains unchanged for
- /// those callers.
- MemorySyncStageChanged {
- trigger: String,
- stage: String,
- provider: Option<String>,
- connection_id: Option<String>,
- detail: Option<String>,
- /// Originating memory-source id for frontend per-row indicator
- /// matching. `None` when the event is not attributable to a
- /// specific `MemorySourceEntry`.
- source_id: Option<String>,
- },
- /// A memory ingestion job started running on the local extraction LLM.
- /// Ingestion is singleton — this fires once, then a matching
- /// [`Self::MemoryIngestionCompleted`] follows when the job finishes.
- MemoryIngestionStarted {
- document_id: String,
- title: String,
- namespace: String,
- queue_depth: usize,
- },
- /// A memory ingestion job finished (successfully or with an error).
- MemoryIngestionCompleted {
- document_id: String,
- namespace: String,
- success: bool,
- elapsed_ms: u64,
- queue_depth: usize,
- },
// ── Memory Diff ─────────────────────────────────────────────────────
- /// A snapshot of a memory source's chunk state was captured.
- MemoryDiffSnapshotTaken {
- snapshot_id: String,
- source_id: String,
- source_kind: String,
- item_count: usize,
- trigger: String,
- },
- /// A diff was computed between two snapshots.
- MemoryDiffComputed {
- source_id: String,
- from_snapshot_id: Option<String>,
- to_snapshot_id: String,
- added: usize,
- removed: usize,
- modified: usize,
- },
- /// Read markers were committed for one or more sources, acknowledging
- /// their current diffs as consumed.
- MemoryDiffMarkedRead {
- source_ids: Vec<String>,
- snapshot_ids: Vec<String>,
- },
// ── Channels ────────────────────────────────────────────────────────
/// An inbound channel message from the transport layer, ready for processing.
@@ -1042,38 +925,7 @@ pub enum DomainEvent {
},
// ── Tree Summarizer ──────────────────────────────────────────────────
- /// An hour leaf was created from buffered data.
- TreeSummarizerHourCompleted {
- namespace: String,
- node_id: String,
- token_count: u32,
- },
- /// A tree node summary was updated during propagation.
- TreeSummarizerPropagated {
- namespace: String,
- node_id: String,
- level: String,
- token_count: u32,
- },
- /// A full tree rebuild completed.
- TreeSummarizerRebuildCompleted { namespace: String, total_nodes: u64 },
-
- /// Fine-grained progress during the memory tree build pipeline.
- /// Emitted at each sub-phase so the frontend can show detailed status.
- MemoryTreeBuildProgress {
- /// Which phase: "extract", "append", "seal", "flush", "embed"
- phase: String,
- /// Sub-step within the phase (e.g. "loading", "summarising", "persisting")
- step: String,
- /// Tree scope when available (e.g. "github:org/repo")
- tree_scope: Option<String>,
- /// Tree level being processed (0 = leaves, 1+ = summaries)
- level: Option<u32>,
- /// Number of items being processed in this step
- item_count: Option<u32>,
- /// Human-readable detail
- detail: Option<String>,
- },
+
// ── Notification ────────────────────────────────────────────────────
/// An integration notification was ingested from an embedded webview.
@@ -1113,53 +965,8 @@ pub enum DomainEvent {
payload_b64: String,
},
// ── Memory tree ─────────────────────────────────────────────────────
- /// A document (chat batch, email thread, or standalone document) was
- /// fully canonicalised and its chunks written to the memory tree.
- ///
- /// Emitted by `tinymemory_core::tree::ingest::persist()` after the chunk upsert
- /// and extract-job enqueue complete. Subscribers (Phase 2 producers such
- /// as the email-signature parser) react to this to inspect the
- /// canonicalised content.
- DocumentCanonicalized {
- /// The source identifier passed to the ingest call (e.g. `"gmail:abc"`,
- /// `"conversations:agent"`).
- source_id: String,
- /// Kind of content — `"chat"`, `"email"`, `"document"`.
- source_kind: String,
- /// Number of chunks written to `vector_chunks` in this ingest.
- chunks_written: usize,
- /// IDs of the chunks that were written.
- chunk_ids: Vec<String>,
- /// Wall-clock seconds since epoch when canonicalisation completed.
- canonicalized_at: f64,
- /// Last ≤ 2 048 characters of the canonicalised markdown body.
- ///
- /// Populated for `email` and `document` sources so that lightweight
- /// subscribers (e.g. the email-signature parser) can inspect trailing
- /// content without hitting disk. `None` for `chat` sources where the
- /// content is conversational and doesn't contain signature-style structure.
- body_preview: Option<String>,
- },
// ── Learning ─────────────────────────────────────────────────────────
- /// The stability detector finished a full cache rebuild cycle.
- ///
- /// Emitted by `learning::stability_detector` (Phase 3) after writing
- /// the new snapshot to `user_profile_facets`. Subscribers (Phase 4
- /// `profile_md_renderer`) react to re-render the `PROFILE.md` managed
- /// blocks.
- CacheRebuilt {
- /// Number of facets added in this cycle.
- added: usize,
- /// Number of facets evicted (below τ_evict threshold) in this cycle.
- evicted: usize,
- /// Number of facets unchanged / carried over.
- kept: usize,
- /// Total facets in the cache after the rebuild.
- total_size: usize,
- /// Wall-clock seconds since epoch when the rebuild completed.
- rebuilt_at: f64,
- },
// ── MCP Clients ─────────────────────────────────────────────────────
/// A new MCP server was installed from the Smithery registry.