Skip to content

The agent that grows with you

refactor(compression): drop the unread attempt-seed copy and log attempt records from one helper

kshitijk4poor54471e04a48d
diff --git a/agent/conversation_compression.py b/agent/conversation_compression.py
index d87344b319e..5407ad9eea3 100644
--- a/agent/conversation_compression.py
+++ b/agent/conversation_compression.py
@@ -3699,7 +3699,7 @@ def _commit_compaction(
messages_before_compression: Optional[list], made_progress: bool, attempt: _Attempt,
verbatim_tail: Optional[list] = None, carried_messages: Optional[list] = None,
) -> _CommitOutcome:
- """Persist the compacted transcript: memory extraction, anti-growth guard, then the
+ """Persist the compacted transcript: anti-growth guard, memory extraction, then the
in-place archive or the parent->child rotation.
Failures roll the live list back and arm the split-failure cooldown; a refused (would-grow) candidate returns
@@ -3771,7 +3771,7 @@ def _commit_compaction(
from agent.conversation_compression_archive import coverage_for_commit
covered_ids, unresolved_held = coverage_for_commit(
agent._session_db, agent.session_id,
- messages_before_compression if messages_before_compression is not None else messages,
+ original_messages,
verbatim_tail)
agent._session_db.archive_and_compact(
agent.session_id, persisted, model_config_patch={PROACTIVE_PRUNE_REARM_MODEL_CONFIG_KEY: None},
@@ -4049,8 +4049,6 @@ def _begin_compression_attempt(
}
with contextlib.suppress(Exception):
agent._compression_attempt_id = attempt_id
- # The agent keeps its own copy: a pre-commit restore puts the previous seed back on the compressor.
- agent._compression_attempt_seed = dict(seed)
from hermes_cli.observability.shared_metrics_events import begin_compression_attempt
begin_compression_attempt(trigger, approx_tokens or getattr(agent.context_compressor, "last_prompt_tokens", None))
diff --git a/agent/conversation_compression_telemetry.py b/agent/conversation_compression_telemetry.py
index 5b533875e4b..faa77ebd977 100644
--- a/agent/conversation_compression_telemetry.py
+++ b/agent/conversation_compression_telemetry.py
@@ -66,22 +66,23 @@ def _attempt_seed(
) -> dict[str, Any]:
"""This attempt's id, the session it started in, and its trigger.
- ``attempt_seed`` is the attempt's own copy and wins: the agent's copy belongs to the newest attempt, so a
- stalled attempt unwinding after its fallback began would otherwise log the fallback's identity. Without
- it, read the agent's copy (a pre-commit restore puts the previous attempt's seed back on the compressor).
+ ``attempt_seed`` is the attempt's own copy and wins: the agent's current-attempt fields belong to the newest
+ attempt, so a stalled attempt unwinding after its fallback began would otherwise log the fallback's identity.
An emit with no attempt begun (pool saturation) gets a fresh id and an unknown trigger."""
if attempt_seed:
return dict(attempt_seed)
attempt_id = getattr(agent, "_compression_attempt_id", None) if attempt_began else None
- seed = getattr(agent, "_compression_attempt_seed", None)
- if attempt_id and isinstance(seed, dict) and seed.get("attempt_id") == attempt_id:
- return dict(seed)
return {
"attempt_id": attempt_id or uuid.uuid4().hex, "session_id": getattr(agent, "session_id", "") or "",
"trigger_source": "unknown",
}
+def _log_attempt_record(payload: dict[str, Any]) -> None:
+ """The one attempt log line; ``scripts/micro_compaction_report.py`` parses this prefix."""
+ logger.info("context compression attempt telemetry: %s", json.dumps(payload, sort_keys=True, separators=(",", ":")))
+
+
def _emit_compression_attempt_telemetry(
agent: Any, *, started_at: float, commit_status: str, split_status: str, failure_class: str | None = None,
commit_started_at: float | None = None, include_last_telemetry: bool = True,
@@ -130,9 +131,7 @@ def _emit_compression_attempt_telemetry(
or getattr(compressor, "_last_aux_model_failure_model", None)
)
)
- logger.info(
- "context compression attempt telemetry: %s", json.dumps(payload, sort_keys=True, separators=(",", ":"))
- )
+ _log_attempt_record(payload)
publish_attempt(agent, payload)
from hermes_cli.observability.shared_metrics_events import finish_compression_attempt
@@ -173,9 +172,7 @@ def _emit_bypassed_attempt_telemetry(
"total_duration_ms": int((time.monotonic() - started_at) * 1000), "commit_status": commit_status,
"split_status": "not_applicable", "fallback_used": False,
}
- logger.info(
- "context compression attempt telemetry: %s", json.dumps(payload, sort_keys=True, separators=(",", ":"))
- )
+ _log_attempt_record(payload)
publish_attempt(agent, payload)
except Exception as exc:
logger.debug("failed to emit compression attempt telemetry: %s", exc, exc_info=True)