From 73a34dd7f13d65cf119d1194504e4d32ceb40bfa Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 1 Oct 2026 17:14:03 +0530 Subject: [PATCH] refactor(state): hoist guard-error import and fix prune docstring order The never-active keyed prune deletes the row first and drops its routing entry only once the delete succeeded (row-then-entry), but the docstring said entry-then-row. hermes_state_errors imports only stdlib, so the function-local import has no cycle to dodge; hoist it to module top like hermes_state_sessions already does. --- hermes_state_gateway.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hermes_state_gateway.py b/hermes_state_gateway.py index 7179eb55d9..e46fcd56dc 100644 --- a/hermes_state_gateway.py +++ b/hermes_state_gateway.py @@ -15,6 +15,7 @@ from typing import Any, Dict, List, Optional, Set, Tuple from hermes_state_common import ( _RECOVERABLE_END_REASONS_SQL, _RESET_CHILD_SQL, _RESET_END_REASONS_SQL, _sql_json_extract, _sql_session_last_active) +from hermes_state_errors import SessionActiveWriteGuardError # Log-record parity with the origin module (caplog tests pin "hermes_state"). logger = logging.getLogger("hermes_state") @@ -404,7 +405,7 @@ class SessionGatewayMixin: Rows under a live turn lease or compression lock are skipped (#123583): the never-active predicate reads committed state, so a keyed row whose first turn lease is already held — its messages not yet flushed — would otherwise be deleted - mid-turn. Each deleted row's routing entry is dropped per row, entry-then-row in + mid-turn. Each deleted row's routing entry is dropped per row, row-then-entry in the same failure domain: a stale entry outliving its target would have the gateway resume a nonexistent id, and an entry deleted ahead of a bulk sweep that later aborts mid-loop (any non-guard write error propagates out of ``_execute_write``) @@ -413,7 +414,6 @@ class SessionGatewayMixin: if not candidates: return (0, 0) ids = {str(row["id"]) for row in candidates} - from hermes_state_errors import SessionActiveWriteGuardError deleted = routing_deleted = 0 for sid in ids: try: