Skip to main content

record_threshold_event

Function record_threshold_event 

Source
pub fn record_threshold_event(
    data_dir: &Path,
    session_id: Option<String>,
    tokens_before: usize,
    tokens_after: usize,
    context_window: usize,
    duration_ms: u64,
    cadence_enabled: bool,
)
Expand description

Build and emit the SURFACE_TCODE_THRESHOLD telemetry record for one AgentLoop::maybe_compact_transcript fire, and — when cadence_enabled — the Slice B durable alarm line alongside it (issues #3867, #3868).

Why: keeps AgentLoop::maybe_compact_transcript a thin call rather than inlining the event construction + percentage derivation at that call site (this crate’s 500-SLOC production file cap). What: compaction_event is always true (issue #3867: true only for tcode-threshold fires — this function is only ever called on one). cadence_enabled gates the alarm line only — the JSONL record itself is unconditional, per issue #3867’s spec. Test: tests::record_threshold_event_writes_jsonl_and_alarm_when_cadence_enabled, tests::record_threshold_event_no_alarm_when_cadence_disabled.