feat(cfg): 步骤4 收尾两针——两 Service 入口接热源工厂(旗默认关=字节不变)+ genconfig __main__ 自检块期望值随单源现值修正(50.0/60,阈值批 bfeaea2d 漏改自检块)
Some checks failed
contract-gates / contract-gates (push) Has been cancelled
docs-gate / docs-gate (push) Has been cancelled

入口接线:tier2 service/app.py:main 与 cheap_service_app.py:main 对称各调 build_and_attach_hot_source(tier=...),
工厂自带启用旗(TIER2_GENCONFIG_NACOS 默认关)+ best-effort,无条件调不再包旗;两档各订各 dataId 不串档。
验证:tier2 126 passed / cheap-worker 339 passed 1 skipped / genconfig 自检块全 OK / py_compile 两入口过。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
lili 2026-07-04 09:23:20 -07:00
parent 344330a48c
commit d9def7d901
3 changed files with 19 additions and 4 deletions

View File

@ -414,6 +414,13 @@ def main() -> None:
host = os.environ.get("CHEAP_SERVICE_HOST", "0.0.0.0")
port = int(os.environ.get("CHEAP_SERVICE_PORT", "8300"))
print(f"[cheap-service] 启动 Agent Service:http://{host}:{port}", flush=True)
# genconfig 热源接线(配置控制面阶段二·步骤4,与 tier2 service/app.py:main 对称):TIER2_GENCONFIG_NACOS=1
# 才启用,默认关 = 行为字节不变。工厂自带启用旗判断 + best-effort(失败只告警不抛、不 attach),订阅
# cheap 档 dataId(gen-hot-params-cheap)——与 tier2 各进程各热源,天然不串档(worker.genconfig 注释详解)。
from worker import genconfig_nacos # noqa: PLC0415 —— 惰性 import,默认关时不牵 nacos 依赖
genconfig_nacos.build_and_attach_hot_source(tier="cheap")
uvicorn.run(build_cheap_app(), host=host, port=port)

View File

@ -314,6 +314,12 @@ def main() -> None:
from . import nacos_registry # noqa: PLC0415 —— 惰性 import,默认关时不牵 nacos 依赖
nacos_registry.register(host, port)
# genconfig 热源接线(配置控制面阶段二·步骤4):TIER2_GENCONFIG_NACOS=1 才启用,默认关 = 行为字节不变。
# 工厂自带启用旗判断 + best-effort(Nacos 不可达只告警不抛),故此处无条件调、不再包旗;订阅 tier2 档
# dataId(gen-hot-params-tier2),软预算/门阈值经 genconfig 数秒热读、不重启。
from worker import genconfig_nacos # noqa: PLC0415 —— 惰性 import,默认关时不牵 nacos 依赖
genconfig_nacos.build_and_attach_hot_source(tier="tier2")
if reload:
# reload 模式必须传 import 字符串(uvicorn 要能在 worker 子进程重导入);指向本模块的 module-level `app`。
# 子进程重导入 service.app 时,module-level `app` 只在 TIER2_SERVICE_EAGER_APP=1 时才建——故在此

View File

@ -421,9 +421,11 @@ if __name__ == "__main__": # pragma: no cover —— 本地自测
reload()
os.environ.pop("TIER2_GENCONFIG", None)
_check("内置默认 model.max_tokens", get("model", "max_tokens", 16000), 16000)
_check("内置默认 budget.rmb_hard_limit", get("budget", "rmb_hard_limit", 3.0), 3.0)
# 期望值锚当前单源现值(YAML/内置):rmb_hard_limit 裁决 ¥50(0号 spike 占位 3.0 已废)、
# writer_max_iters 60(2026-07-04 创始人阈值批 40→60)。改单源必须同步这里,否则自测块先失真。
_check("内置默认 budget.rmb_hard_limit", get("budget", "rmb_hard_limit", 3.0), 50.0)
_check("内置默认 model.thinking_enable(bool)", get("model", "thinking_enable", True), True)
_check("内置默认 iteration.writer_max_iters", get("iteration", "writer_max_iters", 40), 40)
_check("内置默认 iteration.writer_max_iters", get("iteration", "writer_max_iters", 40), 60)
# ② 调用方 default 兜底:内置默认未登记的 key → 返回 default。
_check("未登记 key 回落 default", get("model", "不存在的key", 999), 999)
@ -437,7 +439,7 @@ if __name__ == "__main__": # pragma: no cover —— 本地自测
_check("env 覆盖 bool=false", get("model", "thinking_enable", True), False)
# env 非法值 → 忽略、回落内置默认(不变 None)。
os.environ["TIER2_GEN__ITERATION__WRITER_MAX_ITERS"] = "abc"
_check("env 非法值回落默认", get("iteration", "writer_max_iters", 40), 40)
_check("env 非法值回落默认", get("iteration", "writer_max_iters", 40), 60)
for k in ("TIER2_GEN__ITERATION__WRITER_MAX_ITERS", "TIER2_GEN__BUDGET__RMB_HARD_LIMIT",
"TIER2_GEN__MODEL__THINKING_ENABLE"):
os.environ.pop(k, None)
@ -452,7 +454,7 @@ if __name__ == "__main__": # pragma: no cover —— 本地自测
_check("YAML 改值流通 model.max_tokens", get("model", "max_tokens", 16000), 24000)
_check("YAML 改值流通 budget.rmb_hard_limit", get("budget", "rmb_hard_limit", 3.0), 2.0)
# YAML 没写的 key 仍回落内置默认(= 现值)。
_check("YAML 未写 key 回落内置默认", get("iteration", "writer_max_iters", 40), 40)
_check("YAML 未写 key 回落内置默认", get("iteration", "writer_max_iters", 40), 60)
os.environ.pop("TIER2_GENCONFIG", None)
os.unlink(tmp_path)
reload()