bug(stdlib): react() mutates the caller's tools list when model_options carries TOOLS
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
変異は mellea/stdlib/frameworks/react.py の 87〜94 行目付近にあり、tools が空でないとき tools.extend(mo_tools) が呼び出し元のリストに書き込みます。issue の再現スクリプトを実行し、呼び出し元のリストに 'f2' が追加されることを確認してください。マージの前にリストをコピーし(tools = list(tools or []))、そのあと再実行します。react() が戻った後、例外が発生した場合も含めて、呼び出し元のリストが変更されていなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
What happened?
react() merges model_options[ModelOption.TOOLS] into the tools argument with an in-place extend on the caller's own list:
# mellea/stdlib/frameworks/react.py:87-94
tools = tools or []
mo_tools: list[AbstractMelleaTool] | None = (
model_options.get(ModelOption.TOOLS, None)
if model_options is not None
else None
)
if mo_tools is not None:
tools.extend(mo_tools) # mutates the caller's list when `tools` was truthy
tools or [] only creates a new list when tools is falsy; a non-empty list is used by reference, so react() appends the model-options tools into whatever list the caller passed. The list stays mutated after react() returns — including when react() raises before completing.
Consequences:
- The caller's
toolslist silently gains entries it never declared. - Calling
react()repeatedly with the sametoolslist andmodel_optionsre-extends it each time (theReactInitiatortool dict dedupes by name, so the model prompt is unaffected, but the caller's list grows on every call). - A
toolslist shared across react calls or reused by other code is corrupted.
What did you expect to happen?
react() should not mutate caller-owned inputs — merge into a fresh list (e.g. tools = list(tools or [])).
How can we reproduce it?
import asyncio
from unittest.mock import Mock
from mellea import ModelOption
from mellea.stdlib.context.chat import ChatContext
from mellea.stdlib.frameworks.react import react
from mellea.backends.tools import MelleaTool
def f1(x: int) -> int: return x
def f2(x: int) -> int: return x
my_tools = [MelleaTool.from_callable(f1, "f1")]
mo = {ModelOption.TOOLS: [MelleaTool.from_callable(f2, "f2")]}
try:
asyncio.run(
react(goal="g", context=ChatContext(), backend=Mock(),
tools=my_tools, model_options=mo, loop_budget=0)
)
except RuntimeError:
pass # loop budget exhausted; mutation already happened
print([t.name for t in my_tools])
# ['f1', 'f2'] <-- expected ['f1']; react() appended to the caller's list
Mellea version
0.10.0.dev0
Any environmental details we need to know?
No backend or model needed to reproduce — the mutation runs before the first model call. Repro exits via RuntimeError (loop budget), but the same extend fires on any run where model_options[ModelOption.TOOLS] is set.
Additional context
The fix is a one-liner — copy before merging:
tools = list(tools or [])
(tools = tools or [] is only needed to satisfy the None case; the subsequent extend must not write into the caller's object.)
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 161
- 平均マージ
- 4日 4時間
- マージ済み PR(30日)
- 47
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
generative-computing/mellea のほかの issue
-
bug(cli): intrinsic_uploader builds path_in_repo with os.path.join, producing backslashes on Windowsオープン
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
generative-computing/mellea#1870 ·
メンテナーはふだん 3 日以内に返信
-
bug(backends): tool-call JSON nested under a non-first dict key is silently dropped by find_funcオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
generative-computing/mellea#1867 ·
メンテナーはふだん 3 日以内に返信
-
bug: `mellea.plugins.builtin_debug.generation.log_generation_post_call` shows model as unknown対応中かも @mvanhorn が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
generative-computing/mellea#1864 · コメント 2 件 ·
メンテナーはふだん 3 日以内に返信
-
bug: instruct() and react() replay tool-call turns without tool_calls対応中かも @simonyang08 が 22 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
generative-computing/mellea#1784 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examples対応中かも @madhusudhan1260 が 19 日前に担当しました。 オープンgood first issue p2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
generative-computing/mellea#1780 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
generative-computing/mellea の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ClickHouse/dbt-clickhouse#829 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
volcengine/OpenViking#8432 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信