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>
This commit is contained in:
co-authored by
multica-agent
parent
59fb06304f
commit
78b6267d3a
@@ -99,13 +99,15 @@ class FakeLlm:
|
||||
|
||||
class FakeMemory:
|
||||
instances = []
|
||||
_seq_counter = 0 # unique entry ids across instances (restart-safe, like UUIDs)
|
||||
|
||||
def __init__(self, embedder, collection):
|
||||
self.embedding_model = embedder
|
||||
self.vector_store = _FakeVectorStore()
|
||||
self.llm = FakeLlm()
|
||||
self.collection = collection
|
||||
self.seq = 0
|
||||
FakeMemory._seq_counter += 1
|
||||
self.seq = FakeMemory._seq_counter
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config):
|
||||
@@ -146,13 +148,36 @@ def _sys_modules():
|
||||
|
||||
|
||||
def _make_ledger(path):
|
||||
"""Test ledger with a synthetic authority prefix row (HEL-885).
|
||||
|
||||
The seeded row is deliberately an UNCOUNTED kind with 0 items, so guard
|
||||
``used()`` stays 0 — it only anchors the file identity for the required
|
||||
``authority`` block (product defaults are NOT relaxed; tests must hand the
|
||||
backend an explicit synthetic authority, per the HEL-885 review).
|
||||
"""
|
||||
conn = sqlite3.connect(str(path))
|
||||
conn.execute("CREATE TABLE embed_ops (id INTEGER PRIMARY KEY AUTOINCREMENT, ts TEXT, pid INTEGER,"
|
||||
" kind TEXT, items INTEGER, note TEXT)")
|
||||
conn.execute(
|
||||
"INSERT INTO embed_ops(ts,pid,kind,items,note) VALUES"
|
||||
"('2026-01-01T00:00:00Z',1,'authority_prefix',0,'authority:synthetic-test-prefix')")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def synthetic_authority(ledger_path, *, prefix_rows: int = 1, min_used: int = 0) -> dict:
|
||||
"""Explicit synthetic authority over a test ledger's frozen prefix."""
|
||||
import hashlib
|
||||
|
||||
rows = sqlite3.connect(str(ledger_path)).execute(
|
||||
"SELECT ts,pid,kind,items,note FROM embed_ops ORDER BY id LIMIT ?",
|
||||
(prefix_rows,),
|
||||
).fetchall()
|
||||
digest = hashlib.sha256(
|
||||
"\n".join("|".join(str(c) for c in row) for row in rows).encode()).hexdigest()
|
||||
return {"prefix_rows": prefix_rows, "prefix_sha256": digest, "min_used": min_used}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_mem0(monkeypatch, tmp_path):
|
||||
ledger_path = tmp_path / "ledger.sqlite3"
|
||||
@@ -197,6 +222,10 @@ def backend_for(tmp_path, fake_mem0, *, embedder=None, **overrides):
|
||||
"llm_cap": 10,
|
||||
}
|
||||
config.update(overrides)
|
||||
if config.get("embed_cap", 0) > 0 or config.get("llm_cap", 0) > 0:
|
||||
# HEL-885: positive caps REQUIRE an explicit (synthetic) authority —
|
||||
# the product default refuses without one; tests never relax that.
|
||||
config.setdefault("authority", synthetic_authority(config["ledger_path"]))
|
||||
# each backend wraps a fresh embedder, exactly like real from_config instances
|
||||
sys.modules["mem0"]._TEST_EMBEDDER = embedder or FakeEmbedder()
|
||||
return Mem0Backend(config)
|
||||
|
||||
Reference in New Issue
Block a user