feat: G7 分层 fail-open/fail-closed + G8 Docker 轮询掐断 + G9 worker 忽略 host 预算 + G13/G14 归属(第三批)

- G7:认领门 closed 时查配额异常回 quota_check_unavailable、标 interrupted(可重试/续跑);轮询与轮次边界用 open,异常时回 quota_check_failed——新回合边界拒绝,执行中轮询经 _quota_hit 闭包过滤此串、只记 warning 不杀在跑任务,确认超限才掐断;查询函数本身不吞异常冒充不限额。
- G8:Docker 路径加 _docker_call_with_quota_poll(后台线程跑阻塞式 docker 调用,主循环每 quota_poll_interval_seconds 缺省 30 秒查一次,确认超限按容器名真杀容器,结果改写 quota_exceeded 走统一收尾:interrupted、成本照记、续跑消息保留,配额命中后不走 ALREADY_EXISTS 回落);同步路径保持边界检查。
- G9:worker 路径默认忽略 host max_daily_turns(host.py 顶层 --ignore-host-budget 只清该项,Local/Docker 执行器在子命令前追加,worker CLI 缺省开、--no-ignore-host-budget 关);standalone 直接跑 host.py 时预算照常。
- G13/G14:/pr 不再走 system 豁免,建任务前按请求用户查配额(402/503 均不排队不改状态),队列路 pr_jobs.created_by 记请求用户(老表 ALTER 补列),worker 跑 pr 任务时审计操作人用 created_by(老行回落 system)。注意:G14 原案的 system 豁免(服务端与 worker 写死)与 P1 冲突(P1:system 按普通属主走默认额度,不另设无限额系统预算),本次 rebase 未合入该豁免,system 豁免需另行决策。
- 配额口径与 P0/P1 对齐:无配额行按默认额度(非不限额),只有显式 NULL 行才不限额;无价上限只计 source='actual' 行;缺属主(含父任务回查仍无)拒绝新回合。
- README 配额节同步以上口径与 G15 接受现状(best-effort 超支、UTC 月切分、在跑任务只在轮询/轮次边界响应配额改动)。G4 与 G15 不在本批。
This commit is contained in:
host committed 2026-10-28 11:14:10 +08:00
1 parent 5883169c82
commit e31fcc6cba
11 files changed
+786 -176

No files matched your search

+33
View File
@@ -191,6 +191,39 @@ class TaskOptionsTestCase(unittest.TestCase):
"untrusted")
self.assertNotIn("--sandbox", cmd)
# -- G9:worker 路径默认忽略 host 预算 -------------------------------
def test_local_command_ignore_host_budget_flag(self):
seen = []
def fake_runner(cmd):
seen.append(cmd)
return SimpleNamespace(returncode=0, stdout="{}")
ex = LocalExecutor("/fake/host.py", runner=fake_runner,
ignore_host_budget=True)
ex.dispatch_task({"id": "t1", "prompt": "hi"})
cmd = seen[0]
self.assertIn("--ignore-host-budget", cmd)
# 顶层全局参数,必须在子命令之前。
self.assertLess(cmd.index("--ignore-host-budget"),
cmd.index("dispatch"))
ex2 = LocalExecutor("/fake/host.py", runner=fake_runner)
ex2.dispatch_task({"id": "t1", "prompt": "hi"})
self.assertNotIn("--ignore-host-budget", seen[1])
def test_docker_inner_command_ignore_host_budget_flag(self):
ex = DockerExecutor(config_path="/fake/cfg.json",
ignore_host_budget=True)
cmd = ex._inner_host_command("dispatch", "--name", "x",
"--task", "hi")
self.assertIn("--ignore-host-budget", cmd)
self.assertLess(cmd.index("--ignore-host-budget"),
cmd.index("dispatch"))
ex2 = DockerExecutor(config_path="/fake/cfg.json")
cmd2 = ex2._inner_host_command("dispatch", "--name", "x",
"--task", "hi")
self.assertNotIn("--ignore-host-budget", cmd2)
if __name__ == "__main__":
unittest.main()