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>
This commit is contained in:
zonggong
2026-10-27 03:26:30 +08:00
co-authored by multica-agent
parent c121c42e39
commit 01ff919859
13 changed files with 1682 additions and 142 deletions
+54
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import asyncio
import json
import logging
import time
from contextlib import aclosing
from ..contracts import LLMMessage
@@ -61,6 +62,50 @@ class PersistentBudget(BudgetGuard):
)
return row["v"] if row else 0
# ------------------------------------------------------------ 封账(HEL-879)
def sealed(self):
"""封账标记(None=未封)。体验链提前走完时的可执行关闭,跨重启/归档不失效。"""
row = self.store.query_one("SELECT value v FROM budget_total WHERE key='sealed'")
if not row or row["v"] != 1:
return None
def _val(key, default=0):
r = self.store.query_one(f"SELECT value v FROM budget_total WHERE key='{key}'")
return r["v"] if r else default
return {"requests": _val("sealed_requests"), "tokens": _val("sealed_tokens"),
"sealed_at": _val("sealed_at")}
def seal(self):
"""显式封账:把当前真实用量连同时间戳原子写入账本,此后一切 acquire 拒绝。
HEL-879:A(团队测试实例)在额度未耗尽(如 51/55)时体验链走完,没有可执行
的封账就会在重启/归档恢复后放行第 52 次。封账标记与用量同库持久——重启、
backup API 归档、快照恢复后同样生效;真实用量保持 51,不伪造 55、不清零。
幂等:已封账时保留原标记(含原时间戳),不覆盖。解除封账没有代码路径:
复检 = 新批准 + 新实例/新库(budget-package §6.2.4)。
"""
self._roll()
with self.store.conn:
self.store.execute("BEGIN IMMEDIATE")
existing = self.sealed()
if existing is not None:
return existing
marker = {"requests": self.total_requests_used(),
"tokens": self.total_tokens_used(),
"sealed_at": int(time.time())}
self.store.execute("INSERT INTO budget_total VALUES('sealed',1) "
"ON CONFLICT(key) DO UPDATE SET value=1")
self.store.execute("INSERT INTO budget_total VALUES('sealed_requests',?) "
"ON CONFLICT(key) DO UPDATE SET value=excluded.value",
(marker["requests"],))
self.store.execute("INSERT INTO budget_total VALUES('sealed_tokens',?) "
"ON CONFLICT(key) DO UPDATE SET value=excluded.value",
(marker["tokens"],))
self.store.execute("INSERT INTO budget_total VALUES('sealed_at',?) "
"ON CONFLICT(key) DO UPDATE SET value=excluded.value",
(marker["sealed_at"],))
return marker
def reserve(self, tokens, scene):
"""Legacy background-scene token reservation (95% stop), kept for compatibility."""
self._roll()
@@ -85,6 +130,15 @@ class PersistentBudget(BudgetGuard):
day = self.state.day
with self.store.conn:
self.store.execute("BEGIN IMMEDIATE")
# 封账最优先(HEL-879):已显式封账后,任何类别/任何余量都拒绝——
# 提前收尾(如 51/55)与误重启/归档恢复一样不放行。
sealed = self.sealed()
if sealed is not None:
cap = self.config.total_requests
suffix = f"/{cap}" if cap is not None else ""
raise BudgetStop(
f"budget_sealed:{sealed['requests']}{suffix}(封账于 "
f"{sealed['sealed_at']},真实用量保留,不伪造、不清零)")
row = self.store.query_one(
"SELECT coalesce(sum(used),0) n FROM token_usage WHERE day=?", (day,)
)