Skip to content

fix(adapters): preserve Responses URL authority - #1718

Draft
luvs01 wants to merge 1 commit into
lidge-jun:devfrom
luvs01:agent/fix-responses-url-authority
Draft

fix(adapters): preserve Responses URL authority#1718
luvs01 wants to merge 1 commit into
lidge-jun:devfrom
luvs01:agent/fix-responses-url-authority

Conversation

@luvs01

@luvs01 luvs01 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • parse the validated key-auth base URL and normalize only its pathname
  • preserve authorities named responses or v1, non-default ports, and IPv6 literals
  • keep forward-mode and custom responsesPath routing unchanged

The previous string-wide suffix replacement could treat a hostname as a path segment (for example https://responses) and construct a different authority. Because the adapter attaches API credentials to the resulting request, this is both a routing-correctness and credential-destination fix.

Scope and compatibility

This changes only the default key-auth /v1/responses URL helper. Provider configuration already requires an HTTP(S) URL and rejects embedded credentials, queries, and fragments. URL serialization may canonicalize equivalent syntax such as host case or a default port; it does not change the destination.

No UI is changed.

Verification

Published range: b81314cd29b78fecb447df882dc4fc1a987434b94a48836d06dc314d311651ff86129eaec482dfa9.

The validated and published exact head is 4a48836d06dc314d311651ff86129eaec482dfa9; its parent is current dev at b81314cd29b78fecb447df882dc4fc1a987434b9. The latest-dev rebase preserved stable patch ID ff189d1726cd47d768ce4566aa53b86fcf7cfd6b.

  • Bun 1.3.14: focused Responses URL/passthrough suite 68/68 passed (219 assertions)
  • Bun 1.4.0-canary.1: focused Responses URL/passthrough suite 68/68 passed (219 assertions)
  • TypeScript typecheck passed on both runtimes
  • privacy scan passed on both runtimes
  • git diff --check passed
  • independent correctness review: no P0–P2 findings
  • Codex Security diff scan 87bad3b6-a829-4953-be42-c9b01e63de00: no P0–P2 findings; snapshot codex-security-snapshot/v1:sha256:78b507ea3064e622652c4f6de2a2bea99c2ffe31d78e373e375015315696a669; the scanned patch and exact head share stable patch ID ff189d1726cd47d768ce4566aa53b86fcf7cfd6b

The full repository suite is not claimed green. A Bun 1.3.14 attempt reproducibly exited with an internal assertion in the unrelated api-storage-policy-run.test.ts, including when isolated. A Bun 1.4 canary run completed with 11,479 passing, 17 skipped, 368 failing, and 16 errors, clustered in existing Windows effective-account/ACL/symlink/process-timeout and unrelated catalog areas. No plausible call path from this two-file patch to those failures was found. Maintained CI remains authoritative.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Responses endpoint URL handling across bare hosts, /v1 bases, custom ports, and IPv6 addresses.
    • Preserved query parameters and other URL components when constructing endpoint URLs.
    • Invalid URL inputs are now rejected consistently.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 10db3d00-297d-4c53-98ee-b054bdd5693a

📥 Commits

Reviewing files that changed from the base of the PR and between 81ada7c and 23d10de.

📒 Files selected for processing (2)
  • src/adapters/openai-responses-url.ts
  • tests/openai-responses-passthrough.test.ts

📝 Walkthrough

Walkthrough

The Responses URL builder now uses URL parsing and pathname normalization. Query parameters and other URL components remain intact. Passthrough tests cover bare hosts, ports, and IPv6 addresses.

Changes

Responses URL handling

Layer / File(s) Summary
URL normalization and regression coverage
src/adapters/openai-responses-url.ts, tests/openai-responses-passthrough.test.ts
openaiResponsesUrl parses the trimmed base URL, sets its pathname to /v1/responses, and serializes the result. Tests cover bare hosts, /v1 bases, non-default ports, and IPv6 addresses.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 23d10

This localized change preserves the intended URL authority while keeping existing routing behavior; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

  • lidge-jun/opencodex#1471: Both PRs modify OpenAI Responses URL construction and passthrough tests, but address different concerns.

Suggested reviewers: lidge-jun, ingwannu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main adapter fix: preserving URL authority when constructing the Responses URL.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 14, 2026
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (3/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 3/4).

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ⬜ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

3/4 boxes ticked.

This PR stays in draft until every box above is ticked.

luvs01 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Please review exact head 23d10de33ce8eb25bfd12c0e69e3f9447a2f0e26.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

requested='23d10de33ce8eb25bfd12c0e69e3f9447a2f0e26'
echo '== HEAD =='
git rev-parse HEAD
echo '== requested commit =='
git rev-parse "$requested"
echo '== commit metadata =='
git show -s --format='%H%nParents: %P%nSubject: %s' "$requested"
echo '== changed files =='
git diff-tree --no-commit-id --name-status -r "$requested"
echo '== exact diff =='
git diff "${requested}^" "$requested" --check
git diff --find-renames --find-copies "${requested}^" "$requested" -- .

echo '== outlines of changed source files =='
git diff-tree --no-commit-id --name-only -r "$requested" |
  while IFS= read -r f; do
    case "$f" in
      *.ts|*.tsx|*.js|*.jsx)
        echo "--- $f"
        ast-grep outline "$f" --items all --view expanded || true
        ;;
    esac
  done

echo '== URL helper candidates and usages =='
rg -n -i -C 4 \
  '(responsesPath|/v1/responses|new URL\s*\(|key-auth|keyAuth|baseURL|baseUrl)' \
  -g '*.ts' -g '*.tsx' -g '*.js' -g '*.jsx' .

Length of output: 201513


🏁 Script executed:

#!/bin/bash
set -euo pipefail

requested='23d10de33ce8eb25bfd12c0e69e3f9447a2f0e26'

printf '%s\n' '== commit identity =='
printf 'HEAD: '; git rev-parse HEAD
printf 'requested: '; git rev-parse "$requested"
git show -s --format='parent: %P%nsubject: %s' "$requested"

printf '%s\n' '== changed paths =='
git diff-tree --no-commit-id --name-status -r "$requested"

printf '%s\n' '== patch =='
git diff --no-ext-diff --unified=80 "${requested}^" "$requested" -- \
  $(git diff-tree --no-commit-id --name-only -r "$requested")

printf '%s\n' '== changed-file outlines =='
while IFS= read -r file; do
  case "$file" in
    *.ts|*.tsx|*.js|*.jsx)
      printf '\n--- %s ---\n' "$file"
      ast-grep outline "$file" --items all --view expanded
      ;;
  esac
done < <(git diff-tree --no-commit-id --name-only -r "$requested")

printf '%s\n' '== focused helper symbols and test labels =='
git grep -n -E \
  '(responsesPath|responses.*URL|response.*URL|/v1/responses|authMode.*key|authMode.*forward)' \
  "$requested" -- \
  '*.ts' '*.tsx' '*.js' '*.jsx' |
  head -n 500

Length of output: 10751


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== URL helper with line numbers =='
nl -ba src/adapters/openai-responses-url.ts

echo '== adapter references to the helper and route selection =='
rg -n -C 12 '\bopenaiResponsesUrl\s*\(|\bresponsesPath\b|\bauthMode\b' \
  src/adapters tests/openai-responses-passthrough.test.ts

echo '== baseUrl validation declarations and rules =='
rg -n -C 12 \
  '(baseUrl.*(URL|url|credentials|query|fragment)|new URL\(.*baseUrl|URL\(.*baseUrl|must not include embedded credentials)' \
  src tests \
  -g '*.ts' -g '*.tsx'

echo '== focused changed test section with line numbers =='
nl -ba tests/openai-responses-passthrough.test.ts | sed -n '100,210p'

echo '== all direct helper usages at requested commit =='
git grep -n -E '\bopenaiResponsesUrl\s*\(' HEAD -- '*.ts' '*.tsx'

Length of output: 1184


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== URL helper with line numbers =='
awk '{ printf "%6d  %s\n", NR, $0 }' src/adapters/openai-responses-url.ts

echo '== adapter references to the helper and route selection =='
rg -n -C 12 '\bopenaiResponsesUrl\s*\(|\bresponsesPath\b|\bauthMode\b' \
  src/adapters tests/openai-responses-passthrough.test.ts

echo '== baseUrl validation declarations and rules =='
rg -n -C 12 \
  '(baseUrl.*(URL|url|credentials|query|fragment)|new URL\(.*baseUrl|URL\(.*baseUrl|must not include embedded credentials)' \
  src tests \
  -g '*.ts' -g '*.tsx' | head -n 800

echo '== focused changed test section with line numbers =='
awk 'NR >= 100 && NR <= 210 { printf "%6d  %s\n", NR, $0 }' \
  tests/openai-responses-passthrough.test.ts

echo '== all direct helper usages at requested commit =='
git grep -n -E '\bopenaiResponsesUrl\s*\(' HEAD -- '*.ts' '*.tsx'

Length of output: 133208


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== provider baseUrl validation locations =='
rg -n -C 8 \
  '(baseUrl must not|baseUrl.*(query|fragment|credentials)|embedded credentials|search.*=.*""|hash.*=.*""|protocol.*https?:)' \
  src \
  -g '*.ts' | head -n 500

echo '== configuration module candidates =='
fd -t f -e ts . src | rg '(^|/)(config|schema|validation|provider).*[.]ts$' | head -n 200

echo '== exact config validation function context =='
rg -n -C 30 \
  'function (providerConfigError|validateProvider|providerManagementConfigError)|export function (providerConfigError|validateProvider|providerManagementConfigError)' \
  src \
  -g '*.ts' | head -n 700

echo '== exact diff hygiene =='
git diff --check 81ada7cd092d4be3b25f3013c996cd3262a2f99b 23d10de33ce8eb25bfd12c0e69e3f9447a2f0e26
git status --short

Length of output: 40269


@luvs01 Reviewed exact head 23d10de33ce8eb25bfd12c0e69e3f9447a2f0e26.

No findings.

The change in src/adapters/openai-responses-url.ts Lines 10-15 preserves the parsed URL authority. It only normalizes URL.pathname. This prevents responses or v1 hostnames from being treated as path suffixes.

The helper is used only for non-forward requests with no responsesPath in src/adapters/openai-responses.ts Lines 1353-1357. Forward-mode routing and explicit responsesPath routing remain separate.

src/config.ts Lines 757-766 rejects invalid schemes, embedded credentials, query strings, and fragments. This makes the URL parsing and serialization contract appropriate for the helper.

The added tests cover the affected hostname cases, a non-default port, and an IPv6 literal. git diff --check passed. I did not execute tests in this sandbox.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

luvs01 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Please review exact head eca01d7780c7cc70646d2e8d31caa5b207904149.

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

requested='eca01d7780c7cc70646d2e8d31caa5b207904149'

echo '== Exact commit identity =='
echo -n 'HEAD: '; git rev-parse HEAD
echo -n 'Requested: '; git rev-parse "$requested"
git show -s --format='Parents: %P%nSubject: %s%n%n%B' "$requested"

echo '== Changed paths =='
git diff-tree --no-commit-id --name-status -r "$requested"

echo '== Diff check =='
git diff --check "${requested}^" "$requested"

echo '== Incremental patch =='
git diff --no-ext-diff --find-renames --find-copies --unified=80 \
  "${requested}^" "$requested" -- \
  $(git diff-tree --no-commit-id --name-only -r "$requested")

echo '== Changed TypeScript file outlines =='
git diff-tree --no-commit-id --name-only -r "$requested" |
while IFS= read -r file; do
  case "$file" in
    *.ts|*.tsx|*.js|*.jsx)
      echo "--- $file"
      ast-grep outline "$file" --items all --view expanded || true
      ;;
  esac
done

echo '== Focused references to changed URL helper and routing controls =='
rg -n -C 10 \
  '\bopenaiResponsesUrl\s*\(|\bresponsesPath\b|\bauthMode\b|/v1/responses|new URL\s*\(' \
  src tests -g '*.ts' -g '*.tsx' | head -n 1200

echo '== Working tree status =='
git status --short

Length of output: 99170


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== Helper and all call sites =='
rg -n -C 20 '\bopenaiResponsesUrl\s*\(' \
  src tests -g '*.ts' -g '*.tsx'

echo '== Responses adapter URL selection =='
ast-grep outline src/adapters/openai-responses.ts --items all --view expanded | head -n 500
rg -n -C 35 \
  '(responsesPath|openaiResponsesUrl|buildRequest|baseUrl)' \
  src/adapters/openai-responses.ts

echo '== URL helper and test file relevant sections =='
nl -ba src/adapters/openai-responses-url.ts
nl -ba tests/openai-responses-passthrough.test.ts | sed -n '1,210p'

echo '== Validation call graph and URL validation tests =='
rg -n -C 12 \
  '\bproviderBaseUrlConfigError\s*\(|baseUrl must not include query strings or fragments|baseUrl must not include embedded credentials' \
  src tests -g '*.ts' -g '*.tsx'

echo '== Direct helper tests and URL-shape expectations =='
rg -n -C 10 \
  '(openaiResponsesUrl|responses URL|Responses key-auth URL construction|baseUrl.*[?#])' \
  tests src/adapters -g '*.ts' -g '*.tsx'

echo '== HTTPS policy for provider POST requests =='
rg -n -C 15 \
  'provider POST URL must use HTTPS|providerOutboundRequest|providerPost' \
  src/lib/provider-outbound.ts src/adapters/openai-responses.ts

Length of output: 21505


🏁 Script executed:

#!/bin/bash
set -euo pipefail

show_lines() {
  local file="$1"
  local start="$2"
  local end="$3"
  awk -v start="$start" -v end="$end" \
    'NR >= start && NR <= end { printf "%6d  %s\n", NR, $0 }' "$file"
}

