Skip to content

fix(core): keep signed thinking ahead of tool calls on errored replay - #44480

Closed
Enough1122 wants to merge 1 commit into
anomalyco:v2from
Enough1122:errored-replay-thinking
Closed

fix(core): keep signed thinking ahead of tool calls on errored replay#44480
Enough1122 wants to merge 1 commit into
anomalyco:v2from
Enough1122:errored-replay-thinking

Conversation

@Enough1122

Copy link
Copy Markdown

Issue for this PR

Closes#38620

Type of change

  • Bug fix

What does this PR do?

Replaying an errored assistant message stripped its reasoning provider metadata (signature / redactedData) while still replaying the same message's tool_use parts. Anthropic requires every thinking block to precede its sibling tool_use when thinking is enabled, so any interrupted-or-failed step in a thinking + tool session made the follow-up request fail with a 400.

The reuse gate now keeps signed/redacted reasoning blocks - with their metadata - when the producing model is the replay target, even if the message carries an error. Unsigned hosted-style reasoning (OpenAI itemId/encrypted content) keeps demoting to text as before, cross-model replay is unchanged, and the existing "lowers failed assistant reasoning to text" case still passes untouched since its fixture has no signature.

How did you verify your code works?

  • new test in packages/core/test/session-runner-message.test.ts: errored same-model message with signed reasoning + a tool call lowers to reasoning(with anthropic signature) followed by tool-call, instead of demoting
  • bun test ./test/session-runner-message.test.ts -> 23 pass / 0 fail
  • bun run typecheck (packages/core): clean

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Replaying an errored assistant message stripped its reasoning provider metadata while still replaying the message's tool_use parts. Anthropic requires every thinking block to precede its sibling tool_use, so the follow-up request failed with a 400 whenever extended thinking was enabled and a step was interrupted or failed mid-tool-call.
Same-model messages now keep signed/redacted reasoning blocks (with their metadata) across errors; unsigned hosted-style reasoning keeps demoting to text, and cross-model replay is unchanged.
Fixesanomalyco#38620
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found several related PRs that address similar issues with thinking/reasoning metadata on errored replays:

Potential Related PRs:

  1. fix(core): keep reasoning provider metadata on errored turns for valid Anthropic replay #44054 - fix(core): keep reasoning provider metadata on errored turns for valid Anthropic replay

    • Directly related: handles reasoning metadata preservation on errored turns for Anthropic replay
  2. fix(core): replay thinking safely and drop unsettled tool calls from errored messages #42735 - fix(core): replay thinking safely and drop unsettled tool calls from errored messages

    • Related: addresses thinking replay safety and tool call handling from errored messages
  3. fix(core): drop tool parts when a failed turn loses its reasoning block #40157 - fix(core): drop tool parts when a failed turn loses its reasoning block

    • Related: handles tool parts when reasoning blocks are lost during failed turns
  4. fix(core): preserve reasoning metadata on errored assistant turns #38763 - fix(core): preserve reasoning metadata on errored assistant turns

  5. fix(opencode): drop truncated reasoning from replayed history #40148 - fix(opencode): drop truncated reasoning from replayed history

    • Related: handles reasoning blocks in replayed history

These PRs address overlapping concerns around preserving thinking/reasoning signatures and handling tool calls when messages have errors. PR #44054 appears most closely related as it also handles "reasoning provider metadata on errored turns for valid Anthropic replay."

@Enough1122

Copy link
Copy Markdown
Author

Closing this in favor of the four earlier PRs covering the same ground - #44054, #42735, #40157, #38763 - which the maintainers can now pick between without a fifth candidate muddying the choice. If whichever lands ends up missing regression coverage, the test added here (errored same-model message with signed reasoning + tool call keeps its thinking block ahead of tool-use) should drop in cleanly.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@Enough1122