feat(proxy): T-P0 代理层骨架(包结构/DDL/门控挂载/单进程校验)

- gateway/proxy/ 十文件:config(ProxyConfig:元->毫元加载期换算 D-P1、差异化售价、
  桶/峰谷/限流/semcache 配置)/ errors(8 类 HTTP 语义异常)/ ledger(四表两索引 DDL,
  WAL,ReviewQueue 连接纪律)/ auth·pricing·normalizer·semcache·upstream(§6 签名占位)
  / routes(/proxy/v1/models OpenAI 形状)/ __init__(build_proxy_router 组装点)
- settings DEFAULTS 增 proxy 段(enabled 默认 False,D-P7)
- api.py 首次 include_router(enabled 门控 + 装配失败不拖垮主应用)
- serve.py workers>1 拒绝启动(D-P9:WEB_CONCURRENCY/UVICORN_WORKERS 校验)
- 测试 +4(门控 404/DDL 幂等/毫元换算/池模型列表),全量 322 passed
This commit is contained in:
tzt
2026-09-05 08:35:31 +08:00
parent 3cc9851623
commit b109576707
15 changed files with 580 additions and 1 deletions
+7
View File
@@ -19,6 +19,13 @@ def start(port: int):
if old:
print(f"已有服务运行 (pid={old}),先执行 --stop 再启动。")
return
# D-P9:代理层(singleflight/令牌桶/内存 LRU)为进程内状态,多 worker 会静默失效
for var in ("WEB_CONCURRENCY", "UVICORN_WORKERS"):
v = (os.environ.get(var) or "").strip()
if v.isdigit() and int(v) > 1:
print(f"拒绝启动:{var}={v}。代理层要求单进程(workers=1),"
"扩容路径见《实施方案_代理层与缓存层.md》D-P9。")
return
out = open(ROOT / "_gateway.out.log", "ab", buffering=0)
err = open(ROOT / "_gateway.err.log", "ab", buffering=0)
flags = 0x00000008 | 0x08000000 # DETACHED_PROCESS | CREATE_NO_WINDOW