withSandbox: each run's save drops the harness tool calls of earlier runs

オープン
#2,059 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@tombeckenham がすでに取り組んでいます。

2026年11月5日 から。

  • #2060 @adelrodriguez による — オープン

評価

この issue はまだ評価されていません。

説明

has-pr waiting-on: maintainer
TanStack AI version

@tanstack/ai-sandbox 1.1.0 and main (644a780b0). @tanstack/ai 1.1.0 and main. @tanstack/ai-persistence 1.0.1.

Framework/Library version

Server only. chat() in a Node 24 route handler. No client framework is involved.

Describe the bug and the steps to reproduce it

With withPersistence and withSandbox on one thread, run 2's save does not contain the harness tool calls of run 1. Only the tool calls of the last run survive. After a reload, every earlier run shows its text but none of its tool cards. docs/sandbox/events.md says that the tool cards come back when the user opens the thread again.

Steps:

  1. Use a harness adapter (for example claudeCodeText) with middleware: [withPersistence(persistence), withSandbox(sandbox, { instances })].
  2. Run chat() on thread t1. The harness runs one tool. The saved thread has the tool call and its result.
  3. Run chat() again on thread t1. The harness runs one more tool.
  4. Load thread t1 from the message store. Run 1's tool call and result are gone. Run 2's are there.

The middleware order does not change the result.

Suspected cause. withSandbox's onConfig returns { messages: stripObservedToolCalls(config.messages) }. Its comment says that ctx.messages keeps the recorded calls and that only the model request loses them. But applyMiddlewareConfig sets this.messages = config.messages and then middlewareCtx.messages = this.messages. So the stripped list replaces the transcript. The recorder's reconcile restores only the calls of the current run. Then withPersistence's onFinish saves ctx.messages without the earlier runs' calls.

The engine already keeps a separate list for the model request: this.providerMessages = config.providerMessages ?? config.messages.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://github.com/adelrodriguez/ai/blob/08d45e633c1ce1f58e11da8d7367279709b32166/packages/ai-sandbox/tests/middleware-tool-history.test.ts#L381-L477

The test runs two chat() runs with a fixed harness stream, withPersistence(memoryPersistence()), and withSandbox over a fake provider. It fails on main in both middleware orders:

 × a later run keeps the tool calls of earlier runs (persistence first)
 × a later run keeps the tool calls of earlier runs (sandbox first)
AssertionError: expected undefined to be defined
  expect(pairOf(messages, 'call-run-1').call).toBeDefined()
 Tests  2 failed | 14 passed (16)
Do you intend to try to help solve this bug with your own PR?

Yes, I am also opening a PR that solves the problem along side this issue

Terms & Code of Conduct
  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

🤖 Created with Claude Opus 5.5 in T3 Code

主要言語
TypeScript
スター
3.3k
フォーク
378
平均マージ
1日 2時間
マージ済み PR(30日)
254

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/ai のほかの issue

TanStack/ai の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。