Files
CyberGril/docs/budget-plan-hel874.md
T
zonggongandmultica-agent e291058754 HEL-882 rework: execution-table caps become real hard gates at the wire, SDK hidden retries and mid-add failures recover without loss, the 8360 release package runs offline, and the HEL-874 embedding evidence is corrected - every real provider exit (create/dialogue/life/gist/judgment/growth/proactive phrasing + mem0's internal extraction LLM) now persistently pre-allocates request count (per-category daily + one-shot totals in request_usage/budget_total, BEGIN IMMEDIATE) and a conservative token estimate before sending, refuses at the tightest cap (BudgetStop, no more downgrade-and-keep-calling) and survives restarts; known usage settles to actual, unknown/disconnect/failure keeps the full reservation; ledger guards gain per-day tops (embed_daily/llm_daily) and verify_ledger_authority rejects a fresh file bypassing the frozen 498/500 prefix; the mem0 SDK client's hidden OpenAI retries are disabled (max_retries=0) so every actual send is gated and answered failures (even 5xx) settle as used with only httpx.ConnectError-grade unsent requests released; embed refusals the SDK swallows into empty adds are re-raised as budget errors so the batch re-queues without burning an attempt and resumes when the cap returns, add_group resumes at vector-store level (src_group anchors: only missing rows resent, crash/restart/concurrency never duplicate), sem coverage is per-backend (stub batches no longer block a real rebuild, real done batches never resend) with backend-scoped batch keys; the release package is offline-executable: fresh-dir git clone, cybergril service account, PYTHONPATH in the unit so the lock-only venv imports the product, shipped caps explicitly 0 (=refuse by design until approved), deploy/mem0-stack.lock + accurate 3.11 wheel gap with a no-download path (hel857-venv is 3.10; never present stub/FTS as the real memory experience), and tools/check_release_offline_hel882.py verifies checkout/import/health/fail-closed/approved-run/data-preservation on loopback with echo stand-ins; evidence corrected per manager review: docs/rework/hel874/erratum-hel882.json + README appendix record that e978e87's verification did real local embeddings from cache (provable lower bound 12, exact total unrecoverable, temp sandbox gone) while zero-real-LLM/zero-download/zero-outbound stand, old JSONs and authoritative ledgers untouched, and tools/verify_mem0_real_hel874.py now installs the deterministic 512-dim stand-in before TextEmbedding construction plus non-loopback socket rejection (zero model loads) with final_embed_rows persisted before temp cleanup; verification: 272 python tests pass on 3.11.16 venv + requirements.lock offline (16 new: manager api repro blocked with 0 provider calls, sdk repro 1-HTTP/max_retries=0/llm_ops=1, mid-add swallow requeued-then-resumed, resume-no-duplicate, stub-to-mem0 rebuild, daily embed cap, unified mem0-LLM gate, authority refusal, restart-persistent counters, tightest-constraint settle/release), ruff clean (src/tests/tools), web tsc + 42 vitest + build via npm ci --offline, pinned-install deterministic re-run 12/12, manager review scripts re-run evidence attached in delivery, dual-target requirement checks 4/4 with handoff-HEL-882.json; zero real calls, 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-26 23:20:18 +08:00

117 lines
7.7 KiB
Markdown
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.
# 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 池,发送前预占)。
## 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 部分日账 |
- 硬闸:`embed_cap`/`llm_cap`(累计)+ `embed_daily`/`llm_daily`(日顶)写入
config/semantic.yaml(默认全 0=拒绝);预占-落账事务制保证并发不越 cap;
`embed_reserve` 预留复测余量;`authority` 冻结前缀块拒绝新文件绕过 498/500。
- 碰上限即停:作业批回到 `queued`(reason=`semantic_*_budget_*`),**不耗重试
次数、不丢行**——总管调 cap 后同一批续跑,已入库的行不再重发(向量库级
幂等);检索返回空块、对话回落词面 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 池)。