fix(core): stop replaying stale GitHub Copilot Responses item IDs (#34686)

This commit is contained in:
Aiden Cline 2026-06-30 19:19:02 -05:00 committed by GitHub
commit f1407e41c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 310 additions and 26 deletions

View file

@ -463,7 +463,9 @@ export function message(msgs: ModelMessage[], model: Provider.Model, options: Re
if (
options.store !== true &&
key &&
["@ai-sdk/openai", "@ai-sdk/azure", "@ai-sdk/amazon-bedrock/mantle"].includes(model.api.npm)
["@ai-sdk/openai", "@ai-sdk/azure", "@ai-sdk/amazon-bedrock/mantle", "@ai-sdk/github-copilot"].includes(
model.api.npm,
)
) {
msgs = mapProviderOptions(msgs, (options) => {
if (!options?.[key] || !("itemId" in options[key])) return options

View file

@ -2268,6 +2268,82 @@ describe("ProviderTransform.message - strip openai metadata when store=false", (
expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
})
test("strips GitHub Copilot itemId from the copilot namespace, preserving other copilot options", () => {
const copilotModel = {
...openaiModel,
id: "github-copilot/gpt-5.5",
providerID: "github-copilot",
api: {
id: "gpt-5.5",
url: "https://api.githubcopilot.com",
npm: "@ai-sdk/github-copilot",
},
}
const msgs = [
{
role: "assistant",
content: [
{
type: "reasoning",
text: "thinking...",
providerOptions: {
copilot: { itemId: "rs_123", reasoningEncryptedContent: "encrypted" },
},
},
{
// The stale itemId on tool-call parts is what Copilot echoes back as the
// `function_call` item `id`, which is what the upstream connection rejects.
type: "tool-call",
toolCallId: "call_1",
toolName: "bash",
input: { command: "ls" },
providerOptions: {
copilot: { itemId: "fc_456", reasoningEffort: "medium" },
},
},
],
},
] as any[]
const result = ProviderTransform.message(msgs, copilotModel, { store: false }) as any[]
expect(result[0].content[0].providerOptions?.copilot?.itemId).toBeUndefined()
expect(result[0].content[0].providerOptions?.copilot?.reasoningEncryptedContent).toBe("encrypted")
expect(result[0].content[1].providerOptions?.copilot?.itemId).toBeUndefined()
expect(result[0].content[1].providerOptions?.copilot?.reasoningEffort).toBe("medium")
})
test("leaves a stray openai namespace on a Copilot model untouched, since Copilot's Responses model only reads the copilot namespace", () => {
const copilotModel = {
...openaiModel,
id: "github-copilot/gpt-5.5",
providerID: "github-copilot",
api: {
id: "gpt-5.5",
url: "https://api.githubcopilot.com",
npm: "@ai-sdk/github-copilot",
},
}
const msgs = [
{
role: "assistant",
content: [
{
type: "text",
text: "Hello",
providerOptions: {
openai: { itemId: "msg_456" },
},
},
],
},
] as any[]
const result = ProviderTransform.message(msgs, copilotModel, { store: false }) as any[]
expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_456")
})
test("preserves metadata for openai package when store is true", () => {
const msgs = [
{