Files
hermes-agent/tests/persistence_sqlite/conversation/test_message_reference_reads.py
Electric Sheep e7e66a1120 fix(compression): read every archive reference row, without the 20,000 cap
referenced_archive_refs read at most 20,001 rows and answered "unknown"
past 20,000, and the sweep then kept every file in cache/pruned and
cache/spillover. Every prune stub row counts toward that number, so a
busy home passed it and was never swept again.

Rows are now read one at a time with no cap; memory is bounded by the
reference set. Any database error still answers "unknown", so the sweep
still fails closed. Below the old cap the cost is unchanged (the filter
has no index, so the whole table was already scanned). Past it the read
used to stop at the 20,001st match and now runs to the end, so on a
large home it stays open longer. The docs sentence about the cap is
removed.

(cherry picked from commit a5bed1d2d9fb436f6129388b237330a509abb6aa)
2026-11-18 20:36:07 -08:00

44 lines
2.3 KiB
Python

"""Message verbs on SQLite whose statements keep the legacy readers' shape: the spillover reference read (uncapped,
streamed), the latest dialogue message's one content cell, and the row stamps an archive-dropped replace leaves on the
rows it keeps."""
from persistence.conversation.messages import NewMessage, ReplaceMode
from persistence.conversation.sessions import NewSession
def test_spillover_reference_rows_stream_every_referencing_row(backend, scope_a):
store = backend.open(scope_a)
store.sessions.create(NewSession("spill", "cli"))
for i in range(3):
store.messages.append("spill", NewMessage("assistant", f"see spillover/file-{i}.txt"))
store.messages.append("spill", NewMessage("user", "nothing to see"))
rows = store.messages.spillover_reference_rows()
assert sorted(content for content, _ in rows) == [f"see spillover/file-{i}.txt" for i in range(3)]
with store.holder()._lock:
store.holder()._conn.executemany(
"INSERT INTO messages (session_id, role, content, timestamp) VALUES ('spill', 'tool', ?, 0)",
[(f"spillover/bulk-{i}",) for i in range(20001)])
assert len(list(store.messages.spillover_reference_rows())) == 20004
def test_latest_dialogue_message_is_the_stored_content_cell(backend, scope_a):
store = backend.open(scope_a)
store.sessions.create(NewSession("dialog", "cli"))
store.messages.append("dialog", NewMessage("user", " first question "))
store.messages.append("dialog", NewMessage("tool", "tool output"))
assert store.messages.latest_dialogue_message("dialog") == " first question "
assert store.messages.latest_dialogue_message("missing") is None
def test_archive_dropped_replace_leaves_kept_rows_without_a_snapshot(backend, scope_a):
store = backend.open(scope_a)
store.sessions.create(NewSession("swap", "cli"))
store.messages.append("swap", NewMessage("user", "first", timestamp=1.0))
store.messages.append("swap", NewMessage("assistant", "old answer", timestamp=2.0))
result = store.messages.replace_transcript(
"swap", [NewMessage("user", "first", timestamp=1.0), NewMessage("assistant", "new answer", timestamp=3.0)],
ReplaceMode.ARCHIVE_DROPPED)
kept, written = result.rows
assert kept.db_row_snapshot is None
assert isinstance(written.db_row_snapshot, str) and written.db_row_snapshot