Files
CyberGril/docs/rework/hel885/review_hel882_extra.py
T
zonggongandmultica-agent 78b6267d3a HEL-885 rework: per-row progress matches what was really sent, cross-day and unknown-outcome accounting stay conservative, positive caps require the ledger authority, and the release dependency-fill command actually exists - every Memory.add now carries an anchor for exactly its own row (the HEL-882 whole-batch anchor let the first stored vector mark unsent rows complete; the manager's real-SDK partial reproduction showed the user's original words never leaving the process), a row finishing with a legitimately EMPTY extraction gets a durable sem_row_done record (r4.sql additive table) written inside the worker thread the moment its add completes, resume skips = vector-store anchors ∪ sem_row_done so no row is lost, none falsely complete, and finished work is never re-sent across budget-refusal/crash/restart/lease/concurrency, entry_ids merge across partial attempts, and the swallowed-failure detection is per-row; PersistentBudget.settle/release book on hold.day (the old write to state.day manufactured -80 used on the new day and re-opened headroom the reservation day had already spent; token_usage/request_usage refund the paying day, budget_total stays global) and the empty-budget_total TypeError crash in total_requests_used/total_tokens_used is fixed - the old one-shot-total test passed only because that crash surfaced as chat.error, it now books the total honestly; _atomic_reserve no longer purges aged reserve: rows (a crashed worker's hold is an UNKNOWN outcome - an hour-old timeout is not proof the call never happened; unknown consumption stays billed across restarts, only a provably-unsent release() ever removes a hold, embed_ops and llm_ops share the fix); Mem0Backend refuses construction before importing mem0 when any cap>0 lacks a (non-empty dict) authority block - ledger_authority_required - or when the prefix check fails, closing the fresh-empty-ledger bypass the manager reproduced live, config/semantic.example.yaml ships the authority block as REQUIRED with the explicit cumulative formula (embed_cap=500+approved-increment e.g. 680, embed_reserve=2 frozen untouched, min_used=498; never write 180 as the cumulative cap of a 498-used account) mirrored into docs/budget-plan-hel874.md §2 with the HEL-885 accounting rules; deploy/hel874-release.md §4 replaces the nonexistent uv pip download (rc=2, re-verified) with python3 -m pip download --only-binary :all: --platform manylinux2014_x86_64 --python-version 3.11 --implementation cp --abi cp311 + sha256 manifest + uv pip install --no-index --find-links offline merge + same-process co-import verdict, honest missing-materials list unchanged (no 3.11 wheels cached, zero downloads this card, no version swaps), and tools/check_release_offline_hel882.py gains R7 probing both command surfaces offline; verification: 281 python tests pass on 3.11.16 venv + requirements.lock offline (9 new tests/test_rework_hel885.py cases: partial batch claims only the sent row / empty-extraction row completes and is never resent / process restart sends only the missing row / concurrent ticks never double-send / cross-day settle and release book on the reservation day / aged unknown llm+embed reservations never refunded / missing-empty-malformed-wrong authority all fail closed; test_resume_never_loses_or_duplicates_rows rewritten to drive the REAL product path instead of hand-planting single-row anchors the product never wrote), ruff clean (src/tests/tools), web tsc + 42 vitest + build via npm ci --offline, pinned mem0 2.2.1 install on the deterministic boundary: contract re-run 12/12 (harness now hands a synthetic authority prefix - production defaults not relaxed), new tools/verify_semantic_recovery_hel885.py 7/7 (S0 authority fail-closed, S1 per-row partial with exactly 1 HTTP, S2 restart sends only the missing row proven by HTTP count since mem0 prompts legitimately carry old rows in rolling history, S3 lease recovery + concurrent ticks single-send, S4a/S4b unknown reservations kept), both manager review scripts re-run VERBATIM against this head (partial: completed=[2] only, resume done with 2 entries, HTTP=2, user words actually sent; extra: new-day used=0, over-cap request refused, aged reservation second_allowed=false, uv probe still rc=2), release offline check R1-R7 green, dual-target requirement checks 4/4 with handoff-HEL-885.json; zero real LLM, zero real embeddings, zero non-loopback outbound, authoritative ledgers and freezes untouched, not deployed, PR not merged, no visual changes
Co-authored-by: multica-agent <github@multica.ai>
2026-10-27 00:01:44 +08:00

61 lines
2.5 KiB
Python

"""Independent regressions, temporary ledgers, no provider or remote access."""
import json
import sqlite3
import subprocess
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent
sys.path.insert(0, str(ROOT / 'CyberGril/src'))
from cybergril.life.model import PersistentBudget
from cybergril.memory.store import Store
from cybergril.memory.semantic import LlmLedgerGuard
from cybergril.think.budget import BudgetConfig, BudgetGuard
result = {'head': '59fb06304fb9f230837b43e431e2a1cc303e16c9',
'real_llm_requests': 0, 'real_embeddings': 0}
with tempfile.TemporaryDirectory(dir=ROOT) as td:
tmp = Path(td)
store = Store(tmp / 'midnight.db')
guard = PersistentBudget(store, BudgetGuard(BudgetConfig(
daily_tokens=100, daily_requests={'dialogue': 10})))
guard._roll = lambda: None
guard.state.day = '2026-10-26'
hold = guard.acquire('dialogue_main', tokens=90)
guard.state.day = '2026-10-27'
guard.settle(hold, actual_tokens=10)
used = guard.used
try:
guard.acquire('dialogue_main', tokens=150)
allowed = True
except RuntimeError:
allowed = False
result['midnight_settlement'] = {
'daily_cap': 100, 'old_hold': 90, 'actual': 10,
'new_day_used_before_next_request': used,
'request_estimate': 150, 'over_cap_request_allowed': allowed,
'rows': [dict(r) for r in store.query('SELECT * FROM token_usage')]}
store.close()
ledger = tmp / 'crash.db'
llm = LlmLedgerGuard(ledger, cap=1)
pending = llm.reserve(1, 'sent_but_crashed_before_settlement')
with sqlite3.connect(ledger) as conn:
conn.execute("UPDATE llm_ops SET ts='2000-01-01T00:00:00Z' WHERE id=?", (pending,))
before = llm.used()
try:
second = llm.reserve(1, 'second_send_after_restart')
allowed = True
except RuntimeError:
second, allowed = None, False
result['aged_unknown_reservation'] = {
'cap': 1, 'used_before': before, 'second_allowed': allowed,
'first_hold_id': pending, 'second_hold_id': second,
'used_after': llm.used()}
probe = subprocess.run(['uv','pip','download','--help'], capture_output=True, text=True)
result['release_documented_download_command'] = {
'command': 'uv pip download --help', 'returncode': probe.returncode,
'stderr': probe.stderr.strip()}
(ROOT / 'HEL-882-extra-independent.json').write_text(json.dumps(result, ensure_ascii=False, indent=2))
print(json.dumps(result, ensure_ascii=False, indent=2))