refactor(proxy): deepen provider and responses architecture#209
Merged
Conversation
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors several aspects of the proxy layer to centralize provider endpoint policy, consolidate model registry operations, extract Responses request preparation into an explicit step, and unify WebSocket session-state mutation into a single seam.
Changes:
- Introduces
providerEndpointPolicystruct and per-kind policy factory, replacing scattered switch statements for endpoint routing, unknown-model allowance, and discovered-model filtering with method calls onproviderRuntime. - Consolidates provider model registration into
addProviderModels/mergeProviderModelshelpers, sharing filtering and collision logic across static setup, dynamic setup, and refresh paths. - Extracts
prepareResponsesRequest,postPreparedResponsesRequest, andwriteResponsesUpstreamRequestFailureto separate concerns of header extraction, stream detection, dispatch/retry, and error mapping in the Responses HTTP handler. - Adds
rememberPlannedResponseon the WebSocket session to centralize compaction-trigger and history-update logic for both generate=false and normal response turns.
Show a summary per file
| File | Description |
|---|---|
| proxy/provider_endpoint_policy.go | New file: centralizes all per-provider-kind endpoint decisions into a single policy struct with factory function and providerRuntime method wrappers |
| proxy/provider_endpoint_policy_test.go | New file: comprehensive tests for policy defaults and routing decisions across all provider types |
| proxy/providers.go | Replaces inline model-registration loops with addProviderModels/addStaticProviderModels/mergeProviderModels; removes old scattered helper functions; uses new policy API |
| proxy/upstream_http.go | Replaces free-function calls (providerSupportsEndpoint, providerAllowsUnknownModelEndpoint) with providerRuntime method calls; removes deleted functions |
| proxy/responses_handler.go | Extracts prepareResponsesRequest, responsesRequestStreams, postPreparedResponsesRequest, and writeResponsesUpstreamRequestFailure; simplifies HandleResponses |
| proxy/responses_handler_test.go | Tests for responsesRequestStreams and prepareResponsesRequest |
| proxy/responses_websocket.go | Adds rememberPlannedResponse helper; replaces duplicated compaction-trigger + history-update logic at two call sites |
| proxy/responses_websocket_test.go | Tests for rememberPlannedResponse covering both normal append and compaction-trigger reset paths |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 8/8 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why
The proxy had several shallow modules where provider ownership, endpoint capability, Responses dispatch, and websocket session mutation were spread across call sites. These refactors improve locality and make the test seams better match the behavior callers depend on.
Validation
go test ./proxy -run 'TestProviderEndpointPolicy|TestResolveProviderRequest|TestBuildProvidersGeneric|TestDecode' -count=1go test ./proxy -run 'TestResponsesRequestStreams|TestPrepareResponsesRequestBuildsHeaderAndStreamingPlan|TestHandleResponses' -count=1go test ./proxy -run 'TestResponsesWebSocketRememberPlannedResponse|TestResponsesWebSocket.*Turn|TestResponsesWebSocket.*Compaction' -count=1make testmake build./vekil --helpAutoreview
Each commit was autoreviewed before commit with:
Every autoreview run reported
autoreview clean: no accepted/actionable findings reported.Progress log
Detailed progress and the completion audit are tracked locally in
/tmp/refactor-vekil.md.