bug(stdlib): react() mutates the caller's tools list when model_options carries TOOLS
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Đột biến nằm trong mellea/stdlib/frameworks/react.py, quanh các dòng 87-94, nơi tools.extend(mo_tools) ghi vào danh sách của bên gọi khi tools không rỗng. Chạy script tái hiện từ issue và xác nhận danh sách của bên gọi có thêm 'f2'. Sao chép danh sách trước khi gộp (tools = list(tools or [])), rồi chạy lại. Hoàn thành khi danh sách của bên gọi không thay đổi sau khi react() trả về, kể cả khi nó ném ngoại lệ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.)
- Ngôn ngữ chính
- Python
- Star
- 1.8k
- Fork
- 161
- Merge trung bình
- 4 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 47
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của generative-computing/mellea
-
bug(cli): intrinsic_uploader builds path_in_repo with os.path.join, producing backslashes on WindowsĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
generative-computing/mellea#1870 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug(backends): tool-call JSON nested under a non-first dict key is silently dropped by find_funcĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
generative-computing/mellea#1867 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug: `mellea.plugins.builtin_debug.generation.log_generation_post_call` shows model as unknownCó thể đã có người làm @mvanhorn đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
generative-computing/mellea#1864 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug: instruct() and react() replay tool-call turns without tool_callsCó thể đã có người làm @simonyang08 đã nhận 22 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
generative-computing/mellea#1784 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examplesCó thể đã có người làm @madhusudhan1260 đã nhận 19 ngày trước. Đang mởgood first issue p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
generative-computing/mellea#1780 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của generative-computing/mellea
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ClickHouse/dbt-clickhouse#829 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
volcengine/OpenViking#8432 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày