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

未关闭
#2,059 0 条评论 0 个 reaction 已指派 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 小时
30 天内合并 PR
254

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/ai 的其他 Issue

查看 TanStack/ai 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。