Files
hermes-agent/hermes_state_mutation_compress.py
teknium1 03f987dab8 fix(compress): report the canonical /compress outcome like native /compress
The canonical compress mutation returned no report, so the Ink TUI printed a
bare '✓ transcript compressed' instead of the 'Compressed: N → M messages'
headline, token line and note every native /compress shows. Build the same
summarize_manual_compression() report while preparing the mutation, keep it
in the durable result (exact retries replay it), and print it in the TUI.

(cherry picked from commit 8f4c08abfd65125eefca469785cd7ae35746421e)
2026-09-27 14:46:19 -07:00

28 lines
1.6 KiB
Python

"""Commit a prepared summary, physical target, generation and receipt atomically."""
import uuid
from hermes_state_mutation_prepared import validate_prepared
def compress_in_transaction(db, conn, session_id, payload, prepared):
snapshot = validate_prepared(db, conn, session_id, prepared)
policy = snapshot['receipt']['policy']
target = snapshot['target']
from hermes_state_worker_compression import archive_on_connection, publish_on_connection
# No worker/turn/compactor can be active: validate_prepared checks those
# obligations on this exact connection. No separate legacy transaction runs.
if prepared['in_place']:
child = target
archive_on_connection(db, conn, target, prepared['messages'])
affected = {session_id, target}
else:
child = uuid.uuid4().hex
publish_on_connection(db, conn, parent_session_id=target, child_session_id=child,
source=policy['source'], model=policy['model'], messages=prepared['messages'],
model_config={'_compressed_from': target}, cwd=policy['cwd'], require_compression_lease=False)
affected = set() # Rotation publication already advances the logical revision.
conn.execute('UPDATE sessions SET runtime_generation=runtime_generation+1 WHERE id=?', (session_id,))
generation = conn.execute('SELECT runtime_generation FROM sessions WHERE id=?', (session_id,)).fetchone()[0]
return affected, {'target_session_id': child, 'previous_target_session_id': target,
'execution_generation': generation, 'message_count': len(prepared['messages']),
'summary': prepared.get('summary')}