Skip to main content

ModelDefectLedger

Struct ModelDefectLedger 

Source
pub struct ModelDefectLedger {
    counts: Mutex<HashMap<String, ModelDefectCounts>>,
}
Expand description

Process-lifetime per-model defect counters.

A synchronous mutex over a small map: every operation is a couple of integer bumps under the lock, on paths that already do far heavier work.

Fields§

§counts: Mutex<HashMap<String, ModelDefectCounts>>

Implementations§

Source§

impl ModelDefectLedger

Source

pub fn new() -> Self

Create an empty ledger.

Source

pub fn record_request(&self, model: &str)

Count one request for model.

Source

pub fn record_loop_guard_trip(&self, model: &str, which: LoopGuardTrip)

Count one loop-guard intervention for model, under the detector that raised it.

Since #1052 an intervention is a note or a refusal — the default forwards the request with a note rather than rejecting it.

Bumps the detector’s own count and loop_guard_trips, which stays the sum of the two. Also counts the request itself: a trip outside its own denominator would overstate every rate computed from these numbers.

Scoped to the snapshot, not the client request. Exactly one of this and Self::record_request runs per snapshot recorded, because the caller branches on whether the snapshot names a detector. A client request that is noted and then retried after an upstream death records two snapshots — the second deliberately carries no trip — so it bumps requests twice and loop_guard_trips once. That double count of requests predates this and is the retry path’s, not the guard’s.

Source

pub fn record_repair(&self, model: &str, succeeded: bool)

Count one tool-call repair attempt for model.

Source

pub fn record_stream_error(&self, model: &str)

Count one upstream mid-stream failure for model.

Deliberately does not bump requests, unlike Self::record_loop_guard_trip, which counts a request the guard acted on — refused instead of forwarding, or forwarded with a note — and so has to count its own denominator either way. A stream error happens after the request was forwarded and already counted; bumping here would count the same request twice and deflate every rate.

Source

pub fn record_truncated_generation(&self, model: &str)

Count one generation cut off at the token ceiling for model.

Source

pub fn record_empty_response(&self, model: &str, reasoning_only: bool)

Count one turn that produced nothing client-renderable for model.

reasoning_only says whether the model produced reasoning and nothing else. It is counted within the empty total, not beside it — the turn was empty either way, and this records why.

Source

pub fn record_dialect_residue(&self, model: &str)

Count one turn where dialect markup reached client-visible output.

Source

pub fn record_unvalidatable_schema(&self, model: &str)

Count one turn whose tool call could not be validated at all.

Source

pub fn record_normalization_error(&self, model: &str)

Count one turn whose normalization discarded a malformed tool call.

Source

pub fn record_identical_result_repeat(&self, model: &str)

Count one turn that repeated the call before it and got an equal result back.

Source

pub fn record_repeat_rescued(&self, model: &str)

Count one turn the guard would have acted on for repeating and did not, because the answer had moved. A repeat still inside the allowance is not.

Source

pub fn record_repeat_not_evaluated(&self, model: &str)

Record that one turn repeated a batch whose results could not be compared.

Source

pub fn snapshot(&self) -> HashMap<String, ModelDefectCounts>

The current counts for every model that has any.

Source

fn with(&self, model: &str, update: impl FnOnce(&mut ModelDefectCounts))

Trait Implementations§

Source§

impl Debug for ModelDefectLedger

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ModelDefectLedger

Source§

fn default() -> ModelDefectLedger

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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