fix(middleware): fall back to configurable thread_id in MemoryMiddleware (#1425)#1426
Open
ggnnggez wants to merge 2 commits intobytedance:mainfrom
Open
fix(middleware): fall back to configurable thread_id in MemoryMiddleware (#1425)#1426ggnnggez wants to merge 2 commits intobytedance:mainfrom
ggnnggez wants to merge 2 commits intobytedance:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes DeerFlow’s MemoryMiddleware.after_agent() so memory updates are still enqueued for direct LangGraph runs.wait calls where runtime.context may not include thread_id, by falling back to LangGraph config’s configurable.thread_id.
Changes:
- Import LangGraph
get_configand use it as a fallback source forthread_idwhenruntime.contextlacks it. - Keep the existing behavior of preferring
runtime.context["thread_id"]when present.
| config_data = get_config() | ||
| thread_id = config_data.get("configurable", {}).get("thread_id") | ||
| if not thread_id: | ||
| print("MemoryMiddleware: No thread_id in context, skipping memory update") |
There was a problem hiding this comment.
The skip log message is now potentially misleading: if thread_id is missing in both runtime.context and config.configurable, it still says "No thread_id in context". Consider updating the message to mention both sources (context and config.configurable) to make debugging runs.wait vs other call paths clearer.
Suggested change
| print("MemoryMiddleware: No thread_id in context, skipping memory update") | |
| print( | |
| "MemoryMiddleware: No thread_id found in runtime context or config.configurable, " | |
| "skipping memory update" | |
| ) |
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.
Summary
Fix issue #1425
Fix
MemoryMiddleware.after_agent()so memory writes are not skipped on LangGraphruns.waitcalls whenruntime.contextdoes not containthread_id.What changed
thread_idfromruntime.contextfirstconfig.configurable.thread_idwhen it is missingWhy
On direct LangGraph API
POST /threads/{thread_id}/runs/waitcalls,runtime.contextmaynot include
thread_id. In that case, the previous implementation skipped memory updatesbefore enqueue.
Verification
make devPOST /threads/{thread_id}/runs/wait:MemoryMiddleware: No thread_id in context, skipping memory updateconfig.configurable.thread_idMemoryMiddleware.after_agent()backend/.deer-flow/memory.jsonwas written successfully