Files
CyberGril/tools/seal_budget_hel879.py
T
zonggongandmultica-agent 01ff919859 HEL-879 release closure: the four HEL-896 audit findings become enforced behavior - (1) archive consistency: tools/release_snapshot_hel896.py v2 checks the wal_checkpoint(TRUNCATE) return (busy!=0 = hard failure, no deliverable tar, half-built dir removed - 'stopped service first' is a precondition, never a reason to ignore an actual failed result), aborts packaging on any source-vs-snapshot table-count mismatch instead of recording rows_match=False and shipping anyway, and verify_archive now rejects legacy packages that recorded rows_match=False while mapping a real rollback drill (unpack to an isolated dir, open every DB, check rows AND hashes against both recorded source and snapshot counts, emit a source-path rollback_plan - no more tar-internal self-attestation); selftest 9/9 reproduces every old failure shape first (naive WAL copy loses companion, held-reader checkpoint=(1,9,8) leaves the copied image malformed/missing the events row, the manager's rows_match=False legacy package verifying ok) then proves each fix (busy fails with zero artifacts, stale-snapshot mismatch fails with zero artifacts, online mode refuses --file dirs containing SQLite by magic-header scan, stop mode recursively takes embedded SQLite like history_root/mem0_public_history.db through checkpoint+per-table verification, verify maps source paths and passes); (2) early-finish seal: PersistentBudget gains sealed()/seal() writing sealed/sealed_requests/sealed_tokens/sealed_at atomically into budget_total beside the real usage (never faking 55, never zeroing), acquire checks the seal FIRST so every category and every remaining allowance rejects budget_sealed:51/55, the marker survives restart and backup-API archive/restore, reseal is idempotent, and there is deliberately no unseal path (re-test = new approval + new instance per budget-package 6.2.4); tools/seal_budget_hel879.py makes the closure an explicit auditable operator command with a post-seal rejection self-check; verify_budget_split_hel896.py gains S6 (51/55 experience chain completes -> seal keeps usage 51 -> 52nd and cross-category rejected with dialogue daily still 19/60 proving it is the seal not the caps, mistaken restart rejected, archive restore rejected, marker requests=51 intact) now 10/10, HEAD made dynamic instead of hardcoded 04eff61; budget-package-hel895.md 6.2 rewritten to the executable seal order (stop -> seal -> consistency snapshot); (3) single install entry: deploy/hel895-release-candidate.md 2 is now the only copy-paste install (uv --offline, npm --offline, cache-miss = stop and record, network only inside an authorized release window with per-item sha256) and 4 is the only fixed-SDK entry as a five-step chain (verify tarball sha256 9dcef930...dda23 against mem0-stack.lock -> build the wheel from the fixed source with hatchling honestly listed as the missing build backend -> cp311 dependency prep with greenlet/pillow/truststore confirmed cache-reusable on re-run -> local-wheels-only --no-index install where mem0ai must come from the fixed-source wheel, the lock line is version-only -> same-process co-import plus the 92MB fastembed cache placement); deploy/hel874-release.md 2/4 carry superseded banners pointing here, mem0-stack.lock no longer routes installs through the index mem0ai==2.2.1 wheel; (4) exact-commit honesty: audit_sdk_offline_hel896.py derives head from git rev-parse and accepts an output dir, fresh evidence written to docs/rework/hel879/sdk-audit/ (hel896 evidence left untouched) recording closure 55 / missing 41 (28 pure + 13 native) / cache-reusable [greenlet, pillow, truststore] / tarball-matches-lock at c121c42; regression on this head: pytest 299/299, ruff clean (src/tests/tools), release-snapshot selftest 9/9, budget-split 10/10 including the new S6 negatives; zero provider calls, zero downloads, authoritative ledgers/freezes/HEL-835 gate untouched, not deployed, PR#11 untouched
Co-authored-by: multica-agent <github@multica.ai>
2026-10-27 03:26:30 +08:00

67 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""HEL-879 · A(团队测试实例)显式封账工具——体验链提前走完时的可执行关闭授权。
总管独立复审复现的失败边界:临时库使用 51/55 → 停服/backup 归档 → 原配置重开
后第 52 次仍 allowed——「走完体验链」与「耗尽 55」并不等价,没有可执行封账。
本工具把关闭授权落成一个显式、可审计的动作(budget-package-hel895.md §6.2):
python3 tools/seal_budget_hel879.py --db /opt/<8360实例>/data/<产品库>.sqlite3 [--reason "体验链走完"]
行为:
- 在该库 `budget_total` 原子写入 sealed/sealed_requests/sealed_tokens/sealed_at;
- 真实用量照实保留(如 51),不伪造 55、不清零、不改其他行;
- 此后该库任何 `PersistentBudget.acquire` 在发送前抛 `budget_sealed:<used>/<cap>`,
跨重启、跨 backup API 归档/快照恢复同样拒绝(负例见
`tools/verify_budget_split_hel896.py` S6);
- 无解除封账的代码路径:团队复检 = 新批准 + 新实例/新库(§6.2.4)。
封账顺序:先停服 → 跑本工具 → `tools/release_snapshot_hel896.py` 一致性快照
(封账标记随库一同归档)。本工具只写上述 4 行标记,零 provider 调用、零网络。
"""
from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cybergril.life.model import PersistentBudget # noqa: E402
from cybergril.memory.store import Store # noqa: E402
from cybergril.think.budget import BudgetConfig, BudgetGuard, BudgetStop # noqa: E402
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument("--db", required=True, type=Path, help="团队实例产品库路径")
ap.add_argument("--reason", default="", help="封账原因(记录在交付评论,不写入库)")
args = ap.parse_args()
if not args.db.is_file():
print(json.dumps({"ok": False, "error": f"库不存在:{args.db}"}, ensure_ascii=False))
return 1
store = Store(args.db, init=False)
guard = PersistentBudget(store, BudgetGuard(BudgetConfig()))
before = guard.total_requests_used()
marker = guard.seal()
# 自检:封账后 acquire 必须被拒且不落账(拒绝路径在任何写入之前)。
try:
guard.acquire("dialogue_main", tokens=1)
rejected, message = False, "allowed(封账失效!)"
except BudgetStop as exc:
rejected, message = True, str(exc)
after = guard.total_requests_used()
ok = (marker["requests"] == before == after and rejected
and message.startswith(f"budget_sealed:{marker['requests']}"))
print(json.dumps({"ok": ok, "db": str(args.db), "reason": args.reason,
"sealed_marker": marker, "real_usage_preserved": before == after,
"post_seal_acquire": message}, ensure_ascii=False, indent=1))
store.close()
return 0 if ok else 1
if __name__ == "__main__":
raise SystemExit(main())