Skip to content

fix(gateway): strip port from openai-compat openaiCustomUrl (#1057)#1061

Open
JOJOCrazy123 wants to merge 3 commits into
agentscope-ai:mainfrom
JOJOCrazy123:fix/issue-1057-openai-compat-custom-url-port
Open

fix(gateway): strip port from openai-compat openaiCustomUrl (#1057)#1061
JOJOCrazy123 wants to merge 3 commits into
agentscope-ai:mainfrom
JOJOCrazy123:fix/issue-1057-openai-compat-custom-url-port

Conversation

@JOJOCrazy123

Copy link
Copy Markdown

Summary

Fixes #1057. When the openai-compat LLM provider is configured with an IP:port base URL (e.g. http://10.43.46.12:3000/v1), openaiCustomUrl was set to the full URL including the port. Higress derives the upstream host domain from openaiCustomUrl, so it extracted 10.43.46.12:3000 as the host domain — not a valid DNS hostname — and upstream DNS resolution failed, making the LLM endpoint unreachable.

The port is already provided separately via openaiCustomServicePort, so including it in openaiCustomUrl is both redundant and breaking.

Changes

  • hiclaw-controller/internal/initializer/initializer.go: add customOpenAIURL() helper that strips the port (keeps scheme/host/path) and use it for openaiCustomUrl in both the openai-compat and custom-provider paths.
  • manager/scripts/init/setup-higress.sh: build openaiCustomUrl from scheme + domain + path only (no port).
  • hiclaw-controller/internal/initializer/initializer_test.go: unit tests for customOpenAIURL.
  • changelog/current.md: record the fix.

Result: openaiCustomUrl becomes http://10.43.46.12/v1, host domain is 10.43.46.12, and the port is supplied only via openaiCustomServicePort.

Test plan

  • bash -n manager/scripts/init/setup-higress.sh passes; parsing verified for IP:port+path, host:port, no-port, and no-path inputs.
  • go test ./internal/initializer/ — could not run locally (no Go toolchain in this environment); expected to pass via CI.
  • Manual: initialize with an openai-compat provider using an IP:port base URL and confirm the Higress provider "自定义 OpenAI 服务主机域" shows the host without the port.

Notes

The issue also mentions a secondary bug where the Go EnsureAIProvider/ensureServiceSource use POST-only (treating 409 as success) and cannot correct an already-misconfigured provider on re-run. That is a separate concern and intentionally left out of this narrow fix.

Higress derives the upstream host domain from openaiCustomUrl, so an
IP:port base URL such as http://10.43.46.12:3000/v1 produced host domain
10.43.46.12:3000, which is not a valid DNS hostname and broke resolution.

Strip the port from openaiCustomUrl in the controller initializer and in
setup-higress.sh, keeping scheme/host/path only. The port continues to be
supplied via openaiCustomServicePort.

Fixes agentscope-ai#1057
@github-actions

Copy link
Copy Markdown
Contributor

❌ Integration Tests Failed (controller-cr-2 / mgr=copaw / wk=copaw)

Commit: 539460c
Workflow run: #1699

Test Results
No test output captured.
Debug Log (tail)
No debug logs available.

📦 Download full debug logs & test artifacts

@github-actions

Copy link
Copy Markdown
Contributor

📊 CI Metrics Report

Summary

Metric Current Baseline Change
LLM Calls 183 97 +86 ↑ +88.7%
Input Tokens 5628772 2719498 +2909274 ↑ +107.0%
Output Tokens 52922 16508 +36414 ↑ +220.6%
Total Tokens 5681694 2736006 +2945688 ↑ +107.7%

By Role

Role Metric Current Baseline Change
🧠 Manager LLM Calls 111 72 +39 ↑ +54.2%
Input Tokens 3802648 2092724 +1709924 ↑ +81.7%
Output Tokens 24127 10274 +13853 ↑ +134.8%
Total Tokens 3826775 2102998 +1723777 ↑ +82.0%
🔧 Workers LLM Calls 72 25 +47 ↑ +188.0%
Input Tokens 1826124 626774 +1199350 ↑ +191.4%
Output Tokens 28795 6234 +22561 ↑ +361.9%
Total Tokens 1854919 633008 +1221911 ↑ +193.0%

Per-Test Breakdown

Test Mgr Calls Wkr Calls Δ Calls Mgr In Wkr In Mgr Out Wkr Out Δ Tokens Trend
02-create-worker 6 0 +1 ↑ +20.0% 168385 0 578 0 +31975 ↑ +23.3% ⚠️ regressed
03-assign-task 8 5 0 — 0% 221259 113392 1247 646 +26364 ↑ +8.5% — unchanged
04-human-intervene 11 6 +3 ↑ +21.4% 276498 136008 1293 693 +78055 ↑ +23.2% ⚠️ regressed
05-heartbeat 6 5 +4 ↑ +57.1% 182641 111190 1019 741 +97387 ↑ +49.1% ⚠️ regressed
06-multi-worker 80 56 +78 ↑ +134.5% 2953865 1465534 19990 26715 +2711907 ↑ +154.6% ⚠️ regressed

Trends

⚠️ 4 test(s) regressed (more LLM calls)


Generated by HiClaw CI on 2026-07-19 08:36:24 UTC


📦 Download debug logs & test artifacts

@JOJOCrazy123

Copy link
Copy Markdown
Author

CI note: the only red check (controller-cr-2 / test-21) is unrelated to this PR

The sole failing check is integration-tests (controller-cr-2, SHARD_D_TESTS, copaw, copaw)test-21-team-project-dag. All other shards and build jobs are green.

This PR only touches the gateway openai-compat URL handling (manager/.../initializer.go, manager/scripts/init/setup-higress.sh, changelog). It does not touch the CoPaw team-controller / Leader coordination path that test-21 exercises.

test-21 is a non-deterministic LLM-behavior E2E test. In this run it failed because the CoPaw Leader posted an interim planning message in the Leader DM ("I'll start by reviewing the team-coordination... to plan and coordinate this project.") instead of replying NO_REPLY and putting the first assignment in the Team Room — which trips the fail-fast heuristic (MAX_DM_ONLY_POLLS=1). That's a prompt-adherence flake in the runtime, not something this change can affect.

Importantly, the same shard is also failing on main: latest push run https://github.com/agentscope-ai/AgentTeams/actions/runs/29649250704 (controller-cr-2, SHARD_D_TESTS red). So this is a pre-existing flaky failure, not a regression from #1061.

Could a maintainer re-run the failed job? Happy to rebase if that helps. Thanks!

@JOJOCrazy123

Copy link
Copy Markdown
Author

Hi maintainers, this PR is ready for review, but the workflow is still awaiting maintainer approval. Could someone please approve the workflow and review the PR when convenient? Thank you!

@shiyiyue1102 shiyiyue1102 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the focused fix. The IPv4 host:port case is handled, but customOpenAIURL currently reconstructs the URL from Scheme, Hostname, and the decoded Path, so it changes more than the port: it drops RawQuery, decodes escaped path segments, and emits unbracketed IPv6 literals. I reproduced all three cases locally.

Could you preserve the parsed URL and remove only the port, then add regression cases for query strings, escaped paths, and IPv6 literals? The existing controller unit and envtest integration suites pass locally; the red test-21 shard also fails on main and appears unrelated.


感谢这个聚焦的修复。当前 IPv4 host:port 场景已经处理,但 customOpenAIURL 通过 SchemeHostname 和解码后的 Path 重新拼装 URL,实际修改的不只是端口:它会丢失 RawQuery、解码转义路径,并生成没有方括号的 IPv6 URL。我已在本地复现这三种情况。

请保留解析后 URL 的其他字段,仅移除端口,并补充 query、转义路径和 IPv6 字面量的回归用例。现有 Controller 单元测试和 envtest 集成测试在本地均通过;红色的 test-21 分片在 main 上也失败,判断与本 PR 无关。

…-compat-custom-url-port

# Conflicts:
#	agentteams-controller/internal/initializer/initializer_test.go
#	changelog/current.md
…om openaiCustomUrl

Address review feedback on agentscope-ai#1061: customOpenAIURL reconstructed the URL from
Scheme+Hostname+decoded Path, which dropped RawQuery, decoded escaped path
segments, and emitted unbracketed IPv6 literals. Instead, keep the parsed URL
and remove only the port (re-bracketing IPv6 hosts), so everything else is
preserved. Add regression cases for query strings, escaped paths, and IPv6.
@JOJOCrazy123

Copy link
Copy Markdown
Author

Thanks for the careful review — you're right on all three counts.

I've reworked customOpenAIURL so it no longer rebuilds the URL from Scheme/Hostname/Path. It now keeps the parsed *url.URL and removes only the port (sets u.Host to the hostname, re-bracketing IPv6 literals) then returns u.String(). As a result:

  • Query strings (RawQuery) are preserved.
  • Escaped path segments are no longer decoded (via EscapedPath() in String()).
  • IPv6 literals stay bracketed, e.g. http://[2001:db8::1]:3000/v1http://[2001:db8::1]/v1.

Added regression cases for query strings, escaped paths (%2F), and IPv6 (with and without a port).

I also merged latest main to resolve the conflict from the hiclaw-controlleragentteams-controller rename (the helper and its test moved with it). Pushed as 718c83d.

Agreed the red test-21 shard is unrelated — it also fails on main.

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.

[BUG] openai-compat provider fails when using IP:port base URL

2 participants