Skip to content

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

@kas-cor

Description

@kas-cor

Problem Description

When the gateway restarts (manually via systemctl restart or crash recovery), sessions that were mid-execution are loaded but the agent doesn't continue. The agent "hangs" waiting for user input.

Scenario:

  1. User sends message: "check the latest commits"
  2. Agent starts executing tools (e.g., terminal, search_files)
  3. Gateway restarts mid-execution
  4. Session history is loaded successfully
  5. Last message in history is a tool role response
  6. Agent waits for new input instead of continuing execution
  7. User must write "continue" or use /retry to proceed

Root Cause

When history ends on a tool role message (tool response), the agent doesn't automatically continue the execution loop. The agent expects either:

  • User input to start fresh
  • An assistant message to be the last message (completed turn)

But when execution is interrupted by gateway restart, the assistant message was never written — execution stopped after the tool response.

Expected Behavior

After gateway restart, if the loaded session history ends on a tool role message, the agent should automatically continue execution as if it never stopped. This is similar to how /retry works, but should happen automatically.

Workaround

Currently users must either:

  1. Write "continue" or any message to trigger continuation
  2. Use /retry command to re-send the last user message

Proposed Solution

In gateway/run.py, after loading session history, check if the last message is a tool role. If so, automatically trigger a continuation:

# After loading history in _handle_message or similar
history = self.session_store.load_transcript(session_entry.session_id)

if history and len(history) > 0:
    last_msg = history[-1]
    if last_msg.get("role") == "tool":
        # History ends on tool response - execution was interrupted
        # Auto-continue by triggering agent with empty continuation prompt
        logger.info("Session history ends on tool response, auto-continuing execution")
        # ... trigger agent loop continuation

Alternative Solutions

  1. Add /continue command — explicit command to resume interrupted execution without re-sending the user message
  2. Persist execution state — save that agent was mid-execution, restore on startup
  3. Send system message on restart — gateway sends a "Gateway restarted, continue" system message to agent

Environment

  • Hermes Agent v0.6.0 (2026.3.30)
  • Gateway running via systemd
  • Platform: Telegram
  • Session persistence: enabled (default)

Related Code

  • gateway/run.py — session loading logic around line ~1700
  • SessionStore.load_transcript() — history loading
  • _handle_message() — where history is loaded and agent is invoked

Impact

This affects all gateway users who restart their gateway (manually or due to updates/crashes). The interruption of mid-execution tasks is a common pain point for long-running operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions