The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): persist resume recovery notes
andyst-dev0cc26777bb8a
diff --git a/gateway/run.py b/gateway/run.pyindex 8895660879d..ad7824ffc37 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -1228,6 +1228,24 @@ def build_resume_recovery_note()+def _prepare_resume_pending_message(+ reason: Optional[str],+ message: Optional[str],+ *,+ interactive: bool = True,+) -> tuple[str, str]:+ """Return the recovery message and the identical persisted user text.++ Resume turns replace the empty startup event with a recovery note before+ entering the agent. Persist that note too, rather than the original empty+ event, so the durable transcript matches what the model received.+ """+ recovery_message = build_resume_recovery_note(+ reason, message or "", interactive=interactive,+ )+ return recovery_message, recovery_message++# Assistant-message fields that must survive transcript replay so multi-turn# reasoning context, prefix-cache hits, and provider-specific echo# requirements all behave the same on the gateway as they do in the CLI.@@ -6121,7 +6139,6 @@ class TurnRunner:if _is_resume_pending:_reason = getattr(_resume_entry, "resume_reason", None) or "restart_timeout"- _persist_user_message_override = ctx.message# The empty-message case is the auto-resume startup turn# synthesized by _schedule_resume_pending_sessions — there is# no NEW user message to address. Guidance is adapter-aware:@@ -6134,7 +6151,7 @@ class TurnRunner:_interactive_resume = bool(getattr(_resume_adapter, "interactive_resume", True))- ctx.message = build_resume_recovery_note(+ ctx.message, _persist_user_message_override = _prepare_resume_pending_message(_reason, ctx.message, interactive=_interactive_resume,)elif _has_fresh_tool_tail:diff --git a/tests/gateway/test_restart_resume_pending.py b/tests/gateway/test_restart_resume_pending.pyindex 1acc357e16f..2f602faa21b 100644--- a/tests/gateway/test_restart_resume_pending.py+++ b/tests/gateway/test_restart_resume_pending.py@@ -40,6 +40,7 @@ from gateway.run import (_coerce_gateway_timestamp,_is_fresh_gateway_interruption,_last_transcript_timestamp,+ _prepare_resume_pending_message,_should_clear_resume_pending_after_turn,build_resume_recovery_note,)@@ -314,6 +315,18 @@ class TestResumePendingSystemNote:assert "already appear in the history" in note+ def test_resume_note_is_persisted_instead_of_original_empty_message(self):+ """The auto-resume note must not leave an empty row in state.db."""+ message, persisted = _prepare_resume_pending_message(+ "restart_timeout", "", interactive=False+ )++ assert message+ assert "CONTINUE the interrupted task" in message+ assert persisted == message+ assert persisted != ""++def test_resume_pending_fires_without_tool_tail(self):"""Key improvement over PR #9934: the restart-resume note fireseven when the transcript's last role is NOT ``tool``."""