Skip to main content

Module memory_sink

Module memory_sink 

Source
Expand description

Turn recorder (#2345): durable per-turn dual-write to trusty-memory.

Why: epic #2343 (Infinite Sessions) requires every PM prompt/response turn to be durably recorded in trusty-memory, independent of the in-process Transcript (#2344), which only lives as long as the daemon process. Without this, a daemon restart or crash loses the entire conversation; #2348’s recall_session tool also needs a semantic recall surface over session history that a bare chat_turn_append record alone would not give it (it stores the exact turn but is not embedded/indexed for recall the way memory_remember is). What: TurnMemorySink owns a bounded tokio::sync::mpsc queue and a background drain task. TurnMemorySink::enqueue is the non-blocking producer side, called from task::executor::run_and_record at each turn boundary. The drain task calls BOTH chat_turn_append (the exact chronological record) and memory_remember (tagged ["session:<id>", "turn"], force: true — the semantic recall surface for #2348) via the MCP tools/call envelope (crate::memory_envelope::call_tool_wrapped; #2424 — trusty-memory’s direct-dispatch allowlist has no chat_* methods, so direct dispatch of chat_turn_append fails -32601 on every write), against a base URL resolved ONCE at construction — never blocking or failing the calling turn: any RPC failure is logged via tracing::warn! and dropped. (#2424) Before the FIRST write, the drain task ensures the target palace exists ([ensure_palace]) — memory_remember does NOT auto-create a palace and fails -32603 "palace metadata missing" against a missing one, which is exactly how the #2343 soak lost all 50 turns. The ensure result is cached on success so steady state adds zero extra RPCs. (#4638) That auto-create is gated on PalaceCreation, decided from the session’s project root by SessionRegistry::memory_sink_for. The palace id is DERIVED from that root, so an ephemeral root (a tempfile::TempDir) yields a per-run-unique id and the ensure minted one permanent, unreadable palace per run — 5,667 t-tmp<random> orphans in three weeks, 97.8% of every palace on the machine, which made trusty-memory’s O(n) full-registry handlers (#4637) unusable. A palace is an expensive object (usearch index, KG redb, drawer table, recall log), not a per-session scratch container: the intended shape is ONE durable palace per PROJECT with each session distinguished INSIDE it by chat_turn_append’s session_id and memory_remember’s session:<id> tag, and that shape is what PalaceCreation::Forbidden restores by making palace_create unreachable from an ephemeral root. (#2363) memory_remember’s dedup gate (jaro_winkler >0.92, 5-min same-palace window) is documented as hostile to sequential conversational turns, so every turn-recorder write passes force: true to bypass it outright, along with the other content-QUALITY gates (blocklist, short-content, noise pattern). Issue #2520 (two-tier force): force: true no longer bypasses secret/credential detection — this sink deliberately does NOT set the separate allow_secret_like opt-in, so a turn whose raw LLM/tool-use content looks secret-shaped is correctly REJECTED rather than persisted; this is a behavior change from when force was a blanket bypass and is the intended safe default for an automated writer. A "status":"skipped" response is still checked and warned on as a belt-and-braces guard in case a gate skips the write. TurnMemorySink::socket/TurnMemorySink::palace expose this sink’s already-resolved binding so #2348’s recall_session tool can target the SAME daemon/palace the turn recorder writes into, without a second, independent resolution. derive_palace_id_for_project mirrors trusty_common::catchup’s (private) palace-derivation convention so a session’s turns land in the same palace its PM catch-up digest reads from. Test: memory_sink::tests::*.

Structs§

TurnMemorySink
Async, fire-and-forget durable-write sink for one session’s turns (#2345).

Enums§

MemoryFailureCategory
Which half of the dual-write degraded, as the retained per-session status reports it (#2425).
PalaceCreation
Whether a sink is entitled to bring its target palace into EXISTENCE (#4638).

Constants§

QUEUE_CAPACITY
Bounded mpsc queue capacity (#2345 scope: “~50”).

Functions§

derive_palace_id_for_project
Resolve the palace id for a project directory (#2345).