Skip to content

[Bug]: Gateway restart drops session memory — shutdown_memory_provider receives empty messages #15165

@jlin53882

Description

@jlin53882

Bug Description

When a gateway session ends (e.g. gateway process restart, Discord bot reconnection, idle timeout), the conversation history is not preserved in the Hindsight memory system. After the session restarts, the agent responds with "抱歉,找不到相關的對話記錄" even though the previous conversation was active.

This is not the same as the /new or /reset bug fixed in #7759. That issue was about /new and /reset not triggering memory provider shutdown. This issue is about the gateway restart path specifically — which does call shutdown_memory_provider(), but passes an empty list.

Root Cause Analysis

Two compounding problems:

1. shutdown_memory_provider() is called without session messages

In gateway/run.py (main, line 1767–1768):

if hasattr(agent, "shutdown_memory_provider"):
    agent.shutdown_memory_provider()   # ← no messages passed

The method signature in run_agent.py (line 3959):

def shutdown_memory_provider(self, messages: list = None) -> None:

Because no messages are passed, on_session_end([]) is called on all memory providers, and any provider that tries to extract facts from the session's conversation gets an empty list. Providers like Holographic (on_session_end([])) have an early return guard:

if not messages:
    return

2. Hindsight has no on_session_end or on_pre_compress hook

The Hindsight plugin (plugins/memory/hindsight/) only implements:

  • arecall — injects memories when a session starts
  • No on_session_end hook
  • No on_pre_compress hook

This means even if messages were passed correctly, Hindsight would still not save anything at session end. The only way Hindsight retains content is via the retain tool — which requires the agent to explicitly call it.

Impact

Expected Behavior

When a gateway session ends, the memory provider should:

  1. Receive the full session message list via on_session_end(messages)
  2. Extract key facts and save them to Hindsight
  3. On next session start, arecall should surface relevant memories

Suggested Fix (two parts)

Part A — Pass messages to shutdown_memory_provider

In gateway/run.py, change:

agent.shutdown_memory_provider()

to:

agent.shutdown_memory_provider(conversation_messages)

This requires tracking conversation_messages in the gateway session context and passing it at shutdown time.

Part B — Implement on_session_end in Hindsight plugin

The Hindsight plugin should implement on_session_end(messages) (and optionally on_pre_compress) to extract and retain key facts from the session before it is discarded.

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundcomp/agentCore agent loop, run_agent.py, prompt buildercomp/gatewayGateway runner, session dispatch, deliverycomp/pluginsPlugin system and bundled pluginstool/memoryMemory tool and memory providerstype/bugSomething isn't working

    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