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:
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:
- Receive the full session message list via
on_session_end(messages)
- Extract key facts and save them to Hindsight
- 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
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
/newor/resetbug fixed in #7759. That issue was about/newand/resetnot triggering memory provider shutdown. This issue is about the gateway restart path specifically — which does callshutdown_memory_provider(), but passes an empty list.Root Cause Analysis
Two compounding problems:
1.
shutdown_memory_provider()is called without session messagesIn
gateway/run.py(main, line 1767–1768):The method signature in
run_agent.py(line 3959):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:2. Hindsight has no
on_session_endoron_pre_compresshookThe Hindsight plugin (
plugins/memory/hindsight/) only implements:arecall— injects memories when a session startson_session_endhookon_pre_compresshookThis 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
retaintool — which requires the agent to explicitly call it.Impact
on_pre_compress) is session-local and is not written to Hindsighton_session_finalizehook (mentioned in docs) is also not fired on idle timeout ([Bug]: The on_session_finalize hook is not being fired when gateway sessions expire due to configured idle time. #14981)Expected Behavior
When a gateway session ends, the memory provider should:
on_session_end(messages)arecallshould surface relevant memoriesSuggested Fix (two parts)
Part A — Pass messages to
shutdown_memory_providerIn
gateway/run.py, change:to:
This requires tracking
conversation_messagesin the gateway session context and passing it at shutdown time.Part B — Implement
on_session_endin Hindsight pluginThe Hindsight plugin should implement
on_session_end(messages)(and optionallyon_pre_compress) to extract and retain key facts from the session before it is discarded.Related Issues
/newand/resetdon't trigger memory commit — fixed by e964cfcon_session_finalizehook not fired on idle timeout