Skip to content

A restored session cannot replay an Anthropic provider-executed turn #126

Closed

Description

@shibayan

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_result with its shell_command_output, the hosted_file items, and the function_result the text editor maps to.
  • Keep using rawRepresentation when 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_result answers 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_result has its matching call in the same request.
  • A restored code-execution and bash turn carry their call, outputs and files.
  • A turn still holding rawRepresentation replays byte-identically, unchanged from today.
  • Round-trip equivalence is asserted between the in-memory and the restored path for the same turn.
  • rawRepresentation is still not serialized.
  • pnpm check passes.

Activity

  1. added
    coreUsage: [Issues, PRs], Target: packages/core
    anthropicUsage: [Issues, PRs], Target: packages/anthropic
    on Aug 31, 2026
  2. added theissue type on Aug 31, 2026
  3. self-assigned this
    on Aug 31, 2026
  4. added a commit that references this issue on Sep 2, 2026
    2cbcddf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

anthropicUsage: [Issues, PRs], Target: packages/anthropiccoreUsage: [Issues, PRs], Target: packages/core

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions