Implement the following plan: Fix: GitHub Copilot provider — Responses API support for…
- User
Implement the following plan:
Fix: GitHub Copilot provider — Responses API support for gpt-5.4+
Context
GitHub Copilot provider (
crates/providers/src/github_copilot.rs) hardcodes/chat/completionsfor all models. Newer OpenAI models (gpt-5.4, gpt-5.4-pro, gpt-5.2-pro) only support the Responses API (/responses), returning HTTP 400 withunsupported_api_for_model. See issue #392.The OpenAI provider already has Responses API support via WebSocket, but that's gated behind
api.openai.comdomain checks. The Copilot provider needs its own Responses API path using HTTP+SSE (simpler, no WebSocket pool needed).Approach
Model-based routing with error-based fallback: dispatch to
/responsesfor known models, and detectunsupported_api_for_modelerrors for unknown future models.Files to modify
1.
crates/providers/src/openai_compat.rs— shared utilities-
Move
split_responses_instructions_and_input()fromOpenAiProviderimpl to a free function here. It has noselfdependency — just splits system messages intoinstructionsand passes the rest throughto_responses_input(). -
Add
responses_output_index()— extracted fromws_output_index()inopenai.rs(resolvesoutput_index/item_index/indexfrom a Responses API event). Both providers can share it. -
Add
process_responses_sse_line()— new function that processes a single SSEdata:line from a Responses API stream. ReturnsSseLineResult(reusing existing enum). Handles event types:response.output_text.delta→StreamEvent::Deltaresponse.output_item.added(type=function_call) →StreamEvent::ToolCallStartresponse.function_call_arguments.delta→StreamEvent::ToolCallArgumentsDeltaresponse.function_call_arguments.done→StreamEvent::ToolCallCompleteresponse.completed→ parse usage, returnSseLineResult::Doneerror/response.failed→
-
Assistant
I'll start by reading the key files to understand the current code structure.
Assistant
Let me read the full openai_compat.rs and the relevant parts of openai.rs.
Assistant
Now I have a thorough understanding of all the code. Let me create tasks and start implementing.
Assistant
Starting with task 1: adding shared Responses API utilities to
openai_compat.rs.First, let me add
split_responses_instructions_and_inputas a free function,responses_output_index,ResponsesStreamState,process_responses_sse_line,finalize_responses_stream, andparse_responses_completion.Assistant
Now add the new functions after
finalize_stream(before the tests module). Let me add them at line 871 (after thefinalize_streamfunction).Assistant
Now update
openai.rsto use the shared functions instead of the local ones.Assistant
Now remove the
ws_output_indexfunction and replace its usages withresponses_output_index, and removesplit_responses_instructions_and_inputfrom the impl, replacing with the free function.Assistant
Now replace
ws_output_indexcalls withresponses_output_index:Assistant
Now remove
split_responses_instructions_and_inputfrom the impl and replaceSelf::split_responses_instructions_and_inputwith the free function:Assistant
Now replace
Self::split_responses_instructions_and_inputwith the free function:Assistant
Now check that
to_responses_inputis no longer needed as a direct import since it's used insidesplit_responses_instructions_and_input. Let me verify:Assistant
It's still imported but may not be used directly anymore. Let me check if it's used elsewhere in the file:
Assistant
Only used in the import. Let me remove it:
Assistant
Also check if
HashMapandHashSetare still used at the top of the file (they were used byws_output_indexetc.):Assistant
HashMap and HashSet are still used in the websocket streaming code (tool_calls, completed_tool_calls). Good.
Assistant
Now the big task: updating
github_copilot.rs. Let me update the imports, addneeds_responses_api,is_responses_api_required_error, updateCOPILOT_MODELS, addcomplete_responses,stream_responses_api, and modifycompleteandstream_with_tools.Assistant
Now update
COPILOT_MODELSto add the new models:Assistant
Now add the
needs_responses_apiandis_responses_api_required_errorfunctions. I'll add them right before theLlmProviderimpl:Assistant
Now I need to add
complete_responsesandstream_responses_apimethods toGitHubCopilotProvider, and modifycompleteandstream_with_tools. Let me re-read the impl to get the exact positions:Assistant
Now I'll replace the entire
LlmProviderimpl with the updated version that includes Responses API support:Assistant
Let me do a quick
cargo checkto catch any compile errors before writing tests:Assistant
The
HashSetimport I added toopenai_compat.rsis causing anunnecessary qualificationerror sincestd::collections::HashSetwas already used elsewhere in the file with the full path. Let me fix this:Assistant
That
style.csserror is pre-existing and unrelated to my changes. The providers crate compiled successfully. Let me now run tests specifically for the providers crate:Assistant
All 186 tests pass. Now let me add tests for the new code.
Assistant
Now let me add tests. First to
openai_compat.rsfor the new functions, then togithub_copilot.rsfor the new provider methods.Assistant
Now let me add the tests for the new functions at the end of the tests module:
Assistant
Now add tests to
github_copilot.rs. Let me read the current end of the test module:Assistant
Now I need to update the
MockCopilotProviderto add acomplete_responsesmethod, and also updatestart_mock_with_captureto handle both endpoints. Let me rewrite the test infrastructure and add new tests:Assistant
Now update the
MockCopilotProviderto add acomplete_responsesmethod:Assistant
Now add the new tests at the end of the test module:
Assistant
Now let me run the tests:
Assistant
All 214 tests pass (up from 186 — 28 new tests added).
Assistant
Now run the full verification suite:
Assistant
There are formatting issues. Let me fix them:
Assistant
Formatting is clean. Now run clippy:
Assistant
Two clippy issues. Let me fix them:
Assistant
Let me check the specific lines referenced by clippy:
Assistant
Two issues to fix:
- Collapsible
ifinparse_responses_completion field_reassign_with_defaultin a test
- Collapsible
Assistant
Now fix the
field_reassign_with_defaulttest issue. Let me find the exact test:Assistant
Now let me format and re-run clippy:
Assistant
Clippy passes. Let me run the full test suite one more time to confirm everything still works:
Assistant
All 214 tests pass. Let me also verify the formatting is clean:
Assistant
All tasks complete. Here's a summary of what was implemented:
Summary
crates/providers/src/openai_compat.rs— new shared utilities- User
commit, push, create a PR
Assistant
PR created: https://github.com/moltis-org/moltis/pull/393
- User
any remaining comments to fix at https://github.com/moltis-org/moltis/pull/393 ?
Assistant
There are 2 actionable review comments from bots:
- Case-insensitive error matching in
is_responses_api_required_error— both Greptile and Codex flagged this. Valid fix. - Missing
ProviderRawevents inprocess_responses_sse_line— Greptile noted this but also acknowledged the WebSocket path has the same omission. I'll skip this (consistent with existing precedent).
Let me check what openai.rs does for comparison, then fix comment #1:
- Case-insensitive error matching in
Assistant
Confirmed — the openai.rs version uses
to_ascii_lowercase(). Let me apply the fix:Assistant
Now update the test to also verify case-insensitive matching:
Assistant
All 214 tests pass. Now commit and push:
Assistant
Done. Fixed the one actionable comment:
- Case-insensitive error matching —
is_responses_api_required_errornow usesto_ascii_lowercase()before checking substrings, matching the pattern inopenai.rs. Added a test for mixed-casing.
The other comment (missing
ProviderRawevents) is a deliberate design choice — the OpenAI WebSocket Responses API path has the same behavior, so this is consistent.- Case-insensitive error matching —