Skip to content

fix(core): replay hosted tool results across providers - #57045

Open
abigfatstone wants to merge 1 commit into
anomalyco:devfrom
abigfatstone:cross-provider-tools
Open

abigfatstone wants to merge 1 commit into
anomalyco:devfrom
abigfatstone:cross-provider-tools

Conversation

@abigfatstone

@abigfatstone abigfatstone commented Oct 19, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #57044

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When replaying an assistant message against a different provider, treat its provider-executed tools as ordinary calls with separate tool results. OpenAI Chat can then compile the history instead of rejecting inline tool-result parts.

Normalization only affects request history. Stored messages and same-provider native replay stay unchanged.

How did you verify your code works?

The new regression failed before the fix with the reported OpenAI Chat compilation error. After the fix, core session-runner-message, session-model-request and session-provider-context tests pass: 47 tests. The message suite also passed 10 repetitions. Covers successful and failed results, mixed local/hosted tools, metadata stripping and switching back without history mutation.

Formatting and changed-file lint passed. Full repository check is not green locally: the sparse checkout lacks development dependencies including drizzle-kit; full typecheck was blocked by missing modules. No live provider call or packaged runtime test.

Screenshots / recordings

No UI changes.

Checklist

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

Added by the opencode bot (AI-generated).

Related: #53633, #55271

@github-actions

Copy link
Copy Markdown
Contributor

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

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks correct and is in the right place. The new regression test fails on the base with the OpenAI Chat compile error from #57044 and passes with this PR. The three core suites pass (47 tests) and the packages/core type check is clean. I couldn't run it end to end because there was no provider that runs tools itself.

Public API: unchanged. The change only affects how stored session history is turned into request messages; stored messages are not changed.

One concern, inline: the fix only applies when the provider changes. A model switch within one provider whose models use different protocols probably still fails the same way.

Related: #53633, #55271

// A different provider needs ordinary tool messages, not the original provider's
// inline hosted results. Normalize only this replay, preserving stored history.
const parts = message.content.map((item) =>
item.type === "tool" && item.executed === true && !sameProvider ? { ...item, executed: false } : item,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only rewrites provider-executed tools when the provider changes. Some providers send different models through different protocols. GitHub Copilot, for example, sends some models through Responses and others through Chat. Switching between such models keeps sameProvider true, so provider-executed results stay inline and OpenAI Chat should reject them with the same error. I haven't confirmed Copilot can actually record provider-executed tools, but nothing here guards against it. Could the condition be based on whether the target model can replay the call natively (same model, or at least same protocol) instead of on the provider ID? If the provider check is intentional, could you say so in the comment so the limitation is known?

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provider switch fails to compile history containing provider-executed tool results

1 participant