bug(stdlib): react() mutates the caller's tools list when model_options carries TOOLS
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 82/100
Direzione di ricerca
La mutazione si trova in mellea/stdlib/frameworks/react.py, intorno alle righe 87-94, dove tools.extend(mo_tools) scrive nella lista del chiamante quando tools non è vuoto. Esegui lo script di riproduzione dalla issue e verifica che la lista del chiamante contenga 'f2'. Copia la lista prima dell'unione (tools = list(tools or [])), quindi eseguilo di nuovo. Il lavoro è completato quando la lista del chiamante resta invariata dopo che react() restituisce il controllo, anche quando solleva un'eccezione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.)
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 161
- Merge medio
- 4g 4h
- PR unite (30g)
- 47
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di generative-computing/mellea
-
bug(cli): intrinsic_uploader builds path_in_repo with os.path.join, producing backslashes on WindowsAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
generative-computing/mellea#1870 ·
I maintainer di solito rispondono entro 3 giorni
-
bug(backends): tool-call JSON nested under a non-first dict key is silently dropped by find_funcAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
generative-computing/mellea#1867 ·
I maintainer di solito rispondono entro 3 giorni
-
bug: `mellea.plugins.builtin_debug.generation.log_generation_post_call` shows model as unknownForse già presa @mvanhorn l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
generative-computing/mellea#1864 · 2 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
bug: instruct() and react() replay tool-call turns without tool_callsForse già presa @simonyang08 l’ha presa 22 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
generative-computing/mellea#1784 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examplesForse già presa @madhusudhan1260 l’ha presa 19 giorni fa. Apertagood first issue p2
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
generative-computing/mellea#1780 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di generative-computing/mellea
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ClickHouse/dbt-clickhouse#829 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
volcengine/OpenViking#8432 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno