Skip to content

The agent that grows with you

fix(gateway): log a refused local receipt once at boot

unsupportedpastels81a116e3f908
diff --git a/gateway/session_local_recovery.py b/gateway/session_local_recovery.py
index 0a263a338cf..db84a84cbb9 100644
--- a/gateway/session_local_recovery.py
+++ b/gateway/session_local_recovery.py
@@ -49,6 +49,10 @@ def _refused_check(exc):
return f'{cause}{where}{chained}'
+class _ReceiptRefused(RuntimeStoreError):
+ """A refused receipt ``restore_local_session`` already logged with its failing check."""
+
+
def _with_untracked_compression(authority, sid, receipt):
"""*receipt*, after recording compression steps an older build published past its tip (#140060)."""
from hermes_state_local_lineage import adopt_untracked_compression, untracked_compression_tip
@@ -107,8 +111,8 @@ def restore_local_session(authority, sid):
# The client only sees the bounded code: gateway.log names the check that refused (#140099).
logging.getLogger(__name__).warning('Local session %s receipt refused: %s', sid, _refused_check(exc))
if isinstance(exc, RuntimeStoreError):
- raise
- raise RuntimeStoreError('storage_unavailable') from exc
+ raise _ReceiptRefused(exc.reason, field=exc.field, detail=exc.detail) from exc
+ raise _ReceiptRefused('storage_unavailable') from exc
adapters = local_adapter_map(authority)
adapter = adapters.get(Platform.LOCAL)
if adapter is None:
@@ -213,6 +217,8 @@ def recover_local_sessions(authority, *, schedule=False):
pending = list_session_admissions(authority.db, session_id=sid)
if schedule and pending and not any(row['status'] == 'unknown' for row in pending):
authority._schedule(ref)
+ except _ReceiptRefused:
+ continue # restore_local_session logged the check that refused it
except RuntimeStoreError as exc:
logging.getLogger(__name__).warning('Local session %s paused: %s', sid, exc.reason)
if schedule:
diff --git a/tests/gateway/test_local_recovery_pre_profile_origin.py b/tests/gateway/test_local_recovery_pre_profile_origin.py
index 5a59cadbd5e..2a6f9375be6 100644
--- a/tests/gateway/test_local_recovery_pre_profile_origin.py
+++ b/tests/gateway/test_local_recovery_pre_profile_origin.py
@@ -175,6 +175,7 @@ async def test_a_refused_receipt_names_its_failing_check_in_the_log(tmp_path, mo
assert ref.session_id not in cold.sessions
recovery = [r.getMessage() for r in caplog.records if ref.session_id in r.getMessage()]
assert any(clause in message for message in recovery), recovery
+ assert len(recovery) == 1, f'one boot warning per refused receipt: {recovery}'
caplog.clear()
with pytest.raises(RuntimeStoreError, match='storage_unavailable'):
restore_local_session(cold, ref.session_id)