pub struct TurnMemorySink { /* private fields */ }Expand description
Async, fire-and-forget durable-write sink for one session’s turns (#2345).
Why: see module docs.
What: enqueue never blocks the calling turn and never fails visibly —
see its docs for the overflow policy. The background drain task owns the
only receiver, so it keeps running for exactly as long as this sink (and
therefore the channel’s sender half) stays alive — the session’s
SessionEntry holds the constructed Arc<TurnMemorySink> for the
session’s lifetime (built once, lazily, on the session’s first
task.run — see SessionRegistry::memory_sink_for), so the drain task
naturally survives across every run on that session, not just one.
Implementations§
Source§impl TurnMemorySink
impl TurnMemorySink
Sourcepub fn new(base_url: String, palace: String) -> Self
pub fn new(base_url: String, palace: String) -> Self
Construct a sink writing to palace at the given (already-resolved)
base_url, and spawn its background drain task with the default
QUEUE_CAPACITY.
Test: memory_sink::tests::enqueue_drain_happy_path.
Sourcepub fn with_capacity(base_url: String, palace: String, capacity: usize) -> Self
pub fn with_capacity(base_url: String, palace: String, capacity: usize) -> Self
Same as Self::new with an explicit queue capacity — tests use a
tiny capacity to exercise the overflow policy cheaply.
Why: base_url is resolved ONCE by the caller (mirroring
catchup::pm_catchup_context’s own
resolve_memory_base_url_or_unreachable() call) rather than
re-resolved on every enqueued turn — the daemon’s bound address does
not change mid-session, and re-resolving on every turn would add
discovery-file I/O to the hot drain path for no benefit. Tests inject
a mock server’s URL directly here instead of mutating the
process-global TRUSTY_MEMORY_URL env var (unsafe across parallel
tests).
What: spawns [drain] as a detached tokio::spawned task owning the
receiver half of a capacity-bounded channel; returns the sink
holding only the sender half.
Test: memory_sink::tests::enqueue_drops_newest_when_queue_full.
Sourcepub fn base_url(&self) -> &str
pub fn base_url(&self) -> &str
This sink’s already-resolved trusty-memory base URL.
Why: #2348’s recall_session tool must read from the SAME daemon the
turn recorder writes into; re-deriving it independently would risk the
two disagreeing (e.g. after a discovery-file update mid-session) and
adds a redundant resolution for no benefit.
What: Returns the URL passed to (or resolved by) Self::new/
Self::with_capacity at construction — fixed for the sink’s
lifetime, mirroring write_turn’s own binding.
Test: memory_sink::tests::base_url_and_palace_expose_construction_args.
Sourcepub fn palace(&self) -> &str
pub fn palace(&self) -> &str
This sink’s already-resolved palace id.
Why: see Self::base_url — the same reuse rationale applies to the
palace binding.
What: Returns the palace passed to Self::new/Self::with_capacity
at construction.
Test: memory_sink::tests::base_url_and_palace_expose_construction_args.
Sourcepub fn enqueue(
&self,
session_id: impl Into<String>,
prompt: impl Into<String>,
response: impl Into<String>,
)
pub fn enqueue( &self, session_id: impl Into<String>, prompt: impl Into<String>, response: impl Into<String>, )
Enqueue one turn for durable dual-write, never blocking the caller.
Why: turn recording must NEVER stall or fail a running turn (#2345
acceptance criteria) — a slow or wedged drain task must not back up
into the agent loop.
What: try_sends onto the bounded channel. Overflow policy: DROP THE
NEWEST turn (this call’s turn) rather than evicting an
already-queued older one — the simplest policy mpsc::Sender:: try_send supports directly (no peek/pop-front on the sender side
without a different channel type), logged via tracing::warn! so an
operator can see it happened. A closed receiver (the drain task
panicked or was dropped) degrades the same way: logged, dropped, no
error surfaced to the caller.
Test: memory_sink::tests::enqueue_drops_newest_when_queue_full.
Auto Trait Implementations§
impl Freeze for TurnMemorySink
impl RefUnwindSafe for TurnMemorySink
impl Send for TurnMemorySink
impl Sync for TurnMemorySink
impl Unpin for TurnMemorySink
impl UnsafeUnpin for TurnMemorySink
impl UnwindSafe for TurnMemorySink
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more