echo '== URL helper =='
show_lines src/adapters/openai-responses-url.ts 1 80

echo '== Key-auth URL tests =='
show_lines tests/openai-responses-passthrough.test.ts 120 190
show_lines tests/openai-responses-passthrough.test.ts 2015 2040

echo '== Provider URL validation and configuration entry point =='
show_lines src/config.ts 745 785
rg -n -C 20 \
  '(providerBaseUrlConfigError\(|superRefine|safeParse\(|parse\()' \
  src/config.ts | head -n 800

echo '== Helper import and URL test coverage across the repository =='
rg -n -C 6 \
  'from ["'\''].*openai-responses-url|openaiResponsesUrl\s*\(' \
  src tests -g '*.ts' -g '*.tsx'

echo '== Query or fragment provider URL tests =='
rg -n -C 8 \
  '(query strings or fragments|embedded credentials|baseUrl.*[?]x=|baseUrl.*#)' \
  tests -g '*.ts' -g '*.tsx' | head -n 700

echo '== Exact diff against the requested parent =='
git diff --check eca01d7780c7cc70646d2e8d31caa5b207904149^ eca01d7780c7cc70646d2e8d31caa5b207904149

Length of output: 58591


@luvs01 Reviewed exact head eca01d7780c7cc70646d2e8d31caa5b207904149.

No findings.

src/adapters/openai-responses-url.ts Lines 10-15 now parses baseUrl and changes only URL.pathname. The change preserves the URL authority. This includes a hostname named responses or v1, a non-default port, and an IPv6 literal.

src/adapters/openai-responses.ts Line 1354 uses the helper only for non-forward requests when responsesPath is absent. Forward routing remains separate at Lines 1322-1328. Explicit responsesPath routing remains separate at Lines 1355-1357.

tests/openai-responses-passthrough.test.ts Lines 149-162 cover the affected authority forms. Existing direct helper tests at Lines 2022-2030 continue to cover non-terminal path segments.

I also applied the existing repository context for provider URL validation. src/config.ts Lines 757-766 rejects invalid schemes, embedded credentials, query strings, and fragments before a persisted provider configuration reaches this helper.

git diff --check passed. I did not execute repository tests in this sandbox.


🧠 Learnings used
Learnt from: baileyh8
Repo: lidge-jun/opencodex PR: 1361
File: src/adapters/openai-responses.ts:1249-1251
Timestamp: 2026-08-10T09:09:45.766Z
Learning: In the TypeScript resolver `src/server/adapter-resolve.ts`, `resolveWireProtocolOverride()` changes only the provider `adapter` through a shallow copy and preserves `authMode`, credentials, and `baseUrl`. Reviews must not treat `route.provider.authMode` and the resolved adapter provider's `authMode` as divergent through this resolver.

Learnt from: Eleven-is-cool
Repo: lidge-jun/opencodex PR: 616
File: src/config.ts:499-549
Timestamp: 2026-07-29T02:47:48.815Z
Learning: In `src/router.ts`, registry-backed providers derive an effective `canonicalAuthMode` before request handling. For registry entries with `authKind` other than `forward` or `oauth` (including `openai-apikey`), a persisted `authMode: "forward"` is normalized to `undefined`; reviews of adapters must use this routed provider state rather than assume raw persisted `authMode` reaches the adapter.

Learnt from: Wibias
Repo: lidge-jun/opencodex PR: 1066
File: src/adapters/command-code.ts:261-273
Timestamp: 2026-08-05T21:08:30.551Z
Learning: In this repository, `src/config.ts` function `providerBaseUrlConfigError` accepts both `http:` and `https:` provider URLs and rejects embedded credentials, query strings, and fragments. Operator-controlled provider configuration is the repository-wide model, but OAuth adapters that attach Bearer credentials require separate HTTPS enforcement when cleartext transmission is not acceptable.
⚠️ Action not completed

No files to review.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lidge-jun

Copy link
Copy Markdown
Owner

Thanks for the fix — parsing with new URL() and editing only pathname is the right call, and the table tests cover the authority-mangling cases well. Keeping this as draft for process reasons only: as an external-contributor draft it has not had full CI (fork limitation), so it needs the readiness checklist completed and a maintainer-triggered full CI run before merge. Flagging for maintainer CI.

@lidge-jun lidge-jun added provider Provider adapters, OpenAI-compat presets, upstream API quirks proxy HTTP proxy, routing, reverse-proxy / management auth labels Aug 15, 2026
@luvs01
luvs01 force-pushed the agent/fix-responses-url-authority branch from eca01d7 to 4a48836 Compare August 16, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider Provider adapters, OpenAI-compat presets, upstream API quirks proxy HTTP proxy, routing, reverse-proxy / management auth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants