feat(threads): persist and restore chat history across summarization …#3026
Open
buptwz wants to merge 2 commits into
Open
feat(threads): persist and restore chat history across summarization …#3026buptwz wants to merge 2 commits into
buptwz wants to merge 2 commits into
Conversation
…cycles Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
6d816dc to
1847ef1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2012
Related to #2424
Summary
When the agent's context window fills up,
DeerFlowSummarizationMiddlewareremovesold messages from LangGraph state. These messages were permanently lost from the UI —
users could only see the most recent portion of a long conversation.
The existing handler in
hooks.tsrelied on the internal LangGraph state keySummarizationMiddleware.before_modeland a positional index_messages[2],which are fragile and can break silently across LangGraph version changes.
This PR replaces that with a two-layer mechanism: a file archive for persistence
across page reloads, and a custom stream event for the live streaming session.
What Changed
Backend
MessageArchiveHook(BeforeSummarizationHook) that appends archived messagesto
{thread_dir}/message_archive.jsonl, deduped by message id. Registeredunconditionally alongside
memory_flush_hook.messages_archivedcustom stream event inDeerFlowSummarizationMiddlewarevia
get_stream_writer()before summary generation. Failure is swallowed sosummarization is never interrupted.
GET /api/threads/{id}/message-archiveendpoint that reads the JSONL file andreturns
{"data": [...], "has_more": false}. Returns empty list for threads thatpredate this feature.
Frontend (
hooks.ts)onUpdateEventSummarizationMiddleware block andsummarizedRef.messages_archivedinonCustomEvent: move archived messages into historyand reset
messagesRef.useThreadHistoryso full history is restored onpage reload.
Design Notes
ThreadStateor checkpointsmemory.json,same
BeforeSummarizationHookprotocol asmemory_flush_hook, samecustomstream mode already used by
task_running/llm_retryMessageArchiveHookwrites to disk before the stream event is emitted, so apage reload mid-stream will still recover the archive
Verification