The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(state): re-escape a retired result's own _stored key
unsupportedpastelsbf1ebbc894bc
diff --git a/hermes_state_mutation_retirement.py b/hermes_state_mutation_retirement.pyindex 516c3ec4210..3c605b6873f 100644--- a/hermes_state_mutation_retirement.py+++ b/hermes_state_mutation_retirement.py@@ -62,7 +62,7 @@ def _compact_result(conn, admission_id):"""A retired result keeps the exact-retry outcome (final response, flags, usage/accounting)but not the transcript copies a turn result carries (cumulative ``messages``, reasoning, thesettled ``_turn_user_row``)."""- from hermes_state_terminal import RESULT_PREFIX, load_result+ from hermes_state_terminal import RESULT_PREFIX, encode_result, load_resultsaved = conn.execute('SELECT value FROM state_meta WHERE key=?', (RESULT_PREFIX + admission_id,)).fetchone()if saved is None:return@@ -70,7 +70,7 @@ def _compact_result(conn, admission_id):result = value.get('result')if isinstance(result, dict):value['result'] = {**{k: v for k, v in result.items() if k not in _TRANSCRIPT_FIELDS}, 'messages': []}- conn.execute('UPDATE state_meta SET value=? WHERE key=?', (_json(value), RESULT_PREFIX + admission_id))+ conn.execute('UPDATE state_meta SET value=? WHERE key=?', (_json(encode_result(value)), RESULT_PREFIX + admission_id))def retire_terminal_receipts(conn, session_ids):diff --git a/tests/gateway/test_admission_result_reply_once.py b/tests/gateway/test_admission_result_reply_once.pyindex 140fe6e847e..7075bbfcaf1 100644--- a/tests/gateway/test_admission_result_reply_once.py+++ b/tests/gateway/test_admission_result_reply_once.py@@ -175,8 +175,8 @@ _LEGACY = {'result': {'final_response': REPLY, '_messages_are_turn_suffix': True])def test_any_stored_row_reads_back_as_the_pre_change_shape(owner, result, copies):"""Every row, new or written by an earlier release, decodes to the identical dict, key order- included. Message fields are not format metadata, and a producer-built ``_stored`` is never- taken for the envelope."""+ included, before and after its session is deleted. Message fields are not format metadata,+ and a producer-built ``_stored`` is never taken for the envelope."""admission_id, expected = _stored_round_trip(owner, result)if copies is None: # the row as an earlier release wrote itexpected = result@@ -187,3 +187,12 @@ def test_any_stored_row_reads_back_as_the_pre_change_shape(owner, result, copiesassert copies is None or raw.count(REPLY) == copiesassert json.dumps(admission_result(owner.db, admission_id)) == json.dumps(expected)assert json.dumps(load_result(json.dumps(encode_result(expected)))) == json.dumps(expected)+ # Retirement rewrites the row (keys sorted) without its transcript copies; nothing else changes.+ snap = owner.db.get_session('r')+ mutate_runtime_session(owner.db, epoch=owner.epoch, principal_id='human', session_id='r', request_id='del',+ operation='delete', payload={}, expected_revision=snap['runtime_revision'],+ expected_generation=snap['runtime_generation'])+ from hermes_state_mutation_retirement import _TRANSCRIPT_FIELDS+ kept = json.loads(_json({**expected, 'result': {+ **{k: v for k, v in expected['result'].items() if k not in _TRANSCRIPT_FIELDS}, 'messages': []}}))+ assert json.dumps(admission_result(owner.db, admission_id)) == json.dumps(kept)