round-12: migrate P8 registries + P12 audit to AppStateStore

- app_state.py: host_state_db_path() (host-level DB, distinct from
  per-VM state_db_path); kv_get/kv_put/kv_delete on meta (namespaced
  keys; kv_put skips the no-secrets guard by design — registry docs
  hold user prompts, documented); audit_trail table (P12 record
  shape + hash chain, seq explicit); counts()/backup() gain
  audit_trail.
- swarm.py / presentation.py / browser_tasks.py: JSON-file backends
  replaced by KV rows (p8-swarm / p8-ledger / p8-browser-tasks);
  legacy JSON imported once on first load (renamed .migrated);
  corrupt row / unreadable store returns empty (fail-safe, same
  semantics as before; next successful save self-heals).
- audit_trail.py: StoreAuditTrail (same record shape, hash chain,
  filters, export as JSONL version, backed by audit_trail table);
  migrate_jsonl_to_store() moves a chain verbatim (broken chain
  refused, divergent seq refused, re-run idempotent). JSONL class
  kept for reading old files.
- P12 dict contracts now run against real P3/P5 code
  (ApprovalQueue.record -> build_approval_card ->
  card_matches_channel; CapabilityIssuer.issue -> describe ->
  PermissionRegistry.record_grant).
- P6->P3 local protocol test: real PrivsepClient + real worker
  server + real git status; worker git argv carries the real P3
  helper + useHttpPath; no token in argv/env/audit. runuser + HTTP
  pull stay real-machine-only (see gap docs).
- Gap docs updated: P8 migration done, guest-side browser follow-up
  explicitly left for the real-machine track (no task_id in the
  browser protocol yet; lifecycle needs a real VM to verify);
  P6 wiring + P12 migration marked done; production-readiness.md
  gains §20 (round-12 integration).
- Tests: new cloud/tests/test_chv_muse_round12.py, 24/24 OK;
  test_chv_muse_p8.py ledger corrupt test rewritten for the KV
  backend (+ legacy-import test). P7+P8: 95+1 tests OK.
This commit is contained in:
host committed 2026-11-07 00:36:25 +00:00
1 parent 466cf7eae7
commit d4cef29cdb
11 files changed
+1147 -63

No files matched your search

+43
View File
@@ -1040,3 +1040,46 @@ auditd 审计、与 P3 authd/Sentinel 的真接线)。
- 真机待验证:真实 token 回传下的月度累计与 402、真实多任务下的并发门、
真实 worktree 下的存储门、提醒只发一次、账本并发写不断链。
## 20. 对齐 Muse round-12 集成:P4~P12 合入(分支 feat-chv-muse-round12)
- 合入顺序与提交:P4 c24cc0b → P5 d1c9a8e → P6 b0b9f5e → P7 320cd36 →
P8 240949e → P9 90c42f6 → P10 b55b49b(acf98f8 的 cherry-pick,只含
P10 自有 diff,基线已含的 P3/P5 未重复合)→ P11 77743e7 → P12
466cf7e。基线 round-11 HEAD 29d3a5a。
- 冲突处理(逐项):① executor.py:P9 的 `_inference_gate` 插到 P1
分发器 `_run_with_vm` 之前,gate 调用为分发器第一条语句(deny/ask
在常驻 resume 与冷启动 wake 之前 fail-closed);P9 自己的旧版本
`_run_with_vm` 丢弃——其本体与 P1 `_run_cold` 逐字节相同(P1 的
verbatim 搬运),合入时一度误删 `_run_cold` 体致 dispatch 回 None,
已从 HEAD 原样恢复并由测试钉住;sentinel.py 取 P9 超集版。
② build.sh/buildinfo.py:按 hunk 合,authd 三件套 + P2 三件套 +
P4 三文件 + P7 chv-memory 全在 contents 里,GT 哈希仍为已批准的
49ffe090…。③ docs §15 撞号:P4→§16、P6→§17、P7→§18、P11→§19,
顺序顺延,无覆盖。④ P4 弄坏的 P2 测试改走假 CDP broker,断言不变。
- AppStateStore 迁移(本轨做完):P8 三处登记(swarms.json /
notification-ledger.json / browser-tasks.json)迁到宿主级库
`state_dir/app-state.sqlite`(`host_state_db_path`,与 per-VM 库
同库不同文件),命名空间 `p8-swarm` / `p8-ledger` /
`p8-browser-tasks`,一行存整份文档;旧 JSON 首次加载自动导入并改名
`.migrated`;KV 行损坏回空 fail-safe。P12 审计 JSONL 迁到
`audit_trail` 表(`StoreAuditTrail`,同一记录形状与哈希链),
`migrate_jsonl_to_store()` 原样搬链(坏链拒绝、分叉拒绝、重跑幂
等);JSONL 版保留读旧文件,新写一律走 Store 版。`kv_put` 不过
无凭证守卫(登记文档含用户 prompt,见 app_state.py 注释)。
- 接线验证(本轨,本地):P6 worker→P3 helper/authd→git 跑通真
PrivsepClient + 真 worker server + 真 git status(argv 含真实
helper 与 useHttpPath,argv/env/审计不含 token;runuser 与 HTTP
拉取留给真机);P12 审批卡吃真实 P3 `ApprovalQueue.record()`、
权限登记吃真实 P5 `ScopedCapability.describe()`,均已用真实代码
跑通,不再用替身。
- 未决与留给真机轨:① P11 冲突原样保留(档位门只做准入、USD 路径
不动,等用户裁决,见 `docs/chv-muse-p11-gap.md` §5)。② P8 客机
侧跟进未做(`chv-browser.py` 请求协议无任务 id 字段、进程拉起/
销毁须真机验证,见 `docs/chv-muse-p8-gap.md` §3)。③ 真机验证排
在 round-11 之后:P1 常驻/balloon/vsock、P2 §5 九项否定测试、
P3 §3.6 五项、P4/P5/P6/P7/P8/P9/P10/P11/P12 各自差距表 §6 清单、
以及本轨新增的迁移后真机表现(旧 JSON 一次导入、Store 审计链
在 VM 生命周期下的追加)。
- 测试:新增 `cloud/tests/test_chv_muse_round12.py` 24 项全过;
全量 cloud 套件见合入提交说明(每次合入后跑相关测试,最终全量
一次跑通才算完)。