The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a failed room silence receipt no longer turns silence into an error
kshitijk4poor30071865c9cd
diff --git a/gateway/run_turn_persistence.py b/gateway/run_turn_persistence.pyindex 2adc2d9e154..05ddc14a97e 100644--- a/gateway/run_turn_persistence.py+++ b/gateway/run_turn_persistence.py@@ -78,20 +78,25 @@ class GatewayTurnPersistenceMixin:or not is_intentional_silence_response(agent_result.get("final_response"))):returnstore = self.async_session_store- entry = await store.lookup_by_session_key(session_key)- token = entry.active_turn_token if entry is not None else None- if not isinstance(token, str):- return- history = await store.load_transcript(entry.session_id)- # The agent may have saved its final before gateway session metadata was appended.- # Match recovery's visible tail rather than the literal last bookkeeping row.- last = next((m for m in reversed(history) if m.get("role") not in ("session_meta", "system")), {})- if (last.get("role") != "assistant" or last.get("timestamp") is None- or last.get("content") != agent_result.get("final_response")):- return- await store.set_session_metadata(session_key, "room_silence_decision", {- "token": token, "timestamp": last.get("timestamp"), "silent": bool(silent),- })+ try:+ entry = await store.lookup_by_session_key(session_key)+ token = entry.active_turn_token if entry is not None else None+ if not isinstance(token, str):+ return+ history = await store.load_transcript(entry.session_id)+ # The agent may have saved its final before gateway session metadata was appended.+ # Match recovery's visible tail rather than the literal last bookkeeping row.+ last = next((m for m in reversed(history) if m.get("role") not in ("session_meta", "system")), {})+ if (last.get("role") != "assistant" or last.get("timestamp") is None+ or last.get("content") != agent_result.get("final_response")):+ return+ await store.set_session_metadata(session_key, "room_silence_decision", {+ "token": token, "timestamp": last.get("timestamp"), "silent": bool(silent),+ })+ except Exception:+ # The receipt only lets crash recovery honour this silence; without it recovery keeps+ # the human-turn notice. Live delivery must stay silent rather than become an error.+ logger.warning("Could not record the room silence decision for %s", session_key, exc_info=True)async def _hmwa_shape_agent_response(self, agent_result, source, history, session_entry, session_key,diff --git a/tests/gateway/test_room_allow_silence.py b/tests/gateway/test_room_allow_silence.pyindex 6d11614b8a0..1dc18ca33bb 100644--- a/tests/gateway/test_room_allow_silence.py+++ b/tests/gateway/test_room_allow_silence.py@@ -265,3 +265,14 @@ def test_failed_room_lookup_keeps_the_reply_rule(monkeypatch, tmp_path):assert runner._room_allow_silence(source) is Noneassert runner._silence_allowed_for_source(source, None, True, {"final_response": "NO_REPLY"}) is False+++async def test_unrecordable_silence_receipt_does_not_raise_into_delivery(monkeypatch, tmp_path):+ runner = _runner(monkeypatch, tmp_path)+ runner.session_store.lookup_by_session_key.side_effect = OSError("disk full")++ await runner._record_room_silence_decision(+ "lane", {"final_response": "NO_REPLY"}, True, display_kind=None, reply_expected=True)++ runner.session_store.lookup_by_session_key.assert_called_once_with("lane")