pydantic ext: request_stream() never initializes the turnstile — KeyError('call_...') on first tool call of a streamed run
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- python
調査の方向性
restate/ext/pydantic/_model.py から始め、RestateModelWrapper.request と request_stream を比較し、続いて _toolset.py と turnstile.py を調べて、失敗している lookup を追跡します。ストリーミングされたレスポンスが tool-call IDs から turnstile を初期化すること、および複数のツール呼び出しを含むストリーミング実行が KeyError なしで完了することを確認します。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 82
- フォーク
- 24
- 平均マージ
- 13分
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
restatedev/sdk-python のほかの issue
-
難易度 2/5 1〜2日 初心者へのやさしさ 68/100
restatedev/sdk-python#204 · コメント 1 件 ·
-
RestateModelWrapper should not wrap `SdkInternalBaseException` as generic Exception; classify non-retryable provider errors as terminal対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
restatedev/sdk-python#225 ·
-
pydantic ext: auto_wrap_tools + async event_stream_handler crashes with 'Object of type coroutine is not JSON serializable' on first tool call対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
restatedev/sdk-python#222 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
restatedev/sdk-python#221 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
restatedev/sdk-python#205 · コメント 1 件 ·
restatedev/sdk-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Qiskit/qiskit-ibm-runtime#3431 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Lesson] A compatibility-gate rejection is a verdict, not something to overwrite with --accept-riskオープンlesson-submission needs-ac pending-review
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
Ikalus1988/MisakaNet#2870 ·
メンテナーはふだん 1 日以内に返信
-
feature:LinkChecker
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
digitalfabrik/integreat-cms#4594 ·
メンテナーはふだん 5 日以内に返信