pub fn dispatch_event(
conn: &Connection,
event: &str,
memory_id: &str,
namespace: &str,
agent_id: Option<&str>,
db_path: &Path,
)Expand description
Fire an event to all matching subscribers. Each dispatch is
fire-and-forget — the caller is NOT blocked on delivery. Errors are
logged and counted in the DB via failure_count.
PERF-3 (FX-10, 2026-05-26): pre-fix posture was
std::thread::spawn + per-worker Connection::open(...) per
matching subscriber — 1000 subscribers minted 1000 OS threads + 1000
SQLite handles per store event. Post-fix posture uses a bounded
tokio::sync::Semaphore (default 32 permits, tunable via
AI_MEMORY_WEBHOOK_DISPATCH_CONCURRENCY) + tokio::task::spawn_blocking
against the existing daemon Tokio runtime so the in-flight delivery
count is capped. The pre-fix std::thread::spawn path is preserved
as a fallback for legacy unit tests that run outside any runtime.
Caller owns the connection. Dispatch workers still re-open the
connection per delivery to update counters (cheap — SQLite
connections are process-shared via WAL — and the new concurrency
bound keeps the simultaneous handle count bounded too).
P5 (G9): convenience wrapper for the historical no-details case
(used by memory_store). New event types should call
dispatch_event_with_details and pass the matching
*EventDetails struct serialised to JSON.