Skip to main content

Module telemetry

Module telemetry 

Source
Expand description

Durable compression-effectiveness telemetry (epic #3866, Slice A #3867 + Slice B #3868).

Why: cadence::CadenceOutcome and the #2308 threshold compactor both compute real token/ratio numbers every time they fire, and — before this module — every one of those numbers was thrown away past a tracing::info!/tracing::error! line (stderr-only, never aggregated) or an in-memory-only cache that resets on session end. Owner directive: “measure compression effectiveness, and use logging to track it.” This module is the durable, structured, cross-session, machine-aggregable third channel crate::logging’s own “logs vs. events” doc note says tracing/crate::events cannot serve — see crates/trusty-code/src/ logging/mod.rs. What: CompressionEvent is one JSONL record per compression/ summarization event, appended (best-effort, mirroring trusty-agents::usage::append_usage’s failure posture exactly) to ~/.trusty-code/compression.jsonl via write_compression_event. record_compaction_alarm/lifetime_compaction_alarm_count are Slice B’s durable “has threshold compaction EVER fired under cadence” never-event alarm: a dedicated append-only log (~/.trusty-code/compaction_alarm.log), one line per fire, counted by line rather than read-modify-write so concurrent fires can never race each other into a lost increment. Test: telemetry::tests::*.

Structs§

CompressionEvent
One JSONL line: a single compression/summarization event (issue #3867).

Constants§

DATA_DIR_ENV_VAR
Escape-hatch env var overriding default_data_dir for one process, mirroring cadence::CADENCE_TURNS_ENV_VAR’s precedent. Test-only in practice (production never sets it) — lets a test point every telemetry write/read at an isolated temp directory instead of the real ~/.trusty-code.
DETAIL_CADENCE
surface_detail used for every SURFACE_TCODE_CADENCE record.
DETAIL_CADENCE_FLOOR_BREACH
surface_detail used for every SURFACE_TCODE_CADENCE_FLOOR_BREACH record.
DETAIL_THRESHOLD
surface_detail used for every SURFACE_TCODE_THRESHOLD record.
SURFACE_TCODE_CADENCE
CompressionEvent::surface value for the #2346 cadence compressor.
SURFACE_TCODE_CADENCE_FLOOR_BREACH
CompressionEvent::surface value for a #3911 cadence floor-breach backstop fire — see record_cadence_floor_breach.
SURFACE_TCODE_THRESHOLD
CompressionEvent::surface value for the #2308 threshold compactor.

Functions§

cadence_floor_breach_alarm_log_path
Resolve <data_dir>/cadence_floor_breach_alarm.log (issue #3911).
compaction_alarm_log_path
Resolve <data_dir>/compaction_alarm.log.
compression_log_path
Resolve <data_dir>/compression.jsonl.
compute_ratio
tokens_after / tokens_before, 0.0 when tokens_before == 0.
context_pcts
Derive (working_context_pct, overhead_pct) from a raw token measurement against a model’s context window, mirroring cadence::CadenceOutcome::working_context_pct/overhead_pct’s own saturating arithmetic (never a divide-by-zero, never > 100).
default_data_dir
Resolve the data directory every telemetry read/write in this module uses: DATA_DIR_ENV_VAR when set (test isolation), otherwise crate::workstreams::default_data_dir() (~/.trusty-code, production).
lifetime_cadence_floor_breach_count
Count how many times record_cadence_floor_breach_alarm has ever fired for data_dir — the lifetime, cross-session, cross-restart alarm count exposed on session.get_context_budget as lifetime_cadence_floor_breach_count (issue #3911).
lifetime_compaction_alarm_count
Count how many times record_compaction_alarm has ever fired for data_dir — the lifetime, cross-session, cross-restart alarm count exposed on session.get_context_budget as lifetime_compaction_alarm_count (issue #3868).
record_cadence_event
Build and emit the SURFACE_TCODE_CADENCE telemetry record for one AgentLoop::maybe_cadence_compress call whose outcome.rounds > 0 (issue #3867).
record_cadence_floor_breach
Build and emit the SURFACE_TCODE_CADENCE_FLOOR_BREACH telemetry record plus the durable record_cadence_floor_breach_alarm line, for one AgentLoop::maybe_cadence_compress call whose CadenceOutcome::within_budget was false (issue #3911).
record_cadence_floor_breach_alarm
Append one line to <data_dir>/cadence_floor_breach_alarm.log, recording that cadence::enforce_budget exhausted every eligible entry and STILL exceeded the overhead cap this turn (issue #3911’s backstop).
record_compaction_alarm
Append one line to <data_dir>/compaction_alarm.log, recording that a cadence: Some(_) threshold-compaction fire just happened (issue #3868).
record_threshold_event
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).
session_working_context_floor
Session-scoped working-context low-water mark, read fresh from the durable compression.jsonl log (issue #3912).
write_compression_event
Append event as one JSONL line to <data_dir>/compression.jsonl.