fix: third-audit gate findings (explicit split, shadow explicit failures, N2-N5, N1 note)

Explicit gateway capability now splits known/unknown: known-missing
explicit models fail-fast under active (same shape as the gateway
default gate), unknown explicit models stay audit-only, shadow never
blocks; explicit priority now protects which model the user chose,
not that the chosen model must run. Shadow report reads
worker_capability_gateway_explicit rows as explicit_capability_failures
with a field note distinguishing the three explicit counts.
N2: coordinator requeue CAS rowcount=0 branch covered via a proxy
connection test (no refactor needed). N3: shadow endpoint test on
the create_server + real HTTP skeleton (capability, truncated, and
explicit-failure fields). N4: creation-layer rejection tests for
tools/instructions/tool_approvals on goal/coordinator tasks.
N5: model writeback failure logs a warning (best-effort kept).
N1: writeback capability-recheck trade-off documented in comment
only; recheck itself is a later batch.
This commit is contained in:
host committed 2026-11-04 18:02:21 +00:00
1 parent 621c08d10f
commit 18e3f1c82d
5 files changed
+660 -21

No files matched your search

+59
View File
@@ -4195,6 +4195,20 @@ class CloudControlPlaneHandler(BaseHTTPRequestHandler):
).fetchall()
truncated = len(audit_rows) > 10000
audit_rows = audit_rows[:10000]
# Audit fix 4(第三遍审计显式闭环):显式能力检查
# 结果只记 worker_capability_gateway_explicit,影子
# 端点此前只读 worker_routing,运营方根本看不到它。
# 在此之外加读显式行,附为独立字段,不与已有两个
# explicit_n 口径混在一起(见报告里的字段说明)。
explicit_rows = conn.execute(
"SELECT detail FROM audit_log"
" WHERE project_id = ?"
" AND action = 'worker_capability_gateway_explicit'"
" ORDER BY created_at, id LIMIT 10001",
(project_id,),
).fetchall()
explicit_truncated = len(explicit_rows) > 10000
explicit_rows = explicit_rows[:10000]
task_rows = conn.execute(
"SELECT id, status, model FROM tasks"
" WHERE project_id = ?",
@@ -4229,6 +4243,51 @@ class CloudControlPlaneHandler(BaseHTTPRequestHandler):
tasks_by_id, costs_by_task, explicit_n=explicit_n)
report["project_id"] = project_id
report["truncated"] = truncated
# 显式失败清单:解析 worker_capability_gateway_explicit
# 行(格式:task_id model=.. tier=.. mode=.. missing=..
# unknown=.. blocked=..;fix4 之前的行无 blocked 项,
# 按 False 计)。这与报告里两个 explicit_n 不同义:
# 顶层 explicit_n 是任务表里带模型字段的任务数;
# per-tier explicit_n 是 worker_routing source=explicit
# 审计行数;本字段只计网关显式能力检查的结果行,
# 含被拦的已知不满足与只审计的 unknown,blocked
# 字段区分两者。解析失败的行直接跳过、不谎报。
_explicit_failures = []
for _row in explicit_rows:
_detail = _row["detail"] or ""
_tokens = _detail.split()
if not _tokens:
continue
_kv = {}
for _tok in _tokens[1:]:
if "=" in _tok:
_k, _v = _tok.split("=", 1)
_kv[_k] = _v
if "model" not in _kv or "tier" not in _kv:
continue
_missing = _kv.get("missing") or "-"
_explicit_failures.append({
"task_id": _tokens[0],
"model": _kv["model"],
"tier": _kv["tier"],
"mode": _kv.get("mode") or "-",
"missing": [] if _missing == "-" else _missing.split(","),
"unknown": _kv.get("unknown") == "True",
"blocked": _kv.get("blocked") == "True",
})
report["explicit_capability_failures"] = _explicit_failures
report["explicit_capability_failures_truncated"] = \
explicit_truncated
report["explicit_counts_note"] = (
"explicit_n (top level) counts tasks whose model field is"
" set in the tasks table; per-tier explicit_n counts"
" worker_routing rows with source=explicit; "
"explicit_capability_failures lists"
" worker_capability_gateway_explicit rows only, i.e."
" gateway capability check outcomes for explicit models,"
" with blocked=True for known-missing models that were"
" refused and blocked=False for unknown models that were"
" audited but not blocked.")
# Audit fix 3(I2,端点侧):只读加载当前策略,
# 给每档附能力状态(档模型 vs requires)。加载
# 失败/未配置时状态为 policy_unavailable,不拦、