fix: audit batch 1 (B-A migration audit_loop INTEGER, B-C gateway failure clears running slot)

- B-A: migrations.py tasks backfill loop now types audit_loop as
  INTEGER (other 6 columns stay TEXT), matching db.py backfill,
  server/worker ensure lists; TEXT readback '0' is truthy and
  would silently enable the audit loop for audit_loop=0 rows.
- B-C: gateway preparation failure early-return now calls
  _running_clear(task_id) next to _cleanup_task_seed, matching
  missing-key/repo/capability/tool gates; previously the capacity
  slot leaked until worker exit (default capacity 1 blocks reclaim).
- Tests: cloud/tests/test_audit_batch1.py (3 tests): migration
  ALTER types, INTEGER 0 readback not enabled via real worker
  row mapping, gateway failure clears slot and capacity reclaim.
  _claim doc 'three gates' list left unchanged (full early-return
  gate enumeration not verified this batch; residual wording).
- No other audit items touched (I-1..I-14, N-1..N-12).
This commit is contained in:
host committed 2026-11-04 18:02:22 +00:00
1 parent e3423865aa
commit 44e0f4f1d6
3 files changed
+265 -6

No files matched your search

+15 -6
View File
@@ -221,15 +221,24 @@ def migrate_sqlite_to_postgres(sqlite_path, pg_conn=None, tables=None):
"PRAGMA table_info(tasks)").fetchall()}
except Exception:
_existing = set()
for _col in ("agent_name", "agent_version",
"agent_instructions", "agent_tools",
"agent_tool_approvals", "audit_loop",
"audit_loop_packet"):
for _col, _coltype in (
("agent_name", "TEXT"),
("agent_version", "TEXT"),
("agent_instructions", "TEXT"),
("agent_tools", "TEXT"),
("agent_tool_approvals", "TEXT"),
# 审计循环接线:开关列必须与 db.py 回填清单、
# server/worker ensure 清单一致用 INTEGER;
# 若建成 TEXT,PG 读回的 "0" 为真值,worker
# 的 `or 0` 兜底拦不住,audit_loop=0 的
# 历史任务会被悄悄当成启用(Audit batch 1)。
("audit_loop", "INTEGER"),
("audit_loop_packet", "TEXT")):
if _col not in _existing:
try:
pg_conn.execute(
"ALTER TABLE tasks ADD COLUMN %s TEXT"
% _col)
"ALTER TABLE tasks ADD COLUMN %s %s"
% (_col, _coltype))
except Exception:
pass
if table == "task_followups" and "sender_task_id" in columns: