Files
CyberGril/docs/budget-plan-hel874.md
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

9.3 KiB
Raw Blame History

HEL-874/882 · 真实整体检查执行表(有确定上限,交总管核定)

本表取代 runbook-hel870 §6 的估算口径:**原「约 20–30 次请求 / 100–200 条嵌入」 只是估算,不构成任何批准额度。**HEL-874 本卡零真实模型调用、零出站; HEL-882 勘正:HEL-874 的真实 SDK 验证脚本当时未替换 fastembed 边界, 运行过真实本地嵌入推理(可证下限 12 条,详见 docs/rework/hel874/erratum-hel882.json), 自 HEL-882 起验证边界为确定性 512 维替身 + 禁非回环,零真实嵌入。

三部分各自独立账本与授权来源;超出既有授权的部分由总管向白栖知申请, 批准前对应硬闸保持 cap=0(fail-closed,任何真实工作前拒绝)。 HEL-857 系列冻结余额(真实请求 39/60、嵌入 498/500、HEL-835 闸)不挪用、 不清零、不并入本表任何一部分;换新账本文件绕过冻结会被 verify_ledger_authority 拒绝(HEL-882)。

0. 实测单次开销与入账口径(真实固定 SDK 验证得出,docs/rework/hel874/)

操作 LLM 请求 嵌入条数 说明
Mem0 单行 add(infer) 1 2–3 phase1 查询嵌入 1 + phase3 提取批嵌入 N + phase7 实体 upsert 0..N
Mem0 search 0 1 问答每轮 1 条查询嵌入
失败/取消(HEL-882 口径) 见下 见下 保守入账,不退款
重试上限 每批 ≤3 次 同上×3 预算拒绝不耗次数(重排队等预算);真实错误 3 次后 failed

入账口径(HEL-882 修正,总管独立复现驱动):

  • 发送前预占:所有真实 provider 出口(创建/对话/生活/gist/判定/成长/主动 措辞及 Mem0 内部提取 LLM)在发送前经 PersistentBudget.acquire 原子预占 「请求次数(类别日顶 + 一次性总量)+ 日 token(保守估算)」,任一到顶即 BudgetStop 拒绝——不再降档继续调用;持久落库(token_usage/ request_usage/budget_total),重启不归零、并发不越顶。
  • token 保守性:估算 = 输入字符数 1:1 + 声明的 max_tokens 全额(中英文 两个方向都高估);provider 返回真实 usage 按实际修正(多补少退),未知 usage/断流/失败/取消保守保留全部预占——已发送的成本不当未发生。
  • SDK 隐藏重试已禁用:固定安装内 OpenAI client max_retries=0,每次实际 发送过闸计数;被网关应答过的失败(含 5xx)照实入账,只有可证明未连接 (httpx.ConnectError)才释放预占。
  • 嵌入批次保守性:单条嵌入失败(未产出向量)释放;批次中途失败无法证明 哪些已推理,整批保守落账。
  • Mem0 内部 LLM:独立 llm_ops 累计账(B)+ llm_daily 日顶(C)+ 统一 请求闸(semantic 类别 + 日 token 池,发送前预占)。
  • 未知预占不退款(HEL-885):reserve: 预占行不再按一小时超时清除—— 已发送后崩溃未 settle 的消费事实必须保留;唯一删除路径是可证明未发送的 显式 release()(如 httpx.ConnectError 级未连接)。作业租约过期不是 「未发生」的证明。跨日结算/释放一律按预占凭据的 hold.day 记回原日, 不冲新一天、不产生负用量(token_usage/request_usage 同口径)。

1. A 部分 · 一次性团队整体检查(隔离空库,非用户档案)

用途:统一候选在 8360 隔离实例上按体验链路清单 1–7 全链走一遍(stub 语义, 不激活 Mem0),验证创建→对话→生活→情绪/关系→主动联系→重开同步与隐私负例。

项 次数上限(硬顶)
创建 + 自主诠释 + 初始习惯 4 次请求
对话(含多轮、中断重试) 12 轮 ≤ 16 次请求
生活槽(4 槽)+ 打断/恢复 ≤ 8 次请求
分享判定 / 成长 / gist ≤ 20 次请求(每完成轮 2 条 gist × 最多 8 轮 + 判定/成长若干)
主动联系措辞 ≤ 3 次请求
合计硬顶 55 次请求 / 500,000 tokens / 0 嵌入
  • 硬闸(HEL-882 起为真实硬闸):config/models.yaml budget.total_requests=55 budget.total_tokens=500000(跨日累计,落 budget_total 表)+ 各类别 daily_requests(A 检查当天也受日顶约束,按 C 表或总管核定值)+ daily_tokens。 任一到顶在发送前拒绝(budget_*_exhausted),拒绝如实留证不补发。
  • 授权来源:需总管新批(.11:8731 网关在产品环境的用量不属于 HEL-857 的 60 次实验授权)。

2. B 部分 · 首周后台/语义激活(需白栖知批准后执行)

