Skip to content

The agent that grows with you

refactor(state): name absorbed-row stamps by constant, hoist replay-entry import

kshitijk4poor28a0bf19e63d
diff --git a/gateway/run.py b/gateway/run.py
index 73c0e7ed390..f745ad816df 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -37,6 +37,7 @@ from agent.conversation_compression import (
COMPRESSION_RETRY_MESSAGES_STATUS_TEMPLATE, COMPRESSION_RETRY_TOKENS_STATUS_TEMPLATE,
COMPRESSION_RETRY_TOO_LARGE_STATUS_TEMPLATE, IDLE_COMPACTION_STATUS_TEMPLATE,
PRE_API_COMPRESSION_STATUS_TEMPLATE, PREFLIGHT_COMPRESSION_STATUS_TEMPLATE)
+from agent.conversation_compression_archive import MERGED_DURABLE_ROWS, RETIRED_DURABLE_ROWS, UNNAMED_DURABLE_ROWS
from agent.conversation_loop import INTERRUPT_WAITING_FOR_MODEL_PREFIX
from agent.interrupt_compat import request_hard_interrupt
from agent.message_metadata import ABSORBED_MESSAGE_UIDS, MESSAGE_UID, copy_identity_fields
@@ -1159,9 +1160,6 @@ def _build_replay_entry(
# A merged user dict lost that stamp; this one is what ties it to its durable rows at compaction.
# The other counts the rows the repair dropped behind a dict or folded into an assistant turn,
# which this view cannot name either; the last names them for the commit.
- from agent.conversation_compression_archive import (
- MERGED_DURABLE_ROWS, RETIRED_DURABLE_ROWS, UNNAMED_DURABLE_ROWS)
-
for stamp in (MERGED_DURABLE_ROWS, UNNAMED_DURABLE_ROWS, RETIRED_DURABLE_ROWS):
if msg.get(stamp):
entry[stamp] = msg[stamp]
diff --git a/hermes_state_coverage.py b/hermes_state_coverage.py
index b0993f48764..d19f8a0e682 100644
--- a/hermes_state_coverage.py
+++ b/hermes_state_coverage.py
@@ -11,17 +11,12 @@ from typing import Any, Dict, List, Optional, Set, Tuple
from hermes_cli.timefmt import coerce_epoch
from hermes_state_common import _placeholders
-from hermes_state_messages import _parse_tool_calls, _tool_calls_len
+from hermes_state_messages import _parse_tool_calls
class SessionCoverageMixin:
"""Coverage helpers for SessionDB; relies on SessionMessagesMixin's codec/identity helpers."""
- def _tail_rows_after_watermark(self, conn, sql: str, params) -> Tuple[List[int], int]:
- """``(ids, tool_call_count)`` of the concurrent-tail rows selected by *sql* (``SELECT id, tool_calls``)."""
- rows = conn.execute(sql, params).fetchall()
- return [int(r["id"]) for r in rows], sum(_tool_calls_len(r["tool_calls"]) for r in rows)
-
def _resolve_carried_row_ids(
self, conn, session_id: str, carried_messages: List[Dict[str, Any]],
) -> List[int]:
@@ -201,7 +196,7 @@ class SessionCoverageMixin:
return None
from agent.context_compressor import _DB_PERSISTED_MARKER
from agent.conversation_compression_archive import (
- MERGED_DURABLE_ROWS, OWN_ROW, RETIRED_DURABLE_ROWS, RETIRED_ROW)
+ ABSORBED_ROW_IDS, MERGED_DURABLE_ROWS, OWN_ROW, RETIRED_DURABLE_ROWS, RETIRED_ROW)
proved = [int(row_id) for row_id in covered_ids if isinstance(row_id, int) and row_id > 0]
merged_away: Set[int] = set()
@@ -233,7 +228,7 @@ class SessionCoverageMixin:
message.get(_DB_PERSISTED_MARKER) and len(matches) != 1 and not run):
return None
proved.extend(matches or run)
- merged_away.update(set(run[1:]) - set(message.get("_absorbed_row_ids") or ()))
+ merged_away.update(set(run[1:]) - set(message.get(ABSORBED_ROW_IDS) or ()))
return list(dict.fromkeys(proved)), merged_away
@staticmethod
@@ -246,11 +241,11 @@ class SessionCoverageMixin:
without ids are in neither, so their count is added. A dict that holds a ``_row_id`` was
written back as a single row by an earlier compaction.
"""
- from agent.conversation_compression_archive import MERGED_DURABLE_ROWS, UNNAMED_DURABLE_ROWS
+ from agent.conversation_compression_archive import ABSORBED_ROW_IDS, MERGED_DURABLE_ROWS, UNNAMED_DURABLE_ROWS
def behind(message: Dict[str, Any]) -> int:
merged, unnamed = message.get(MERGED_DURABLE_ROWS), message.get(UNNAMED_DURABLE_ROWS)
- unlisted = merged - 1 - len(message.get("_absorbed_row_ids") or ()) if type(merged) is int else 0
+ unlisted = merged - 1 - len(message.get(ABSORBED_ROW_IDS) or ()) if type(merged) is int else 0
return max(0, unlisted) + (unnamed if type(unnamed) is int else 0)
return sum(
diff --git a/hermes_state_messages.py b/hermes_state_messages.py
index 3f23076bad3..bf8a01a1a9e 100644
--- a/hermes_state_messages.py
+++ b/hermes_state_messages.py
@@ -902,6 +902,11 @@ class SessionMessagesMixin:
return int(self._read_one(
"SELECT COALESCE(MAX(id), 0) FROM messages WHERE session_id = ? AND active = 1", (session_id,))[0])
+ def _tail_rows_after_watermark(self, conn, sql: str, params) -> Tuple[List[int], int]:
+ """``(ids, tool_call_count)`` of the concurrent-tail rows selected by *sql* (``SELECT id, tool_calls``)."""
+ rows = conn.execute(sql, params).fetchall()
+ return [int(r["id"]) for r in rows], sum(_tool_calls_len(r["tool_calls"]) for r in rows)
+
def _clone_message_rows(self, conn, tail_ids: List[int], *, session_id: Optional[str] = None) -> None:
"""Pure-SQL clone of *tail_ids* as fresh live rows (new id/display order, active=1, compacted=0;
message payload columns stay byte-exact and FTS triggers index the clones), into *session_id* when given."""