Repository navigation
fix(langgraph): don't rename the user's function in named tasks - #9623
Closed
manasa1508 wants to merge 1 commit into
Closed
manasa1508 wants to merge 1 commit into
manasa1508 wants to merge 1 commit into
Conversation
`task(fn, name=...)` set `fn.__name__ = name` on the user's function, so two named tasks built from the same function both ran, streamed and checkpointed under the last name, and the function was renamed for every other caller. Wrap functions and partials in a partial instead, as already done for bound methods. `__module__`/`__qualname__` are copied over, so cache keys are unchanged. Callable instances keep the existing behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 tasks done
Contributor
|
This PR has been automatically closed because you are not assigned to the linked issue. External contributors must be assigned to an issue before opening a PR for it. Please:
Maintainers: reopen this PR or remove the |
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.
Fixes #9520
task(fn, name=...)no longer setsfn.__name__on the user's function. Plain functions and partials are wrapped in afunctools.partial(as bound methods already are) and the name goes on the wrapper, so tasks that share a function keep their own names and the function itself isn't renamed. Callable instances keep the current path, because wrapping them would hide an async__call__fromis_async_callable.Notes:
update_wrappercopies__module__/__qualname__, soidentifier()and cache keys are unchanged (a cache entry written before this change is still hit)._call.CACHE, which matches the@task(name=...)decorator form today.How I verified
test_named_tasks_sharing_a_functionintest_pregel.pyandtest_pregel_async.py(the async one also covers a named async callable instance). Both fail on main and pass with the fix.make format,make lint, and the fulllibs/langgraphsuite pass, withtest_pregel.py/test_pregel_async.pyalso run underLANGGRAPH_STRICT_MSGPACK=true.