Skip to content

fix(langgraph): don't rename the user's function in named tasks - #9623

Closed
manasa1508 wants to merge 1 commit into
langchain-ai:mainfrom
manasa1508:fix/task-name-mutates-function
Closed

manasa1508 wants to merge 1 commit into
langchain-ai:mainfrom
manasa1508:fix/task-name-mutates-function

Conversation

@manasa1508

@manasa1508 manasa1508 commented Nov 7, 2026 •

Copy link
Copy Markdown

Fixes #9520

task(fn, name=...) no longer sets fn.__name__ on the user's function. Plain functions and partials are wrapped in a functools.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__ from is_async_callable.

Notes:

  • update_wrapper copies __module__/__qualname__, so identifier() and cache keys are unchanged (a cache entry written before this change is still hit).
  • A named task built from a module-level function no longer reuses the module-level runnable cache in _call.CACHE, which matches the @task(name=...) decorator form today.
  • A thread interrupted on the old code with two named tasks sharing a function will re-run the first of them once on resume, since its task id was derived from the wrong name.
  • No JS change needed.

How I verified

  • New test_named_tasks_sharing_a_function in test_pregel.py and test_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 full libs/langgraph suite pass, with test_pregel.py/test_pregel_async.py also run under LANGGRAPH_STRICT_MSGPACK=true.

`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>
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
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:

  1. Comment on the linked issue to request assignment from a maintainer
  2. Once assigned, your PR will be reopened automatically

Maintainers: reopen this PR or remove the missing-issue-link label to bypass this check.

@github-actions github-actions Bot closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task(fn, name=...) renames the user function in place, so named tasks sharing a function all run under the last name

1 participant