The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): no restart notice on a recovered automation answer
Teknium401abcca7e0f
diff --git a/gateway/session_authority.py b/gateway/session_authority.pyindex 3a8977465d9..a2494eaa8ca 100644--- a/gateway/session_authority.py+++ b/gateway/session_authority.py@@ -808,7 +808,10 @@ class SessionAuthority:return await tracked_write(self, partial(resolve_unknown_session_input, self.db, epoch=self.epoch, admission_id=admission_id,generation=generation, _captured=prepared,- _terminal_write=lambda conn, lost: close_discarded_turn(self.db, conn, lost, notice)),+ # ``notice`` says the turn was interrupted: only when that is the outcome, never beside a+ # captured result this resolution commits as the turn's own answer.+ _terminal_write=lambda conn, lost: close_discarded_turn(self.db, conn, lost, None if (+ prepared is not None and lost['owner_epoch'] == self.epoch) else notice)),then=partial(self._resolved_unknown, ref, admission_id, prepared, captured))async def _resolved_unknown(self, ref, admission_id, prepared, captured, row):diff --git a/tests/gateway/test_unknown_automation_settles.py b/tests/gateway/test_unknown_automation_settles.pyindex 7fa90607d7f..204cb6a04a7 100644--- a/tests/gateway/test_unknown_automation_settles.py+++ b/tests/gateway/test_unknown_automation_settles.py@@ -180,3 +180,34 @@ async def test_messaging_pause_notice_names_discard_and_discard_resumes_the_fifoassert 'nothing' in (await discard_lost_turns(authority, 's')).lower()finally:store.close_all_db_handles()+++async def test_captured_completed_automation_result_gets_no_restart_notice(tmp_path, monkeypatch):+ """Review #141357 F6: an automation turn fenced ``unknown`` only because its settlement write+ failed, while this owner holds its completed result, commits that result as completed. Its+ transcript must not also claim the turn was interrupted by a restart."""+ from gateway.session_results import admission_result+ from gateway.session_settlement_recovery import recover_failed_settlement+ from gateway.session_unattended_unknown import settle_unattended_unknown+ store, runner = _runner(tmp_path, monkeypatch, [])+ db = store._db+ db.create_session('s', source='telegram')+ authority = await initialize_session_authority(runner, profile_id='p', instance_id='owner-1')+ authority.sessions['s'] = LiveSession(SessionSource(platform=Platform.TELEGRAM, chat_id='gw10'), 's')+ authority._schedule = lambda ref: None+ try:+ admit_session_input(db, epoch=authority.epoch, principal_id='automation:probe', session_id='s',+ request_id='done', payload={'text': 'done'})+ row = claim_session_input(db, epoch=authority.epoch, session_id='s')+ db.append_message('s', 'user', 'done')+ db.append_message('s', 'assistant', 'REAL_FINISHED_ANSWER')+ authority.pending_results[row['admission_id']] = {'result': {+ 'final_response': 'REAL_FINISHED_ANSWER', 'completed': True, 'messages': []}, 'usage': {}}+ await recover_failed_settlement(authority, row)+ assert await settle_unattended_unknown(authority, SessionRef('p', 's'))+ assert _statuses(db)[row['admission_id']] == ('terminal', 'completed')+ assert admission_result(db, row['admission_id'])['result']['final_response'] == 'REAL_FINISHED_ANSWER'+ assert not [m for m in db.get_messages('s') if m.get('display_kind') == 'failed_turn']+ finally:+ store.close_all_db_handles()