fix: imagegen MCP env 必须写死本地网关 base URL
首轮生产验收失败根因:_prepare_tenant 只把 IMAGE_GEN_* 透传 进 MCP env,没写 IMAGE_GEN_BASE_URL,也没带 SUB2API_BASE_URL, 于是 imagegen.py 回落到公网 sub2.diante.me,而它不在 Tinyproxy 白名单里,API 调用 403 Filtered。 修法:worker 在写 MCP env 前用 imagegen.build_mcp_env 算好 base(显式 IMAGE_GEN_BASE_URL > SUB2API_BASE_URL),并把 网关 host 加进 NO_PROXY;组装逻辑抽成可单测 helper,新增 2 项回归测试(本地网关解析、显式 base 优先)。
This commit is contained in:
1 parent
da7b8e3a4f
commit
7a920cee59
3 files changed
+68
-16
No files matched your search
+10
-16
@@ -2906,22 +2906,16 @@ class Worker:
|
||||
# 未配 IMAGE_GEN_API_KEY 时仍写 base/model,工具会
|
||||
# 明确报“未配置”;绝不把任务自己的分组 2 key 塞进来。
|
||||
try:
|
||||
imagegen_env = dict(proxy_env) if proxy_env else {}
|
||||
for key in ("IMAGE_GEN_BASE_URL", "IMAGE_GEN_API_KEY",
|
||||
"IMAGE_GEN_MODEL"):
|
||||
if os.environ.get(key):
|
||||
imagegen_env[key] = os.environ[key]
|
||||
base = (os.environ.get("IMAGE_GEN_BASE_URL", "")
|
||||
or os.environ.get("SUB2API_BASE_URL", ""))
|
||||
host = base.split("://", 1)[-1].split("/", 1)[0]
|
||||
host = host.split(":", 1)[0]
|
||||
no_proxy = imagegen_env.get("NO_PROXY", "")
|
||||
parts = [p for p in no_proxy.split(",") if p]
|
||||
for item in ("localhost", "127.0.0.1", host):
|
||||
if item and item not in parts:
|
||||
parts.append(item)
|
||||
imagegen_env["NO_PROXY"] = ",".join(parts)
|
||||
imagegen_env["no_proxy"] = ",".join(parts)
|
||||
# env 组装在 imagegen.build_mcp_env 里(可单测):
|
||||
# base 必须在这里算好写进 MCP env,MCP 进程只读
|
||||
# config.toml 里的 env,看不到 worker 的
|
||||
# SUB2API_BASE_URL;不写的话 imagegen.py 会回落
|
||||
# 到公网 sub2.diante.me,而它不在 Tinyproxy
|
||||
# 白名单里,实测 403 Filtered(2026-10-30 首轮
|
||||
# 生产验收即因此失败)。本地网关 origin 优先,
|
||||
# 因为它走 NO_PROXY 直连,不依赖白名单。
|
||||
from cloud.imagegen import build_mcp_env as _build_mcp_env
|
||||
imagegen_env = _build_mcp_env(os.environ, proxy_env)
|
||||
home = self._tenant_dirs(
|
||||
task.get("project_id"))["codex_home"]
|
||||
_ensure_imagegen_mcp_env(home, imagegen_env)
|
||||
|
||||
Reference in new issue
Block a user