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§
- Compression
Event - One JSONL line: a single compression/summarization event (issue #3867).
Constants§
- DATA_
DIR_ ENV_ VAR - Escape-hatch env var overriding
default_data_dirfor one process, mirroringcadence::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_detailused for everySURFACE_TCODE_CADENCErecord.- DETAIL_
CADENCE_ FLOOR_ BREACH surface_detailused for everySURFACE_TCODE_CADENCE_FLOOR_BREACHrecord.- DETAIL_
THRESHOLD surface_detailused for everySURFACE_TCODE_THRESHOLDrecord.- SURFACE_
TCODE_ CADENCE CompressionEvent::surfacevalue for the #2346 cadence compressor.- SURFACE_
TCODE_ CADENCE_ FLOOR_ BREACH CompressionEvent::surfacevalue for a #3911 cadence floor-breach backstop fire — seerecord_cadence_floor_breach.- SURFACE_
TCODE_ THRESHOLD CompressionEvent::surfacevalue 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.0whentokens_before == 0.- context_
pcts - Derive
(working_context_pct, overhead_pct)from a raw token measurement against a model’s context window, mirroringcadence::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_VARwhen set (test isolation), otherwisecrate::workstreams::default_data_dir()(~/.trusty-code, production). - lifetime_
cadence_ floor_ breach_ count - Count how many times
record_cadence_floor_breach_alarmhas ever fired fordata_dir— the lifetime, cross-session, cross-restart alarm count exposed onsession.get_context_budgetaslifetime_cadence_floor_breach_count(issue #3911). - lifetime_
compaction_ alarm_ count - Count how many times
record_compaction_alarmhas ever fired fordata_dir— the lifetime, cross-session, cross-restart alarm count exposed onsession.get_context_budgetaslifetime_compaction_alarm_count(issue #3868). - record_
cadence_ event - Build and emit the
SURFACE_TCODE_CADENCEtelemetry record for oneAgentLoop::maybe_cadence_compresscall whoseoutcome.rounds > 0(issue #3867). - record_
cadence_ floor_ breach - Build and emit the
SURFACE_TCODE_CADENCE_FLOOR_BREACHtelemetry record plus the durablerecord_cadence_floor_breach_alarmline, for oneAgentLoop::maybe_cadence_compresscall whoseCadenceOutcome::within_budgetwasfalse(issue #3911). - record_
cadence_ floor_ breach_ alarm - Append one line to
<data_dir>/cadence_floor_breach_alarm.log, recording thatcadence::enforce_budgetexhausted 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 acadence: Some(_)threshold-compaction fire just happened (issue #3868). - record_
threshold_ event - Build and emit the
SURFACE_TCODE_THRESHOLDtelemetry record for oneAgentLoop::maybe_compact_transcriptfire, and — whencadence_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.jsonllog (issue #3912). - write_
compression_ event - Append
eventas one JSONL line to<data_dir>/compression.jsonl.