The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): carry response_reused on the authority's message.complete
Teknium03e40cf1bd2a
diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.pyindex 98b5a3ec611..65110d9fd81 100644--- a/gateway/run_turn_runner.py+++ b/gateway/run_turn_runner.py@@ -1185,6 +1185,7 @@ class TurnRunner(GatewayTurnProgressMixin, GatewaySessionAgentMixin):"final_response": final_response, "last_reasoning": result.get("last_reasoning"), **common,"response_previewed": result.get("response_previewed", False),"response_transformed": result.get("response_transformed", False),+ "response_reused": result.get("response_reused", False),# Lets the persistence block tell whether the codex app-server path self-persisted (it# didn't — see codex_runtime.py); default True keeps skip-db for the standard runtime."agent_persisted": result.get("agent_persisted", True),diff --git a/gateway/session_authority.py b/gateway/session_authority.pyindex 6f37bb4cb81..245bb518796 100644--- a/gateway/session_authority.py+++ b/gateway/session_authority.py@@ -517,20 +517,25 @@ class SessionAuthority:try:with live.event_stream.lock:from gateway.session_results import finish_result+ captured = self.pending_results.pop(admission_id, None)settled, response = finish_result(self.db, epoch=self.epoch, row=row,- response=response, outcome=outcome,- result=self.pending_results.pop(admission_id, None))+ response=response, outcome=outcome, result=captured)live.controls.snapshot(ref.session_id, None)from gateway.session_ingress_media import release_admission_mediarelease_admission_media(self.db, admission_id)self._publish_pending(ref)# ``status`` is the message.complete contract's TurnStatus: the Desktop# extends a Stopped bubble to the persisted partial only on 'interrupted'.- live.event_stream.publish(ref.session_id, {+ complete = {'text': response, 'content': response, 'admission_id': admission_id,'outcome': 'cancelled' if settled['outcome'] == 'interrupted' else settled['outcome'],'status': {'completed': 'complete', 'interrupted': 'interrupted'}.get(- settled['outcome'], 'error')})+ settled['outcome'], 'error')}+ # Only the agent's reuse site sets this (never inferred from equal text): the+ # final repeats a reply the viewer already painted, so it settles in place.+ if response and ((captured or {}).get('result') or {}).get('response_reused'):+ complete['response_reused'] = True+ live.event_stream.publish(ref.session_id, complete)except Exception:# The settle fence lost (a reset/compression moved runtime_generation under# the turn). The row stays `started` for recovery -> `unknown`; re-settlingdiff --git a/tests/gateway/test_authority_complete_reused_final.py b/tests/gateway/test_authority_complete_reused_final.pynew file mode 100644index 00000000000..ea4369467ce--- /dev/null+++ b/tests/gateway/test_authority_complete_reused_final.py@@ -0,0 +1,49 @@+"""A reused final keeps main's message.complete contract through the session authority.++The agent marks a final that repeats text the turn already delivered (``response_reused``);+the Desktop settles it in place instead of appending it after the bubble's last tool row.+"""+import asyncio+from types import SimpleNamespace++import pytest++from gateway.session_authority import LiveSession, SessionAuthority+from gateway.session_contract import Principal, SessionRef, Submission+from hermes_state import SessionDB+from hermes_state_runtime import begin_runtime_epoch++ACTOR = Principal('human', 'owned', frozenset({'session:submit', 'session:control'}), 'cli')+REF = SessionRef('owned', 's')++[email protected]('reused', [True, False])+async def test_completion_carries_the_reused_final_flag(tmp_path, monkeypatch, reused):+ from gateway import session_finite+ monkeypatch.setenv('HERMES_HOME', str(tmp_path))+ db = SessionDB(db_path=tmp_path / 'state.db')+ db.create_session('s', source='test')+ epoch = begin_runtime_epoch(db, instance_id='current')+ runner = SimpleNamespace(_draining=False, config=SimpleNamespace(multiplex_profiles=False),+ _adapter_for_source=lambda source: None)+ authority = SessionAuthority(runner, profile_id='owned', instance_id='current', db=db, epoch=epoch)+ authority.sessions['s'] = LiveSession(SimpleNamespace(platform=None, user_id='human'), 'route')+ frames = []+ authority.sessions['s'].event_stream.observers.add(frames.append)++ async def execute(authority, ref, row):+ authority.pending_results[row['admission_id']] = {'result': {+ 'final_response': 'answered', 'messages': [], 'response_reused': reused,+ 'response_transformed': False}, 'usage': {}}+ return 'answered'+ monkeypatch.setattr(session_finite, 'execute_finite_admission', execute)++ with db:+ await authority.submit(ACTOR, Submission(request_id='r', ref=REF, payload={'text': 'q'}, intent='queue'))+ await asyncio.wait_for(authority.sessions['s'].task, 5)++ [complete] = [f['params']['payload'] for f in frames if f['params']['type'] == 'message.complete']+ assert complete['text'] == 'answered'+ assert complete.get('response_reused', False) is reused+