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.
(#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::base_url/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§
- Turn
Memory Sink - Async, fire-and-forget durable-write sink for one session’s turns (#2345).
Constants§
- QUEUE_
CAPACITY - Bounded mpsc queue capacity (#2345 scope: “~50”).
Functions§
- derive_
palace_ id_ for_ project - Derive the palace id for a project directory (#2345).