opencode_env: keep the upstream base path in the interception proxy - #1264
Open
jayzuccarelli wants to merge 1 commit into
Open
jayzuccarelli wants to merge 1 commit into
jayzuccarelli wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 of 12 tasks
This branch has not been deployed
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
The interception proxy builds the upstream URL by appending
/v1/chat/completionsto anybase_urlthat doesn't end in/v1. For OpenAI-compatible providers with a different prefix (Gemini.../v1beta/openai, z.ai.../api/paas/v4) that produces.../v1beta/openai/v1/chat/completions, while opencode inblack_boxmode calls.../v1beta/openai/chat/completionswith the samebase_url. So the same config works in black_box and not in transparent_proxy.This applies the rule #1237 settled on for
OpenAIClient: add/v1only when the URL has no path, otherwise use it as-is. The proxy runs standalone in the sandbox, so the check is inlined rather than imported fromopenenv.core./v1and pathless bases resolve exactly as before.Type of Change
Alignment Checklist
Before submitting, verify:
.claude/docs/PRINCIPLES.mdand this PR aligns with our principles.claude/docs/INVARIANTS.mdand no invariants are violated/pre-submit-pr(orbash .claude/hooks/lint.shand tests) and addressed all issuesRFC Status
Test Plan
PYTHONPATH=src:envs uv run pytest tests/envs/test_opencode_*.py -q: 48 passed, 1 skipped. The new test fails on main. Also ran the proxy against a local stub mounted at/api/paas/v4: main forwards to/api/paas/v4/v1/chat/completions, this branch to/api/paas/v4/chat/completions.Claude Code Review
N/A
🤖 Generated with Claude Code
Note
Low Risk
Localized URL-building bugfix in the sandbox proxy with unit tests; pathless bases behave as before.
Overview
Fixes transparent proxy upstream URL construction so it matches opencode black_box behavior for non-OpenAI path prefixes.
_resolve_upstream_urlno longer treats “doesn’t end with/v1” as “needs/v1inserted.” It usesurlsplit: if the base URL already has a path (/v1,/v1beta/openai,/api/paas/v4, etc.), it only appends/chat/completions; pathless hosts still get/v1/chat/completions. That stops broken URLs like.../v1beta/openai/v1/chat/completionsfor Gemini-style bases.Adds
test_interception_keeps_upstream_base_pathcovering OpenAI/v1, localhost, Gemini, and z.ai-style bases.Reviewed by Cursor Bugbot for commit 0060306. Bugbot is set up for automated code reviews on this repo. Configure here.