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
@@ -306,3 +306,36 @@ def ensure_imagegen_mcp_env(codex_home_dir, env):
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def build_mcp_env(worker_environ, proxy_env=None):
|
||||
"""Build the [mcp_servers.imagegen.env] dict from worker env.
|
||||
|
||||
The MCP process only sees config.toml env, never the worker's
|
||||
own env, so IMAGE_GEN_BASE_URL must be resolved HERE (worker
|
||||
IMAGE_GEN_BASE_URL, else SUB2API_BASE_URL, else absent and
|
||||
imagegen.py falls back to the public relay domain -- which is
|
||||
NOT on the Tinyproxy whitelist, so a missing base here caused
|
||||
a 403 Filtered in the first production verification, 2026-10-30).
|
||||
proxy_env supplies HTTP(S)_PROXY for downloading the returned
|
||||
image URL; NO_PROXY gains the gateway host for direct API calls.
|
||||
Never injects the task user's gateway key.
|
||||
"""
|
||||
env = dict(proxy_env) if proxy_env else {}
|
||||
for key in ("IMAGE_GEN_BASE_URL", "IMAGE_GEN_API_KEY",
|
||||
"IMAGE_GEN_MODEL"):
|
||||
if worker_environ.get(key):
|
||||
env[key] = worker_environ[key]
|
||||
base = (worker_environ.get("IMAGE_GEN_BASE_URL", "")
|
||||
or worker_environ.get("SUB2API_BASE_URL", ""))
|
||||
if base:
|
||||
env["IMAGE_GEN_BASE_URL"] = base
|
||||
host = base.split("://", 1)[-1].split("/", 1)[0]
|
||||
host = host.split(":", 1)[0]
|
||||
parts = [p for p in env.get("NO_PROXY", "").split(",") if p]
|
||||
for item in ("localhost", "127.0.0.1", host):
|
||||
if item and item not in parts:
|
||||
parts.append(item)
|
||||
env["NO_PROXY"] = ",".join(parts)
|
||||
env["no_proxy"] = ",".join(parts)
|
||||
return env
|
||||
Reference in new issue
Block a user