Skip to content

agentHost: preserve BYOK state through tool continuations - #331749

Open
sgent-epic wants to merge 2 commits into
microsoft:mainfrom
sgent-epic:codex/fix-agent-host-stateful-marker
Open

agentHost: preserve BYOK state through tool continuations#331749
sgent-epic wants to merge 2 commits into
microsoft:mainfrom
sgent-epic:codex/fix-agent-host-stateful-marker

Conversation

@sgent-epic

Copy link
Copy Markdown

Summary

  • retain provider response IDs only while tool calls are pending
  • recover the Copilot SDK immediate tool-result replay by supplying previous_response_id and forwarding only the matching tool outputs
  • scope pending state by authenticated SDK session, vendor, and model
  • preserve explicit continuation IDs and clear recovered state after a terminal response

Why

The bundled Copilot SDK currently replays the full Responses history after a tool call and omits previous_response_id. Extension-provided stateful models then receive no stateful_marker and reject the continuation.

The integration test reproduces the SDK request shape directly. Before the proxy change, it failed because the second request replayed the message, reasoning, and tool call with no response ID. It now reaches the provider with the original response ID and only the tool output.

Fixes #329283

Testing

  • npm run compile-client
  • scripts\test.bat --run src\vs\platform\agentHost\test\node\byokLmProxyService.test.ts
  • scripts\test-integration.bat --run src\vs\platform\agentHost\test\node\providerIntegration\copilotByokResponses.integrationTest.ts
  • precommit hygiene
  • git diff --check upstream/main...HEAD

Copilot AI balanced review requested due to automatic review settings August 20, 2026 05:06

Copilot AI 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.

Pull request overview

Preserves BYOK provider state through Copilot SDK tool continuations, addressing #329283.

Changes:

  • Tracks pending response IDs by session, vendor, and model.
  • Recovers matching tool-output continuations without overriding explicit state.
  • Adds unit and SDK integration coverage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
byokLmProxyService.ts Implements continuation recovery and scoped state tracking.
byokLmProxyService.test.ts Tests recovery, scoping, explicit IDs, and cleanup.
copilotByokResponses.integrationTest.ts Verifies SDK tool continuation behavior end-to-end.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

}
}
if (calls.size) {
state.set(key, { responseId: result.responseId, calls });

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in e547f44 with a 256-entry recency cap and oldest-entry eviction. Regression coverage verifies resumable continuations are preserved.

@sgent-epic
sgent-epic force-pushed the codex/fix-agent-host-stateful-marker branch from e547f44 to 9886540 Compare August 20, 2026 14:23
@sgent-epic

Copy link
Copy Markdown
Author

Hi Vritant Bhardwaj (@vritant24), I hope you're doing well. Is there any way this could be prioritized? It's a blocker for wider piloting of agents in VS Code at Epic. I'm personally really liking the VS Code environment over other options, and I'd like to enable other folks to give it a try as well. Thanks for your time!

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.

[Agent Host BYOK] Responses reasoning continuation loses its stateful marker

3 participants