Skip to main content

SessionPipeline

Struct SessionPipeline 

Source
pub struct SessionPipeline { /* private fields */ }
Expand description

Per-session pipeline handle. Cloneable; holds an Arc to the inner LayeredPipeline plus Paper 3 enricher state (recent-tools window, effectiveness counters, fail-fast circuit).

Implementations§

Source§

impl SessionPipeline

Source

pub fn new(config: AdaptiveConfig) -> Self

Create a new pipeline for the current MCP server process. The session id is derived from the process id so multiple concurrent devboy mcp instances do not collide in shared telemetry.

When config.telemetry.enabled is true, a JsonlSink is opened at <config.telemetry.path | ~/.devboy/telemetry>/<session>.jsonl and attached to the pipeline. Failures to open the sink (missing permissions, etc.) are logged at WARN level and degrade to a no-op telemetry — they never fail the server start-up.

Source

pub async fn with_speculation( self, dispatcher: Arc<dyn PrefetchDispatcher>, ) -> Self

Attach a speculative-execution dispatcher. The host calls this once at startup with a PrefetchDispatcher that bridges to its own tools/call path. After this, Self::speculate_after schedules out-of-band prefetches when the planner finds high- probability follow-ups.

Source

pub async fn shutdown(&self)

Best-effort drop hook: on session close, abort every still- pending speculative task. The async-aware version of Drop (Rust’s sync Drop only sends an abort signal; this method also drains the JoinSet so the runtime sees the cancellation before we return).

Source

pub fn enrichment_snapshot(&self) -> EnrichmentEffectiveness

Snapshot of the Paper 3 enrichment counters so far in this session. Cheap (clone of EnrichmentEffectiveness); intended for tools/list debug output, end-of-session summary, or live status reporting.

Source

pub fn recent_tools_snapshot(&self) -> Vec<String>

Snapshot of recent tool names (oldest first). Used by the host when it builds a TurnContext for EnrichmentPlanner::build_plan.

Source

pub fn should_skip(&self, tool_name: &str) -> bool

Returns true when the planner’s fail-fast circuit is armed for tool_name — the host should refuse to dispatch the call and emit a short hint instead. Armed iff:

  1. [tools.<tool_name>].fail_fast_after_n = Some(n), and
  2. the last n consecutive responses for that tool were “empty” (≤ FAIL_FAST_EMPTY_THRESHOLD_BYTES).

EnrichmentEffectiveness is not updated here — the host is expected to call Self::record_fail_fast_skip once it has actually skipped the dispatch, so the saved-call counters stay honest if the host opts to override the recommendation.

Source

pub fn record_fail_fast_skip(&self, predicted_cost_tokens: u32)

Notify the aggregator that the host actually short-circuited a call this turn (the host saw should_skip return true and honoured it). predicted_cost_tokens should come from the tool’s cost_model.typical_kb so the saved-token count stays proportional to the call we avoided.

Source

pub async fn speculate_after( &self, tool_name: &str, prev_response_json: &Value, ) -> String

Run the Paper 3 planner against the response that just landed for tool_name, dispatch every safe (Pure / ReadOnly) follow-up out-of-band, and wait up to enrichment.prefetch_timeout_ms for them to complete.

Settled prefetches land in the dedup cache so the LLM’s next tools/call for the same tool_name+args collapses to an L0 hit. Tasks still pending past the timeout keep running and land later on the same session — never blocking the main response path.

Returns a short hint string the host can append to the LLM’s response so the model knows what context arrived early. Empty when the planner had nothing to schedule (or speculation is disabled).

Speculation is disabled when:

In both cases this method is a cheap no-op and returns "".

Source§

impl SessionPipeline

Source

pub fn on_compaction_boundary(&self)

Notify the pipeline that the host compacted its context. Drops dedup entries from prior partitions on the next eviction sweep.

Source

pub fn invalidate_file(&self, file_path: &str)

Invalidate all cache entries pointing at file_path. Called by the server before a mutating tool (Edit/Write/…) is dispatched so that a subsequent Read of the same file does not return a stale > [ref: …] hint.

Source

pub fn process( &self, request_id: &str, params: &ToolCallParams, result: ToolCallResult, ts_ms: i64, ) -> ToolCallResult

Process a single tool-call response through L0 dedup. When the L0 layer emits a reference hint (> [ref: tc_42, byte-identical] or its terse / verbose variant), the input ToolCallResult is rewritten to carry the hint instead of the original body. Other layer outcomes pass the original result through unchanged — L1/L2 encoders for typed-domain responses live in Pipeline.

Trait Implementations§

Source§

impl Clone for SessionPipeline

Source§

fn clone(&self) -> SessionPipeline

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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