The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): defer only a failed state read in the closed-tip lookup
unsupportedpastelsd0df5e07ba38
diff --git a/gateway/run_notifications_ownership.py b/gateway/run_notifications_ownership.pyindex 583f6be374e..7528ae1e779 100644--- a/gateway/run_notifications_ownership.py+++ b/gateway/run_notifications_ownership.py@@ -12,9 +12,11 @@ from __future__ import annotationsimport asyncioimport jsonimport logging+import sqlite3from typing import Any, Optional, Sequence, castfrom gateway.session import SessionEntry+from hermes_state_errors import StateDbReplacedError# Log-record parity with the origin module.logger = logging.getLogger("gateway.run")@@ -80,7 +82,7 @@ class GatewayNotificationOwnershipMixin:try:target = await session_db.get_compression_tip(pinned_session_id)row = await session_db.get_session(target) if target == entry.session_id else None- except Exception:+ except (sqlite3.Error, StateDbReplacedError):logger.debug("Closed local tip lookup failed for %s", pinned_session_id, exc_info=True)return "" # the compression path below defers itif (target != entry.session_id or row is None or not row.get("ended_at")diff --git a/tests/gateway/test_unviewed_completion_notes.py b/tests/gateway/test_unviewed_completion_notes.pyindex fe7c06d65c9..68ab248d940 100644--- a/tests/gateway/test_unviewed_completion_notes.py+++ b/tests/gateway/test_unviewed_completion_notes.py@@ -374,3 +374,27 @@ async def test_closed_tip_note_needs_the_route_to_name_it(tmp_path, monkeypatch)assert (await runner._classify_completion_owner(ancestor, route))[0] != 'deliver'finally:authority.db.close()+++async def test_closed_tip_lookup_defers_only_a_failed_read():+ """A state read that fails leaves the completion to the compression path, which defers it; any+ other error is a bug and surfaces instead of being logged at debug."""+ import sqlite3+ from types import SimpleNamespace+ from typing import Any+ from gateway.config import Platform+ from gateway.run_notifications_ownership import GatewayNotificationOwnershipMixin+ from hermes_state_errors import StateDbReplacedError+ entry: Any = SimpleNamespace(platform=Platform.LOCAL, session_id='lc7-tip')++ def db(error):+ async def tip(_session_id):+ raise error+ return SimpleNamespace(get_compression_tip=tip)++ lookup = GatewayNotificationOwnershipMixin()._closed_local_target+ for error in (sqlite3.OperationalError('database is locked'), StateDbReplacedError('replaced')):+ assert await lookup(db(error), entry, 'lc7-root', {'end_reason': 'compression'}) == ''+ with pytest.raises(AttributeError):+ await lookup(db(AttributeError('bug')), entry, 'lc7-root', {'end_reason': 'compression'})