fix: handle runtime.context being None in ThreadDataMiddleware and related middlewares#1825
Open
highland0971 wants to merge 1 commit intobytedance:mainfrom
Open
Conversation
Problem: ThreadDataMiddleware.before_agent() assumes runtime.context is always set and contains thread_id. However, runtime.context defaults to None when no custom context is provided, causing AttributeError when accessing runtime.context.get(). Root Cause: In LangGraph API, runtime.context is user-defined static context and defaults to None. The actual thread_id is stored in config.configurable under the key thread_id (CONFIG_KEY_THREAD_ID). Solution: 1. Check if runtime.context is not None before accessing 2. Fallback to get_config() to retrieve thread_id from config.configurable 3. Provide clear error message if thread_id is not found in either location Testing: - Verified with curl request to LangGraph API - thread_data paths are correctly generated - AI agent responds normally Co-authored-by: 多慧 <duohui@openclaw.ai>
|
root seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Collaborator
|
@highland0971, thanks for your contribution. Please click the CLA assistant button to sign the CLA and change the Chinese comments into English. There are some conflicts that need to be resolved. |
Author
CLA assistant button,在哪里点击?我在Github上有自己的邮箱,PR是通过OpenClaw来提交,有啥需要特别处理的吗? |
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.
Problem
When
runtime.contextisNone(user-defined static context is empty), several middlewares throw errors:ThreadDataMiddleware:AttributeError: NoneType object has no attribute getuploads_middleware:_get_context_valueinfinite recursionloop_detection_middleware: similar None check missingSolution
get_config()whenruntime.contextis None_get_context_valueruntime.contextTesting
Files Changed
backend/packages/harness/deerflow/agents/middlewares/thread_data_middleware.pybackend/packages/harness/deerflow/agents/middlewares/uploads_middleware.pybackend/packages/harness/deerflow/agents/middlewares/loop_detection_middleware.py