Skip to main content

BenchRunsClient

Struct BenchRunsClient 

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

Operations keyed on a global bench_runs.id. These endpoints live under /bench-runs/{id}/... and don’t need a project scope (the server resolves the owning project from the run row). Obtained via client.bench_runs().

Implementations§

Source§

impl BenchRunsClient

Source

pub async fn get(&self, run_id: i64) -> Result<Option<BenchRun>>

GET /bench-runs/{id} — 404 → Ok(None).

Source

pub async fn delete(&self, run_id: i64) -> Result<()>

DELETE /bench-runs/{id} — returns () (server emits 204 No Content). Cancels the run first (best-effort) before dropping the row.

Source

pub async fn list_results(&self, run_id: i64) -> Result<Vec<BenchResult>>

GET /bench-runs/{id}/results. 404 → empty list.

Source

pub async fn subscribe_run_events( &self, run_id: i64, ) -> Result<(UnboundedReceiver<BenchRunEvent>, EventSubscription)>

Subscribe to a bench run’s live result stream over SSE (GET /bench-runs/{id}/events, Accept: text/event-stream).

Returns a receiver of typed BenchRunEvents plus an EventSubscription handle that cancels the background listener on drop. The server emits a BenchRunEvent::Result per recorded case, a BenchRunEvent::Lagged if the broadcast subscriber falls behind, and a final BenchRunEvent::Terminal carrying the run’s terminal status — after which the channel closes.

This awaits the SSE subscription being live on the server before returning, so a non-2xx (e.g. 403 on a project the token can’t read, or the run id not resolving to a project) surfaces here rather than as a silently-empty stream. Reuses the crate’s shared SSE byte-deframer and field parser (the same machinery behind events().event_stream / executions().run_stream).

Mirrors the TS SDK’s subscribeRunEvents; the terminal frame is surfaced as a typed variant so Rust callers can detect end-of-stream without a side channel. Drop the returned EventSubscription (or let it fall out of scope) to unsubscribe.

let (mut rx, _sub) = client.bench_runs().subscribe_run_events(42).await?;
while let Some(evt) = rx.recv().await {
    match evt {
        BenchRunEvent::Result(r) => println!("case {} → {}", r.case_id, r.status),
        BenchRunEvent::Lagged { dropped } => eprintln!("dropped {dropped}"),
        BenchRunEvent::Terminal { status } => {
            println!("run ended: {status}");
            break;
        }
    }
}
Source

pub async fn cancel(&self, run_id: i64) -> Result<BenchRun>

POST /bench-runs/{id}/cancel. Flips the cancel token; in-flight cases complete naturally. Returns the run row as it stands.

Source

pub async fn tag_session( &self, run_id: i64, mcp_session_id: &str, ) -> Result<BenchRunTagSessionResponse>

PATCH /bench-runs/{id}/tag-session — attribute the run to an MCP session id so the coordinator’s finalize step posts the cost into mcp_session_cost.

Source

pub async fn promote_execution( &self, execution_id: &str, req: &PromoteExecutionRequest, ) -> Result<BenchCase>

POST /executions/{exec_id}/promote-to-case — promote a completed execution into a bench case, with optional edits overlay.

This is run-scoped only in the loose sense: it lives on /executions rather than /bench-runs, but it’s the natural counterpart to the “promote-from-execution” flow on the bench surface and doesn’t need a project_id (the server resolves the owning project from the source execution).

Source

pub async fn compare(&self, run_a: i64, run_b: i64) -> Result<CompareReport>

GET /bench-runs/{a}/compare/{b} — diff two runs of the same bench.

Source

pub async fn get_case(&self, case_id: &str) -> Result<Value>

GET /executions/{case_id} — fetch a single case (cases are executions rows with kind='case'). Returned as Value for compatibility with the MCP tool, which doesn’t trust the row to always type-check as BenchCase (legacy promoted-execution rows can have null kind on older servers).

Source

pub async fn patch_case( &self, case_id: &str, req: &PatchBenchCaseRequest, ) -> Result<BenchCase>

PATCH /cases/{id} — sparse update.

Source

pub async fn delete_case(&self, case_id: &str) -> Result<()>

DELETE /cases/{id}. The server emits a {"deleted": true} JSON body; we discard it and return ().

Source

pub async fn bench_by_id(&self, bench_id: i64) -> Result<Option<Value>>

GET /benches/{id} — fast bench-by-id lookup. Returns the bench row joined with the owning project_id + script_name so the caller can chain into list_cases / list_runs without an N+1 project walk. 404 → Ok(None).

Source

pub async fn mcp_session_cost(&self, session_id: &str) -> Result<Value>

GET /mcp-sessions/{id}/cost — aggregated cost for an MCP session. Returns {session_id, total_cost_usd, breakdown}. Lets the MCP server (and any other client) read accumulated cost via HTTP rather than querying the mcp_session_cost table directly.

Trait Implementations§

Source§

impl Clone for BenchRunsClient

Source§

fn clone(&self) -> BenchRunsClient

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

impl Debug for BenchRunsClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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