fix(middleware): bridge thread_id from config.configurable to runtime.context#1145
Open
lofibrainwav wants to merge 1 commit intobytedance:mainfrom
Open
fix(middleware): bridge thread_id from config.configurable to runtime.context#1145lofibrainwav wants to merge 1 commit intobytedance:mainfrom
lofibrainwav wants to merge 1 commit intobytedance:mainfrom
Conversation
….context When running via LangGraph HTTP API, thread_id is placed in config.configurable but not injected into runtime.context. ThreadDataMiddleware.before_agent() only checked runtime.context, causing a ValueError for every HTTP API request. Changes: - Add fallback: read thread_id from get_config()["configurable"] - Add global injection: write thread_id back to runtime.context so all downstream middlewares and tools can access it uniformly
|
|
Collaborator
|
@lofibrainwav, please click the CLA button to accept the CLA first. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes LangGraph HTTP API executions failing in ThreadDataMiddleware.before_agent() by sourcing thread_id from config.configurable when it isn’t present in runtime.context, then writing it back into runtime.context for consistent downstream access.
Changes:
- Add a fallback lookup for
thread_idvialanggraph.config.get_config()["configurable"]["thread_id"]whenruntime.contextlacks it. - Inject the resolved
thread_idintoruntime.contextso subsequent middlewares/tools can rely on a single access pattern.
| config = get_config() | ||
| thread_id = config.get("configurable", {}).get("thread_id") | ||
| if thread_id is None: | ||
| raise ValueError("Thread ID is required in the context") |
Comment on lines
+75
to
+89
| if thread_id is None: | ||
| # Fallback: LangGraph HTTP API puts thread_id in config.configurable | ||
| # but does NOT inject it into runtime.context. Bridge it here once, | ||
| # so all downstream middlewares and tools can read it normally. | ||
| from langgraph.config import get_config | ||
| config = get_config() | ||
| thread_id = config.get("configurable", {}).get("thread_id") | ||
| if thread_id is None: | ||
| raise ValueError("Thread ID is required in the context") | ||
|
|
||
| # Global injection: propagate thread_id to runtime.context so every | ||
| # subsequent middleware and tool (sandbox, uploads, memory, etc.) | ||
| # can access it via runtime.context.get("thread_id"). | ||
| runtime.context["thread_id"] = thread_id | ||
|
|
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
When running via LangGraph HTTP API,
thread_idis placed inconfig.configurablebut not injected intoruntime.context.ThreadDataMiddleware.before_agent()only checkedruntime.context, causing aValueErrorfor every HTTP API request.Changes
backend/packages/harness/deerflow/agents/middlewares/thread_data_middleware.py:get_config()["configurable"]["thread_id"]whenruntime.contextdoesn't have itthread_idback toruntime.contextso all downstream middlewares and tools can access it uniformlyTest plan
make dev).deer-flow/threads/{thread_id}/ValueErroron thread_id resolution🤖 Generated with Claude Code