Skip to content

The agent that grows with you

fix(telemetry): compression attempts that could not fail count as skipped, not failed

Tekniumb813bb1b2d95
diff --git a/hermes_cli/observability/shared_metrics_events.py b/hermes_cli/observability/shared_metrics_events.py
index 514ee6b19f7..b8a4a0e96ae 100644
--- a/hermes_cli/observability/shared_metrics_events.py
+++ b/hermes_cli/observability/shared_metrics_events.py
@@ -65,6 +65,14 @@ def record_compression(
# began on another thread. An attempt begins and emits on one thread (the pool worker or the caller).
_compression_attempt = threading.local()
+# Attempts that ended before anything could fail: another path held the lock, the transcript had
+# nothing summarizable (no LLM call was made), the user stopped it, or a newer attempt replaced it.
+# Counting these as ``failed`` made a session that is simply all protected tail read as broken.
+_SKIPPED_COMPRESSION_CLASSES = frozenset({
+ "lock_contended", "insufficient_messages", "no_compressible_window", "empty_post_handoff_window",
+ "explicit_interrupt", "attempt_superseded", "snapshot_stale",
+})
+
def begin_compression_attempt(trigger: str, tokens_before: Any) -> None:
_compression_attempt.pending = (trigger, tokens_before)
@@ -77,7 +85,10 @@ def finish_compression_attempt(
pending, _compression_attempt.pending = getattr(_compression_attempt, "pending", None), None
if not pending:
return
- outcome = "success" if commit_status == "committed" else "skipped" if failure_class == "lock_contended" else "failed"
+ outcome = (
+ "success" if commit_status == "committed"
+ else "skipped" if failure_class in _SKIPPED_COMPRESSION_CLASSES else "failed"
+ )
record_compression(trigger=pending[0], outcome=outcome, tokens_before=pending[1], context_length=context_length)
if outcome == "success" and agent is not None:
from .shared_metrics_efficiency import record_cache_break
diff --git a/tests/agent/test_compression_attempt_telemetry.py b/tests/agent/test_compression_attempt_telemetry.py
index d0243a8da79..89bc51cdb86 100644
--- a/tests/agent/test_compression_attempt_telemetry.py
+++ b/tests/agent/test_compression_attempt_telemetry.py
@@ -225,21 +225,15 @@ def test_automatic_compaction_counts_once_in_shared_metrics(monkeypatch):
]
-def test_structural_no_op_keeps_the_compressors_failure_class(caplog, monkeypatch):
- """A transcript that fits inside the tail budget is logged as ``no_compressible_window``.
-
- The compressor classifies WHY it returned the transcript unchanged; the caller only observes THAT
- it did (``no_progress``). The attempt log line and the shared-metrics sink must both carry the
- compressor's class, or an operator reads "the summarizer achieved nothing" for an attempt that
- never made a summary call (#131412).
- """
+def test_structural_no_op_is_counted_skipped_with_the_compressors_class(caplog, monkeypatch):
+ """A transcript that fits inside the protected tail makes no summary call: the attempt log names
+ ``no_compressible_window`` (not the caller's generic ``no_progress``) and the shared metric counts
+ it ``skipped``, not ``failed`` (#131412)."""
from hermes_cli.observability import shared_metrics_events
+ from hermes_cli.observability.shared_metrics_fields import compression_fields
- finished = []
- monkeypatch.setattr(
- shared_metrics_events, "finish_compression_attempt",
- lambda commit_status, failure_class, *_args, **_kwargs: finished.append((commit_status, failure_class)),
- )
+ recorded = []
+ monkeypatch.setattr(shared_metrics_events, "record_compression", lambda **kw: recorded.append(kw))
with patch("agent.context_compressor.get_model_context_length", return_value=100_000):
compressor = ContextCompressor(
model="test/main-model", provider="test-provider", threshold_percent=0.50, quiet_mode=True,
@@ -248,16 +242,14 @@ def test_structural_no_op_keeps_the_compressors_failure_class(caplog, monkeypatc
agent = _Agent(compressor)
messages = _messages()
- # Every row lands inside the protected tail, so the summarizable middle window is empty.
with patch.object(compressor, "_find_tail_cut_by_tokens", return_value=0):
with caplog.at_level(logging.INFO, logger="agent.conversation_compression"):
- compressed, _ = compress_context(agent, messages, "system prompt", approx_tokens=75_000, force=True)
+ compressed, _ = compress_context(agent, messages, "system prompt", approx_tokens=75_000)
assert compressed == messages
payload = _extract_telemetry(caplog)
- assert payload["commit_status"] == "aborted"
- assert payload["failure_class"] == "no_compressible_window"
- assert finished == [("aborted", "no_compressible_window")]
+ assert (payload["commit_status"], payload["failure_class"]) == ("aborted", "no_compressible_window")
+ assert [compression_fields(**kw)["outcome"] for kw in recorded] == ["skipped"]
@pytest.mark.parametrize(
diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.md
index 6b6e3e7f079..a0c30e92786 100644
--- a/website/docs/developer-guide/relay-shared-metrics.md
+++ b/website/docs/developer-guide/relay-shared-metrics.md
@@ -339,7 +339,7 @@ itself ships.
| `hermes.setup.completed` | surface (`cli`/`desktop`), provider | Which providers people choose at setup, and on which surface. |
| `hermes.model_tokens.sum` | call role, model, provider, auxiliary task, token type | Token volume per model/provider, prompt-cache share, and what auxiliary work (compression, titles, vision, ...) costs. The value is a token sum, not an event count. |
| `hermes.model_route.count` `ttft_bucket` | time to first token | Perceived latency per provider/model. |
-| `hermes.compression.count` | trigger, outcome, context-fill bucket | How often compaction runs, how full contexts get, and whether it fails. |
+| `hermes.compression.count` | trigger, outcome, context-fill bucket | How often compaction runs, how full contexts get, and whether it fails. `skipped` = nothing could fail: lock held elsewhere, nothing summarizable (no model call), user stop, or a newer attempt replaced it. |
| `hermes.model_switch.count` | from/to provider, surface | Which providers people leave and move to. |
| `hermes.fallback.count` | from/to provider, error class | How often fallback providers rescue a turn, and from what. |
| `hermes.slash_command.count` | command, surface | Which built-in commands are used (`/retry`, `/undo`, `/new` are friction signals). Skill and plugin commands report `skill`/`plugin`. |