Copilot Chat BYOK OpenAI-Responses custom endpoint fails on 2nd turn with "previous response not found" since ~1.134: request no longer sends store:true
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
## Summary
Since VS Code **1.134** (reported after upgrading from 1.133 on another machine; reproduced locally on 1.136.1), Copilot Chat with a **custom endpoint / BYOK model using the OpenAI Responses API** (`/v1/responses`) fails on the **second turn** of every conversation with:
```
previous response not found
```
Rolling back to **1.133.0 fixes it**. Tested side-by-side on the same machine, same endpoint/key — 100% reproducible.
## Root cause (confirmed by packet capture + extension.js diff)
VS Code's built-in Copilot implements Responses-API statefulness via an opaque marker: on `response.completed` it records `statefulMarker = response.id`, stores history as `modelId\marker`, and on the next turn resolves it to `previous_response_id` while truncating local history.
The base `createRequestBody` sets `store: !zeroDataRetentionEnabled` (i.e. explicitly sends `"store": true` by default).
In 1.136.1, the **CustomEndpoint** subclass overrides `createRequestBody` and additionally does:
```js
// 1.136.1 CustomEndpoint override (minified)
useResponsesApi && zeroDataRetentionEnabled === undefined && delete n.store
```
So for custom endpoints the request **omits `store` entirely**; 1.133 sent `"store": true` explicitly.
Server-side verification (per OpenAI-Responses semantics `store` defaults to true, but our test endpoint only retains responses when `store:true` is explicit):
- request **with** `"store": true` → next request with `previous_response_id` succeeds
- request **without** `store` → next request with `previous_response_id` → `not_found`
So the regression: **1.134+ stopped sending `store:true` for custom-endpoint Responses requests while still unconditionally sending `previous_response_id` derived from the marker.** Endpoints that don't retain responses by default then hard-fail on turn 2 with `previous response not found` (that error string doesn't exist client-side — it comes from the server, consistent with the capture).
## Repro
1. VS Code 1.136.1 (reported on other 1.13x ≥ 1.134), built-in Copilot
2. Configure a BYOK / custom endpoint provider exposing the OpenAI **Responses** wire format (`/v1/responses`), e.g. an OpenAI-compatible gateway whose Responses endpoint only retains state on explicit `store:true`
3. Open Chat, select the custom model, send message 1 → succeeds
4. Send message 2 → error: `previous response not found`
Side-by-side: same steps on 1.133.0 → both turns succeed. Proxy captures of both versions differ only in the `store` field.
Capture evidence (1.136.1 run through a local forwarding proxy, key redacted):
- turn-1 request without `store` → server creates `resp_2026...7df8...`
- turn-2 request carries `previous_response_id: resp_...7df8...` → server replies
`{"error":{"code":"not_found","message":"previous_response_id 'resp_...' not found","type":"not_found"}}`
- control: request **with** `store:true` → the `previous_response_id` chain works (server returns a chained response)
## Expected behavior
Either:
- keep sending `"store": true` by default for custom endpoints (as 1.133 did), **or**
- honor the contract implied by the stateful-marker design: only send `previous_response_id` when the client actually asked the server to store, and otherwise fall back to sending full local history (the fallback already exists for when no marker is present)
## Suggested fix direction
In the CustomEndpoint `createRequestBody` override, don't `delete store` unconditionally when `zeroDataRetentionEnabled === undefined`; keep the base-class `store: !zeroDataRetentionEnabled`. (Or if the intent was ZDR-by-default, then also stop sending `previous_response_id` and send full history instead.)
## Environment
- OS: Windows 11 (10.0.26200), x64
- VS Code: 1.136.1 (fails) / 1.133.0 (works); regression appeared after upgrading past 1.133 on a second machine
- Copilot: built-in extension; custom endpoint (OpenAI-Responses wire); both streaming and non-streaming
## Related issues
- #322357 — Copilot Chat BYOK /responses appears to resend large local history after compaction (same marker/history machinery)
- #322209 — "Response contained no choices" using OpenAI Responses API BYOK model
- #320339 — Agents Window Agent Harness with BYOK Support
Contributor guide
Assessment
This issue has not been assessed yet.