Sandbox takeover: the saved transcript loses everything the first host delivered before the restart

Abierto
#2,061 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@tombeckenham ya está trabajando en esto.

Desde el 5/11/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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. @tanstack/ai-claude-code 1.0.1.

Framework/Library version

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

Describe the bug and the steps to reproduce it

A host restarted during a 40-second Bash call. sandboxRunDriver took over the run on another host and finished it. The saved transcript has the Bash tool result and the final text, but no assistant message with the Bash tool call. The live stream was correct, because the event log already held the first part of the run.

The transcript loses more than that one call. The successor's transcript is missing every chunk that the first host delivered before the restart: assistant text, complete tool calls, and the start of a tool call that was still running. A call that was still running leaves its result as an orphan role: 'tool' message with no call.

Expected: the saved transcript after a takeover is the same as the transcript of a run that did not restart.

Steps:

  1. Use claudeCodeText with withPersistence and withSandbox(sandbox, { instances, runs, durability }).
  2. Start a run where the agent writes some text and then runs a slow tool.
  3. Stop the host while the tool runs. Let sandboxRunDriver take over the run on another host.
  4. When the run finishes, load the thread from the message store. It holds only the chunks that the successor forwarded.

Suspected cause. On an attach, the harness adapter wraps its replay in alignedIfAttaching. alignToStoredLog suppresses the prefix that the event log already holds and yields only the rest. The wrap is inside the adapter's chatStream, so the suppressed chunks never reach the engine:

  • The engine does not see the text of the prefix, so it does not add that text to the transcript.
  • withSandbox's onChunk does not see the TOOL_CALL_START, TOOL_CALL_ARGS and TOOL_CALL_END of the prefix, so the tool-history recorder writes no call. The later TOOL_CALL_RESULT arrives, and the recorder writes the result alone.

A comment in appendCall says that "a journal replay on takeover re-emits the whole stream". After alignment, that is not true.

Other effects. stripObservedToolCalls removes a result only when it also removed the result's call. So an orphan result stays in the model request of the next turn. claudeCodeText is not affected, because buildPrompt keeps only user and assistant text. I did not check the other harness adapters.

Not checked: whether withPersistence's snapshotStreaming option saves the first host's partial transcript in a form that the successor merges back.

Related: #2035 is a different takeover bug, where the reconnected client receives the rest of the run twice.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://gist.github.com/adelrodriguez/4e34cfd7224b96dfe05d554e4c0dd1e0

The test runs one chat() with withPersistence(memoryPersistence()) and withSandbox(..., { runs, durability: { adapter: fakeLog(prefix), attach: true } }). Its adapter does what claudeCodeText does: it wraps a fixed replay in alignedIfAttaching. The log already holds the chunks up to the Bash call's TOOL_CALL_END, including a first text message. Place the file in packages/ai-sandbox/tests/ and run vitest run tests/takeover-transcript.repro.test.ts in packages/ai-sandbox. Both tests fail on main:

forwarded to engine: TOOL_CALL_RESULT, TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, TEXT_MESSAGE_END, RUN_FINISHED
saved transcript:
  { "role": "user", "content": "Run the slow job" }
  { "role": "tool", "toolCallId": "bash-1", "content": "done" }
  { "role": "assistant", "content": "Finished.", ... }

 × keeps the assistant tool call, not only its result
 × keeps the text the first host streamed before the restart
AssertionError: expected 'Run the slow job done Finished.' to contain 'Starting the job.'
 Tests  2 failed (2)
Do you intend to try to help solve this bug with your own PR?

Maybe, I'll investigate and start debugging

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

Lenguaje dominante
TypeScript
Estrellas
3.3k
Forks
378
Merge medio
1 d 2 h
PR fusionados (30 d)
254

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/ai

Todos los issues de TanStack/ai

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.