# NousResearch/hermes-agent · Auto-continue agent execution after gateway restart

## Open now

- Nothing open on GitHub.

These members address a feature or fix enabling agents to automatically resume interrupted work when a gateway restarts and conversation history ends on a tool response.

## TL;DR

- 3 member(s): 0 open issue(s), 1 closed issue(s), 0 open PR(s), 1 merged PR(s), 1 PR(s) closed without merging.
- A fix was merged to main in PR #9934. Verify it addresses your case.
- **Recommended:** read PR #9934 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `resolved` · deciding PR(s): `pr-9934`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_SPANNING`): every member is connected by structural evidence: shared changed files, or a closing/superseded reference.
- Pairwise link density `0.67`: the share of member pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. `1.00` means every pair is linked.

## Closed / duplicate issues

- #4493: \[Enhancement\] Auto-continue execution after gateway restart when history ends on tool response

## Prior & competing PRs

- **#4509: fix(gateway): auto-continue execution when history ends on tool response after restart**. closed without merge · fix tier `suggested`
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `e7475b158`, `#4493`
  - _suggested-tier fix detail withheld; re-request with `?tier=all` to include it._
- **#9934: feat: auto-continue interrupted agent work after gateway restart (#4493)**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`
  - files: `gateway/run.py`, `tests/gateway/test_auto_continue.py`, `tests/gateway/test_restart_drain.py`
  - fix hunks:
  - `gateway/run.py`

    ```diff
    @@ -1405,7 +1405,7 @@ async def _notify_active_sessions_of_shutdown(self) -> None:
             action = "restarting" if self._restart_requested else "shutting down"
             hint = (
                 "Your current task will be interrupted. "
    -            "Use /retry after restart to continue."
    +            "Send any message after restart to resume where it left off."
                 if self._restart_requested
                 else "Your current task will be interrupted."
             )
    ```

    ```diff
    @@ -8450,6 +8450,21 @@ def _approval_notify_sync(approval_data: dict) -> None:
                 if _msn:
                     message = _msn + "\n\n" + message
     
    +            # Auto-continue: if the loaded history ends with a tool result,
    +            # the previous agent turn was interrupted mid-work (gateway
    +            # restart, crash, SIGTERM).  Prepend a system note so the model
    +            # finishes processing the pending tool results before addressing
    +            # the user's new message.  (#4493)
    +            if agent_history and agent_history[-1].get("role") == "tool":
    +                message = (
    +                    "[System note: Your previous turn was interrupted before you could "
    +                    "process the last tool result(s). The conversation history contains "
    +                    "tool outputs you haven't responded to yet. Please finish processing "
    +                    "those results and summarize what was accomplished, then address the "
    +                    "user's new message below.]\n\n"
    +                    + message
    +                )
    +
                 _approval_session_key = session_key or ""
                 _approval_session_token = [redacted:secret-assignment]
                 register_gateway_notify(_approval_session_key, _approval_notify_sync)
    ```
  - `tests/gateway/test_auto_continue.py`

    ```diff
    @@ -0,0 +1,95 @@
    +"""Tests for the auto-continue feature (#4493).
    +
    +When the gateway restarts mid-agent-work, the session transcript ends on a
    +tool result that the agent never processed.  The auto-continue logic detects
    +this and prepends a system note to the next user message so the model
    +finishes the interrupted work before addressing the new input.
    +"""
    +
    +import pytest
    +
    +
    +def _simulate_auto_continue(agent_history: list, user_message: str) -> str:
    +    """Reproduce the auto-continue injection logic from _run_agent().
    +
    +    This mirrors the exact code in gateway/run.py so we can test the
    +    detection and message transformation without spinning up a full
    +    gateway runner.
    +    """
    +    message = user_message
    +    if agent_history and agent_history[-1].get("role") == "tool":
    +        message = (
    +            "[System note: Your previous turn was interrupted before you could "
    +            "process the last tool result(s). The conversation history contains "
    +            "tool outputs you haven't responded to yet. Please finish processing "
    +            "those results and summarize what was accomplished, then address the "
    +            "user's new message below.]\n\n"
    +            + message
    +        )
    +    return message
    +
    +
    +class TestAutoDetection:
    +    """Test that trailing tool results are correctly detected."""
    +
    +    def test_trailing_tool_result_triggers_note(self):
    +        history = [
    +            {"role": "user", "content": "deploy the app"},
    +            {"role": "assistant", "content": None, "tool_calls": [
    +                {"id": "call_1", "function": {"name": "terminal", "arguments": "{}"}}
    +            ]},
    +            {"role": "tool", "tool_call_id": "call_1", "content": "deployed successfully"},
    +        ]
    +        result = _simulate_auto_continue(history, "what happened?")
    +        assert "[System note:" in result
    +        assert "interrupted" in result
    +        assert "what happened?" in result
    +
    +    def test_trailing_assistant_message_no_note(self):
    +        history = [
    +            {"role": "user", "content": "hello"},
    +            {"role": "assistant", "content": "Hi there!"},
    +        ]
    +        result = _simulate_auto_continue(history, "how are you?")
    +        assert "[System note:" not in result
    +        assert result == "how are you?"
    +
    +    def test_empty_history_no_note(self):
    +        result = _simulate_auto_continue([], "hello")
    +        assert result == "hello"
    +
    +    def test_trailing_user_message_no_note(self):
    +        """Shouldn't happen in practice, but ensure no false positive."""
    +        history = [
    +            {"role": "user", "content": "hello"},
    +        ]
    +        result = _simulate_auto_continue(history, "hello again")
    +        assert result == "hello again"
    +
    +    def test_multiple_tool_results_still_triggers(self):
    +        """Multiple tool calls in a row — last one is still role=tool."""
    +        history = [
    +            {"role": "user", "content": "search and read"},
    +            {"role": "assistant", "content": None, "tool_calls": [
    +                {"id": "call_1", "function": {"name": "search", "arguments": "{}"}},
    +                {"id": "call_2", "function": {"name": "read", "arguments": "{}"}},
    +            ]},
    +            {"role": "tool", "tool_call_id": "call_1", "content": "found it"},
    +            {"role": "tool", "tool_call_id": "call_2", "content": "file content here"},
    +        ]
    +        result = _simulate_auto_continue(history, "continue")
    +        assert "[System note:" in result
    +
    +    def test_original_message_preserved_after_note(self):
    +        """The user's actual message must appear after the system note."""
    +        history = [
    +            {"role": "assistant", "content": None, "tool_calls": [
    +                {"id": "c1", "function": {"name": "t", "arguments": "{}"}}
    +            ]},
    +            {"role": "tool", "tool_call_id": "c1", "content": "done"},
    +        ]
    +        result = _simulate_auto_continue(history, "now do X")
    +        # System note comes first, then user's message
    +        note_end = result.index("]\n\n")
    +        user_msg_start = result.index("now do X")
    +        assert user_msg_start > note_end
    ```
  - `tests/gateway/test_restart_drain.py`

    ```diff
    @@ -193,7 +193,7 @@ async def test_shutdown_notification_says_restarting_when_restart_requested():
     
         assert len(adapter.sent) == 1
         assert "restarting" in adapter.sent[0]
    -    assert "/retry" in adapter.sent[0]
    +    assert "resume" in adapter.sent[0]
     
     
     @pytest.mark.asyncio
    ```

## Fix status

- Merged to main in PR #9934 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-04-14`. This confirmation is old and may be out of date (a revert/reopen would not have invalidated it here); re-verify.
- Subsystem: `gateway`
