pydantic ext: request_stream() never initializes the turnstile — KeyError('call_...') on first tool call of a streamed run
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- python
- Ambito
- distributed-systems
Direzione di ricerca
Inizia in restate/ext/pydantic/_model.py confrontando RestateModelWrapper.request con request_stream, quindi esamina _toolset.py e turnstile.py per seguire la ricerca che fallisce. Verifica che le risposte trasmesse inizializzino il turnstile dai relativi tool-call IDs e che un’esecuzione trasmessa con più chiamate agli strumenti termini senza il KeyError.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
In a streamed run (RestateAgent with an event_stream_handler), the first tool call fails with:
KeyError: 'call_XXXXXXXXXXXX'
raised from Turnstile.wait_for via RestateContextRunToolSet.call_tool.
Non-streamed runs (no event_stream_handler) work fine.
Environment
- restate-sdk 1.0.3 (bug also present on current
main) - pydantic-ai-slim 2.4.0
- Python 3.12, Restate server 1.7.2
Root cause
Tool executions are gated by a Turnstile built from the model response's tool-call ids so parallel tool calls run in deterministic journal order.
The non-streaming path arms it — restate/ext/pydantic/_model.py, RestateModelWrapper.request:
res = await context.run_typed("Model call", self.wrapped.request, self._options, *args, **kwargs)
ids = [c.tool_call_id for c in res.tool_calls]
current_state().turnstile = Turnstile(ids) # <- line 82
The streaming path (RestateModelWrapper.request_stream) never does this, so the state keeps the default Turnstile([]) from State.__init__. Then in _toolset.py::RestateContextRunToolSet.call_tool:
await turnstile.wait_for(id) # Turnstile.wait_for: self.events[id] -> KeyError
Reproduction
Same setup as the companion issue (agent with one tool, RestateAgent(agent, event_stream_handler=..., auto_wrap_tools=True)), with the "run event" coroutine bug patched or avoided. Any prompt that triggers a tool call raises:
File ".../restate/ext/pydantic/_toolset.py", line 92, in call_tool
await turnstile.wait_for(id)
File ".../restate/ext/turnstile.py", line 25, in wait_for
event = self.events[id]
KeyError: 'call_HtCkhcyMnGofOXHadHWA9AXS'
Suggested fix
Mirror the non-streaming path after the journaled stream step resolves (deterministic on replay since the response is recorded):
response = await context.run_typed("Model stream call", request_stream_run, self._options)
ids = [c.tool_call_id for c in response.tool_calls]
current_state().turnstile = Turnstile(ids)
yield RestateStreamedResponse(model_request_parameters, response)
We are running this exact patch as a local subclass workaround and streamed multi-tool runs (3 tool calls in one turn) complete correctly with proper Calling <tool> journal entries.
Related
- Companion issue: #222 (the two bugs stack on the same code path).
- #198 fixed a similar turnstile race in the langchain integration.
- Lingua principale
- Python
- Stelle
- 81
- Fork
- 23
- Merge medio
- 4g 2h
- PR unite (30g)
- 1
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
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 restatedev/sdk-python
-
Difficoltà 2/5 1-2 giorni Idoneità per principianti 68/100
restatedev/sdk-python#204 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
restatedev/sdk-python#225 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
restatedev/sdk-python#222 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
restatedev/sdk-python#221 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
restatedev/sdk-python#205 · 1 commento ·
Tutte le issue di restatedev/sdk-python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
mozilla/bedrock#17413 · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
-
instance instance add
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
searxng/searx-instances#943 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
bug tools
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
lance-format/lance#9655 ·
I maintainer di solito rispondono entro 2 giorni