Repository navigation
Description
What happens
Content describing a call the provider ran is replayed to Anthropic as the block the API originally sent, read from rawRepresentation. rawRepresentation is not serialized, so it survives an in-memory session and nothing else.
Restore a session from persistence and replay a turn that used a provider-executed tool — code execution, bash, the text editor — and the block is gone. The hosted contents drop out of the request, and a text_editor_code_execution_tool_result, which converts to a function_result, replays as a tool_result answering a call the transcript no longer contains. The Messages API rejects that.
In-memory sessions, the default, are unaffected. This reaches anyone persisting sessions and resuming a conversation that used the code-execution beta.
Why it is filed separately
Closing it needs an outbound mapping: building the provider blocks from the typed contents rather than replaying a stored copy. That is send-side work, deliberately out of scope for the receive-side mapping that surfaced it, and it overlaps the hosted-tool declaration work tracked elsewhere.
Serializing rawRepresentation is not the answer. It is dropped everywhere in this framework on purpose — it holds arbitrary provider payloads, would bloat every persisted session, and would put unreviewed provider data into stored state.
Required implementation
- Build the Anthropic request blocks for provider-executed content from the typed contents themselves:
code_interpreter_tool_call,code_interpreter_tool_result,shell_tool_resultwith itsshell_command_output, thehosted_fileitems, and thefunction_resultthe text editor maps to. - Keep using
rawRepresentationwhen it is present — it is the exact bytes the provider sent, and reconstructing them is a fallback, not a replacement. - A restored turn must produce a request the API accepts: every
tool_resultanswers a call present in the same request, and no assistant turn loses content it had before persistence.
Acceptance criteria
- A reproduction-first test runs a code-execution turn, serializes the session, restores it, replays, and fails before the fix on the missing block.
- A restored text-editor turn produces a request whose
tool_resulthas its matching call in the same request. - A restored code-execution and bash turn carry their call, outputs and files.
- A turn still holding
rawRepresentationreplays byte-identically, unchanged from today. - Round-trip equivalence is asserted between the in-memory and the restored path for the same turn.
-
rawRepresentationis still not serialized. -
pnpm checkpasses.
Activity
Rebuild provider-executed Anthropic blocks for a restored session (#162)