Skip to main content

TurnMemorySink

Struct TurnMemorySink 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more