用途:CYBERGRIL_SEMANTIC=mem0 真实激活,独立新账(embed_ops 续账 + llm_ops 新表),观察提取/检索/原话回读在真实使用中的质量。

项 上限(硬顶)
Mem0 提取 LLM(随公开轮 add) ≤ 60 次(llm_cap)
嵌入(提取批 + 实体 + 查询) ≤ 180 条(embed_cap)
对话/生活/判定等其余 并入 C 部分日账

累计 cap / 保留量算式(HEL-885,写入 config 前照此换算,禁止把增量直接填进累计上限):

权威账现状   :已用 498 条,原批上限 500,冻结不动余额 2 条
新批增量     :白栖知批准的 B 部分嵌入条数(示例 180)
embed_cap    = 500 + 180 = 680      # 原批上限 + 新批增量(≠ 180)
embed_reserve= 2                    # 原冻结余额继续保留,不得消耗
可用余量     = 680 − 498 − 2 = 180
authority    = {prefix_rows: <权威账前N行>, prefix_sha256: <逐行摘要>,
                min_used: 498}      # HEL-885 起任一 cap>0 时必填,缺/空/错即拒绝构造

错误示例:对已用 498 的账把 embed_cap 填成 180(等于瞬间耗尽并掩盖历史用量); 以任何方式消耗旧冻结 2 条(min_used: 498 保证拒绝)。authority 块缺省或 整段注释时,mem0 模式在构造前 fail-closed(ledger_authority_required), 不再是可以跳过的可选项。

  • 硬闸:embed_cap/llm_cap(累计)+ embed_daily/llm_daily(日顶)写入 config/semantic.yaml(默认全 0=拒绝);预占-落账事务制保证并发不越 cap; embed_reserve 预留复测余量;authority 冻结前缀块拒绝新文件绕过 498/500。
  • 碰上限即停:作业批回到 queued(reason=semantic_*_budget_*),不耗重试 次数、不丢行——总管调 cap 后同一批续跑,已完成的行不再重发(向量库逐行 锚点 + sem_row_done 逐行完成记录,HEL-885:每个向量只证明自己那一行, 空提取行同样有完成证明);检索返回空块、对话回落词面 FTS,主对话不中断; 不自动翻页。
  • SDK 吞错已堵住:中途嵌入被预算挡住时 mem0 返回空列表,产品现在识别为预算 拒绝并重排队(不再误写 done/[] 造成永久漏整理)。
  • 授权来源:需白栖知明确批准(提高嵌入上限或另批独立账;现有 498/500 余额 2 条不够任何真实激活,属 HEL-835 未解闸范围)。

3. C 部分 · 用户日常使用(体验地址交付后)

项 日上限(硬顶,建议值交核定)
主对话 + 主动措辞 + 危机 ≤ 60 次/日(类别 dialogue)
生活事件生成(4 槽/天) ≤ 8 次/日(类别 life)
gist/判定/成长(含创建诠释) ≤ 40 次/日(类别 background)
Mem0 提取 LLM ≤ 40 次/日(类别 semantic,llm_daily)
嵌入(全部) ≤ 60 条/日(embed_daily)
tokens 2,000,000/日(daily_tokens)
  • 硬闸(HEL-882):上表全部落 daily_requests/embed_daily/llm_daily/ daily_tokens,发送前原子预占、到顶拒绝、重启不归零;daily_tokens 到 95% 非关键场景仍先降档/停(structured 预检),到顶一律硬停不降档续调; 嵌入/提取到顶只停语义层,主对话可继续(其类别独立计账)。
  • 授权来源:需白栖知批准日预算后才能交付体验地址;首周日用量按本表 B 部分上限受控观察,超限如实记录不补发。

4. 本卡已核实的闸门事实(代码级,测试可复现)

  1. embed_cap=0 / llm_cap=0 / daily_requests.*=0 在任何真实工作前拒绝, 出站为 0(真实 SDK 实测 C5 + tests/test_hard_gates_hel882.py)。
  2. 每次 search 恰好 1 条嵌入记账;并发预占不越 cap(C4/C6)。
  3. 对话同一轮绝不双发(chat_lock + 轮次幂等重放);预算到顶 0 次 provider 调用、如实 chat.error(总管 api 复现已拦住,tests 复现)。
  4. 请求计数与 token 预占持久化,重启不归零(tests 双实例同库复现)。
  5. 语义作业:预算拒绝重排队不耗次数;真实错误 ≤3 次重试;租约回收与向量库 级幂等保证不重发已入库行;stub→mem0 按后端区分覆盖,真实完成批不重发。
  6. SDK 隐藏重试已禁用(max_retries=0),被应答的失败照实入账;只有可证明 未连接的预占才释放(总管 sdk 复现已拦住,tests 复现)。
  7. 主对话 token/请求与语义层独立闸,均发送前预占(含 Mem0 内部 LLM 并入 semantic 类别 + 日 token 池)。