Skip to content

opencode_env: keep the upstream base path in the interception proxy - #1264

Open
jayzuccarelli wants to merge 1 commit into
huggingface:mainfrom
jayzuccarelli:fix-proxy-upstream-path
Open

jayzuccarelli wants to merge 1 commit into
huggingface:mainfrom
jayzuccarelli:fix-proxy-upstream-path

Conversation

@jayzuccarelli

@jayzuccarelli jayzuccarelli commented Sep 28, 2026 •

Copy link
Copy Markdown

Summary

The interception proxy builds the upstream URL by appending /v1/chat/completions to any base_url that 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 in black_box mode calls .../v1beta/openai/chat/completions with the same base_url. So the same config works in black_box and not in transparent_proxy.

This applies the rule #1237 settled on for OpenAIClient: add /v1 only 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 from openenv.core. /v1 and pathless bases resolve exactly as before.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • New environment
  • Refactoring

Alignment Checklist

Before submitting, verify:

  • I have read .claude/docs/PRINCIPLES.md and this PR aligns with our principles
  • I have checked .claude/docs/INVARIANTS.md and no invariants are violated
  • I have run /pre-submit-pr (or bash .claude/hooks/lint.sh and tests) and addressed all issues

RFC Status

  • Not required (bug fix, docs, minor refactoring)
  • RFC exists: #___
  • RFC needed (will create before merge)

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_url no longer treats “doesn’t end with /v1” as “needs /v1 inserted.” It uses urlsplit: 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/completions for Gemini-style bases.

Adds test_interception_keeps_upstream_base_path covering 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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant