Skip to content

Auto-recover stuck gateway sessions after restart #64585

Description

@OpenCodeEngineer

Summary

Add gateway startup recovery that resumes stuck chat sessions after restart, not just outbound delivery queue retries.

Problem

Current startup flow only calls recoverPendingDeliveries() in server.impl, which retries failed outbound queue items. Sessions can still be stuck when the latest turn never produced a user-visible reply (e.g., thinking-only assistant turn), leaving unanswered conversations until a user manually re-pings.

Requirements

  • Add startup recovery module under src/gateway/.
  • Scan gateway session stores and detect stuck sessions by transcript tail:
    • Last meaningful message is user (unanswered), or
    • Last meaningful message is assistant with no visible text and no tool call.
  • Replay by invoking sessions.send via existing gateway handler/context pipeline.
  • Safety:
    • Skip non-chat/internal channels (global, unknown, cron, internal).
    • Process newest first with per-startup cap (e.g. 10).
    • Log scanned/candidates/replayed/failed summary.
  • Integrate into startup flow in server.impl after request context and channel sidecars are ready.
  • Reuse existing utilities (session-utils, transcript readers, coreGatewayHandlers.sessions.send path) where possible.
  • Add unit tests for detection/selection logic.

Validation

Run focused tests for added/changed files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions