feat: cloud 门禁/超时/成本/沙箱收敛为单一判定源

- 新增标准库叶子层 timeouts/gates/quota/sandbox_policy:
  审批 3600 与单轮 600 各有名常量与环境覆盖层,已建项
  expires_at 永不重算;目录/控制/合并状态门禁统一判定,
  目录违规无任何覆盖参数;配额取数与比较唯一来源
  (USD 先于无价、命中均为 >=、无价只计 actual 行);
  /tmp 隔离矩阵与失联清理判定纯函数化。
- 调用点委托:server/worker/automations/auto_memory 的
  配额 SQL 与比较、server/tree/marker 的目录解析、
  marker 的控制门、sandbox 的任务容器名正则、两处 300 秒
  陈旧阈值默认值均收敛,别名与错误文案不变。
- 统一两个 P0 口径分歧:服务端无价计数由全部 usd IS NULL
  行改为 actual-only;显式不限额用户在服务端准入亦不受
  无价上限约束(与 worker 运行时一致)。
- 不新增门禁种类与 record 模式(主线无此实现);不改
  skill_seed/skills/SKILL.md;不改 v1.1 契约与分支保护。
- 新增 test_arch_converge.py 18 项。
This commit is contained in:
host committed 2026-11-04 20:54:50 +00:00
1 parent 17fa493da7
commit facc2a249a
16 files changed
+1070 -301

No files matched your search

+18 -16
View File
@@ -64,19 +64,24 @@
- item/tool/call 与 account/chatgptAuthTokens/refresh:前者是
动态工具执行,后者是凭证刷新,都不是用户审批,排除。
本模块只依赖标准库,不 import cloud 其他模块,避免循环
import;服务端与未来 worker/hook 共用。占位符用 ?,建表与
列补齐写法与 peer_messages 同款(db 适配层负责翻译)。
本模块只依赖标准库与同为标准库叶子的 cloud.timeouts,
不 import 其他 cloud 模块,避免循环 import;服务端与未来
worker/hook 共用。占位符用 ?,建表与列补齐写法与
peer_messages 同款(db 适配层负责翻译)。
"""
import json
import time
import uuid
from cloud.timeouts import APPROVAL_DEFAULT_SECONDS as _APPROVAL_DEFAULT
from cloud.timeouts import expires_at_for as _expires_at_for
from cloud.timeouts import resolve_module_timeout as _resolve_timeout
KINDS = ("elicitation", "command", "file_change", "permissions",
"user_input")
DECISIONS = ("approved", "denied")
DEFAULT_TIMEOUT_SECONDS = 3600
DEFAULT_TIMEOUT_SECONDS = _APPROVAL_DEFAULT
MAX_SUMMARY_CHARS = 2000
MAX_DETAIL_CHARS = 20000
@@ -167,12 +172,15 @@ def approval_to_dict(row):
def create_approval(conn, task_id, project_id, kind="elicitation",
summary="", detail=None, requested_by=None,
timeout_seconds=DEFAULT_TIMEOUT_SECONDS, now=None):
timeout_seconds=None, now=None):
"""创建一条待审批项,返回 dict。非法输入抛 ValueError,
调用方据此回 400;成功时 commit。
timeout_seconds:None 用默认值;0 表示不过期(只允许
模块级调用,服务端入口另有限制);负数非法。"""
timeout_seconds:None 用默认值(cloud/timeouts.py 的
环境变量感知默认值,未设环境变量时为 3600;签名默认
故意写 None 而不是 3600,避免默认值在 import 时绑定死、
环境覆盖层传不进去);0 表示不过期(只允许模块级调用,
服务端入口另有限制);负数非法。"""
if kind not in KINDS:
raise ValueError("kind must be one of: " + ", ".join(KINDS))
if not isinstance(summary, str) or not summary.strip():
@@ -180,17 +188,11 @@ def create_approval(conn, task_id, project_id, kind="elicitation",
summary = summary.strip()
if len(summary) > MAX_SUMMARY_CHARS:
raise ValueError("summary too long")
if timeout_seconds is None:
timeout_seconds = DEFAULT_TIMEOUT_SECONDS
if not isinstance(timeout_seconds, (int, float)) \
or isinstance(timeout_seconds, bool) \
or timeout_seconds < 0:
raise ValueError("timeout_seconds invalid")
# 不传 default:None 时走 timeouts 的环境变量感知默认值。
timeout_seconds = _resolve_timeout(timeout_seconds)
detail_str = _detail_to_str(detail)
now = time.time() if now is None else now
expires_at = None
if timeout_seconds:
expires_at = now + timeout_seconds
expires_at = _expires_at_for(now, timeout_seconds)
item_id = uuid.uuid4().hex
ensure_approvals_table(conn)
conn.execute(