From df812f38608d896e32b371cf7c004ed376546185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Fri, 9 Oct 2026 18:25:43 -0400 Subject: [PATCH] Correct the p2-4 record against what the reviewer measured MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round one of the p2-4 review found the behaviour sound and the record wrong in eight places. All eight are fixed here, each against a measurement: D1 "compare_digest" was written as if it covered holder tokens. It does not: the store keeps only a sha256 digest, so verify_token is SQL equality; compare_digest guards the operator's plaintext (api_auth.py:54, :110). D2 register_minimal is called at memory.py:94, not :120. D3 the compiler cache key never had an "as_holder or ''" step — the old key had no identity component at all, which is a stronger defect than the one I described. D4 browse.py's own comment said four copies, two here. There are five, three here (:52, :66, :93), which is what test_visibility_rule asserts. D5 the store_search / vector_index line pointers moved with the as_of work. D6 my review prompt said 33 routes; measured 34 decorators / 31 distinct paths at the parent, 38 / 35 at the reviewed commit. D7 the semgrep claim cannot be re-run in this container (neither semgrep nor opengrep is installed), so it is recorded as an observation from the p0-1 gate run, and the anti-drift job is given to the test that does not need that tool. D8 "a holder can only write as itself, now guaranteed by the token" is the opposite of what runs: only the operator writes, attribution comes from default_holder, and the real guarantee is that RememberRequest has no holder field. Four precision notes are recorded too: a revoked token is a hard 401 rather than a downgrade to anonymous, an anonymous caller passing an empty ?holder= gets 403, the capability card also carries newest_memory timestamps and token_issued, and leg_check's commit line is the cwd's HEAD. The p2-3 entry gains the as_of gap the key test exposed, and the final-accept entry now carries the seven measured scenarios with the two reasons it stays open: scenario 7 unmeasured, and recall@10 0.863 against a 0.90 bar. --- CHECKLIST.md | 22 ++++++++++++++++------ backend/src/ely_eye/browse.py | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHECKLIST.md b/CHECKLIST.md index f82474c..286217b 100644 --- a/CHECKLIST.md +++ b/CHECKLIST.md @@ -420,22 +420,24 @@ - **评审第 3 轮 FAIL**(同一独立 pi,8 项全跑,~534 工具轮;D36–D39 的修法全部实测成立,16 对冲突逐对复现):两条——D40 机制盲区:主语是两字 CJK 词或单个拉丁词时,紧跟的裸数字被并进主语、`values` 空,`_note_conflicts` 直接返回,整条 lane 一条不记(`温度 22/24 度`、`室温`、`设定`、`预算 5000/8000 元`、`The thermostat 22/24 degrees` 全部 0 条,HTTP 上也是 `[]`),而三字主语 `恒温器 22/24 度` 记 1 条——**主语长度决定记不记**,且 `:412` 那句「数字只要站在某个词之后就是量不是名字」被 `温度 22 度` 直接推翻;D41 归因错:我写「一条记忆只有数字没有词时没有主语可比」,实测 `numeric_values('22 度').subject == '22'`,0 条是因为两侧主语不同。修法换成机制(`_numbers_follow`)而不是加披露,实测 33 对里只动 6 对(五条漏报变记上,加一条新披露边界 `Room 3 is big` + `Room 4 is big` → 1 条),其余逐字不变。该轮同时实测确认:门禁全绿、五个攻击(标点隔开、数字开头、融合写法、一句多数字、反向实验)全部量过,`Room 3 holds 22 degrees at 5 pm` 报 `room3` 22→24 是真读数变化、但 `degrees` 键拿到了 `5`(P5,本轮无害);反向实验删掉改名那四行恰好让两条测试变红(我预测的第三条不变红,因为「数字开头当主语」住在 `_subject_and_rename_slot` 第一个分支 `trust.py:254`);抑制只在页面(搜只给新侧,`GET /api/atoms` 两侧都在且 `valid_to` 仍 None)。另有四条精度说明:P1 smoke 要加指纹断言,否则 8799 上的旧服务能替这棵树答题(它自己就撞上一次:答题体没有 p2-3 字段)——第 3 轮加在 `scripts/mcp_write_smoke.sh` 的 `recall_count` 断言被第 4 轮判为**空判别子**(D42):`ely-eye-mcp/internal/mcpserver/write_tools.go:61-70` 把 HTTP 答复解进强类型 `domain.Memory` 再原样发出,旧服务缺的字段解成 `0` 又被 Go 侧重新发出,所以旧 Python 服务照样通过(评审用 `4c6af87` 的服务 + HEAD 编的 MCP 二进制实测,答复里是 `"recall_count":0`)。指纹现在打在 **Python 答复**上:就绪后先探 `GET /api/memory/working`,实测 `4c6af87` 返 404、HEAD 返 200(两边我都自己起服务量过),旧服务替这棵树答题会当场 FAIL;MCP 侧那条断言留着,但文案改成它真正钉住的东西——脚本自己现编的那个 Go 二进制是不是这份树编的;P2 「整行」口径(已写进 p1-6.4);P3 本报告里门禁行与第 1 轮记录行各重复一份(已去重);P4 `LEGS.md` 的 stamp(`a52c104`,harness blob `a1e9842d`)比改名后的 HEAD(blob `977d19eb`)旧——实测 `git diff a52c104:bench/leg_check.py HEAD:bench/leg_check.py` 只有一行注释被压成一行、零代码变动,`bench/leg_report.py` 两处 blob 全同,所以报告里的数字就是这份代码跑出来的,不必重测(重测只会把延迟换成另一个机器负载下的值)。 - **评审第 4 轮 FAIL**(同一独立 pi,7 项全跑,~557 工具轮;D40/D41 的修法实测成立,16 对逐字复现、五对 D40 全记上):三条——D42 就是上面 P1 那句被实验推翻(Go 层重发缺失字段,旧服务照样过);D43 `:412` 的机制句**方向写反**,我写「主语之前的裸数字并入主语键」,而代码的改名槽是 `index + 1`(主语 token 的**下一个**,`trust.py:275-276`),实测 `3 room holds 22 degrees` 主语是 `3`、不会向前融合,三个例子里只有 `2026 saw …` 数字在前、走的是 `trust.py:270-272` 首数字分支;D44 `_numbers_follow` 的**漏报侧没披露**:改不改名取决于每条记忆自己后面还留着没有第二个数字,`温度 22 度` + `温度 24 度 湿度 40`(`温度`/`温度24`)、`温度 22 度 湿度 40` + `温度 24 度`、`温度 22 度 湿度 40` + `温度 24 度 湿度 60`(`温度22`/`温度24`)、`预算 5000 元 超了 8000` + `预算 6000 元`(`预算5000`/`预算`)四对全 0 条,方向 fail-closed(两条都留在页上)。D44 按评审建议只**披露 + 加测试**(`test_a_second_number_in_one_memory_hides_the_update`),不用「未改名主语兜底比对」,那会把 `Room 3 holds 22 degrees` + `Room 4 holds 24 degrees` 退回 D37 的误报。四条精度说明全部采纳:P-a `degrees` 键也吞年份(`in 2026` → `{'degrees':'2026'}`),P5 那句已改成「第二个数字,含年份」;P-b 反向实验的红名单是 4 条不是 5 条(全套 4 failed / 379 passed,无连带);P-c 「数字只要站在某个词之后就是量不是名字」已就地加限定词(且不在紧挨主语那个位置);P-d 8799 守卫仍只在开跑时探一次,现在指纹补上了**旧构建**答题这一口——同树残留的服务占住端口时指纹仍给 200(评审实测:同树同 `ELY_EYE_AUTH_TOKEN` 的服务把 5 条 atom 落进它自己的 home,直到挂载卡带才失败),那种情形仍只有 busy-port 守卫能挡。该轮同时实测确认:门禁全绿且 mypy 两边逐字相同、tokenize 0 块、最大文件 `bench/systems.py` 498 行;D41 的新测试文案与实测一致;P4 的 stamp 判断站得住(`bench/leg_report.py` 两处 blob 全同 `40596d29…`)。判定:p2-3.1/3.2/3.3 与两条验收都能 `[x]`,p2-3.4 因 D43/D44 的记录级缺陷暂缓。 - **评审第 5 轮 PASS**(同一独立 pi,7 项全跑,本轮 diff 仅 3 个文件 +31/−5、机制 blob 全同:`trust.py d0b1a090`、`memory.py 13b0ebbf`、`retrieval.py 305d6e3a`、`compiler.py 5d341ca5`、`api_memory.py 22a03666`):D42/D43/D44 全部按实测改掉并被独立复现——D42 的判别子它自己起两边服务量过(`4c6af87` 的 `/api/memory/working` 404、HEAD 200);D43 三个主语实测 `3` / `room3` / `2026`;D44 四对逐对 0 条且贴出了页面(两条都留着),新测试的两条断言它逐条读过(第二条真的检查了「都在页上」)。**「不用未改名主语兜底比对」这个判断它用实验支持了**:把 `quantity_conflict` 改成主语不等时退回比值键,`Room 3 holds 22 degrees` + `Room 4 holds 24 degrees` 立刻变回 `('holds','22','24')`,即第 2 轮 D37 的误报复活。反向实验(去掉 `_numbers_follow` 条件)红名单仍是 4 条、全套 4 failed / 379 passed,**新加那条不变红**(无条件改名下它两条断言仍成立)。20 对冲突 + D40 五对 + `Room 3 is big` 边界逐字复现。门禁全部重跑且与本报告逐格一致(384 passed、六文件 83、conflicts 27、三文件 35、mypy 与 `9cb46c1` 文件集合与去行号文本逐字相同、tokenize 148 个 `.py` 0 块、最大文件 `bench/systems.py` 498、go `-count=1` 全套 + gofmt 空、`index-CSDHCFNo.js 221.48 kB`、smoke PASS)。两条精度说明(不算缺陷)已采纳:P-e 把 D44 成因从「一侧改名」改成「改名后主语键各自吃进自己的数字,两侧都改名也永不相等」(我另测 `温度 22 度 湿度 40` + `温度 24 度 湿度 40` → 0 条证实对称情形);P-f 把「指纹补上 8799 那一口」限定为旧构建那一口。判定:p2-3.1/3.2/3.3/3.4 与两条验收全部 `[x]`。 + - 钥匙测试场景 3 暂露的真缺口(终验时补):`v_atoms_current` 只答「现在开着」的记忆,所以被 supersede 的旧事实**无论怎么设 `since`/`until` 都答不出来**——那两个字段框的是 event time,不是「从哪个时刻答题」。补成能力:`SearchFilters.as_of`(`schemas.py`),`store_search.py` 把视图换成 `atoms` + 两分支谓词(不带 as_of 时逐字重复视图条件,带时 `valid_from <= as_of < valid_to`、`event_time <= as_of`、`retention_until > as_of`,且**不看 `archived_at`**,因为归档是存储层不是关于世界的断言),`vector_index.py:_allowed()` 同一套窗口,`retrieval.py:119` 透传,CLI `search --as-of`。验收:`pytest backend/tests/test_as_of_search.py` → **5 passed**(旧记忆答它当真的那阵、下周的记忆不答今天的问、归档前的时段仍答、as_of 不借别人的记忆、dense 腿与文字腿读同一个窗口)。 - 顺带:`cli.py` 495→432 行(写路径拆进 `cli_memory.py`),`bench/leg_check.py` 拆出 `bench/leg_report.py`;typer 0.27.2 用**关键字**调用回调,`*atom_ids: str` 形式的命令一调就 `TypeError`,改成 `list[str]`——这才是之前 `test_maintenance` 那条 TypeError 的真因,命令重名只是表象。报告 stamp 早于 harness 的缺陷也修了(`a52c104`)。 - [x] **p2-4** 共享记忆 - [x] p2-4.1 多用户/多 agent 作用域 + ACL(schema v11:holder token + 三态眼睛) - - 事实:`holders` 加 `token_hash` / `token_issued_at`(`migrations.py:92` DDL,`_NEW_HOLDER_COLUMNS` 给老库 ALTER)。**只存哈希**(`sha256`,`holder_store._token_hash`),所以拷走的库不能重放 token;明文只在 `POST /api/holders/{id}/token` 的响应里出现一次(`IssuedToken`),`GET /api/holders/wife` 只回 `token_issued_at`。生成用 `secrets.token_urlsafe(32)`,比对用 `secrets.compare_digest`。`register_minimal` 是 `INSERT … ON CONFLICT DO NOTHING`,`remember` 在写记忆前调它(`memory.py:120` 之后),所以被转介的人一定有目录行,且它绝不覆盖人已声明的 name/contact。 - - 身份是**服务器算的**:`api_auth.resolve_caller` 三选一——operator(全局 token,可指名任何人)、holder(自己的 token,`verify_token`)、anonymous(没 token)。`read_as(caller, claimed)` 把「调用者声称的 holder」降级成「服务器认定的眼睛」:operator 不声称 → `None`(整库),operator 声称 → 那个人,holder 声称自己 → 自己,**声称别人 → 403 并把两个人都点名**,anonymous 声称任何人 → 403。`/api/search`、`/api/atoms`、`/api/atoms/{id}/image`、`/api/chat`、`/api/memory/working`、`/api/memory/conflicts`、`/api/ask` 全部走它;`remember`/`supersede` 的 holder 也只能是 caller 自己(p0-2 那条「客户端不能声称自己是别人」现在由 token 保证,不再靠 `default_holder` 兜底)。 + - 事实:`holders` 加 `token_hash` / `token_issued_at`(`migrations.py:92` DDL,`_NEW_HOLDER_COLUMNS` 给老库 ALTER)。**只存哈希**(`sha256`,`holder_store._token_hash`),所以拷走的库不能重放 token;明文只在 `POST /api/holders/{id}/token` 的响应里出现一次(`IssuedToken`),`GET /api/holders/wife` 只回 `token_issued_at`。生成用 `secrets.token_urlsafe(32)`。**两条 token 走两条比对**:operator 的明文用 `secrets.compare_digest`(`api_auth.py:54`、`:110`),holder token 是 SQL 等值查摘要(`holder_store.verify_token` = `WHERE token_hash = ?`)——库里只存 sha256,没有明文可做常数时间比较;评审第 1 轮 D1 就是我把这两条混成了一句。`register_minimal` 是 `INSERT … ON CONFLICT DO NOTHING`,`remember` 在写记忆前调它(`memory.py:94`),所以被转介的人一定有目录行,且它绝不覆盖人已声明的 name/contact。 + - 身份是**服务器算的**:`api_auth.resolve_caller` 三选一——operator(全局 token,可指名任何人)、holder(自己的 token,`verify_token`)、anonymous(没 token)。`read_as(caller, claimed)` 把「调用者声称的 holder」降级成「服务器认定的眼睛」:operator 不声称 → `None`(整库),operator 声称 → 那个人,holder 声称自己 → 自己,**声称别人 → 403 并把两个人都点名**,anonymous 声称任何人 → 403。`/api/search`、`/api/atoms`、`/api/atoms/{id}/image`、`/api/chat`、`/api/memory/working`、`/api/memory/conflicts`、`/api/ask` 全部走它;`remember`/`supersede` 仍是 **operator 才能写**(holder token 拿去写 → 401,评审实测),operator 写的归属来自请求或 `ELY_EYE_DEFAULT_HOLDER`(评审实测库里 `[('husband',2),('local',2)]`);p0-2 那条「客户端不能声称自己是别人」仍由 `RememberRequest` 没有 holder 字段保证,token 没有取代它(评审第 1 轮 D8:我原先写成「现在由 token 保证,不再靠 `default_holder` 兜底」,与实测相反)。 - **眼睛是三态、不是一个字符串的两可**(跑出来的决定):`NULL` = 整库(operator,或自己拥有这个 store 的进程),holder id = 那个人的眼睛,`''` = 谁也不是(无 token 的 HTTP 调用者)。让 `NULL` 也代表「谁也不是」会逼 CLI、proofs、compiler、bench harness、`who_knows`、`ask` 全都传眼睛,那跟 p0-2 定的「拥有 store 的进程按本机受信主体读」直接冲突——第一次这样改时 `pytest -q` 红了 29 条(`test_vector_index.py:46` `assert [] == ['mem-eaf3b790ca27bf3e:text']`、`test_proofs.py` 回放 0 hits、`test_visual_index.py:43` `ValueError: invalid literal for int() with base 10: 'widget gadget sprocket'`,因为一条本来被跳过的腿开始跑了)。`''` 能当「谁也不是」是因为本 schema 里 `holder_id = ''` 本来就是「无主」。 - - 修前是真的漏:`browse.py`(`GET /api/atoms` 与 `/api/atoms/{id}/image`)**完全没有可见性规则**,无 token 就能翻页读到别人的记忆正文和图片;`store_search.py:81-86` 与 `vector_index.py:245-252` 的规则是 `(? IS NULL OR holder_id = '' OR scope='everyone' OR holder_id = ? OR …)`,`as_holder IS NULL` 短路成「整库」,所以无 token 搜索也看见全部。现在五处副本统一成 `(? IS NULL OR holder_id = '' OR json_extract(visibility_json,'$.scope') = 'everyone' OR (? <> '' AND (holder_id = ? OR EXISTS (… value = ?))))`,**四个参数同一个值**。 - - 规则为什么写五份而不抽常量:semgrep `python.sqlalchemy.security.sqlalchemy-execute-raw-query` 对 `connection.execute(f"…{常量}…")` 报警,哪怕那个常量是模块级的,所以只能写整句字面量。防漂移靠 `backend/tests/test_visibility_rule.py`:`EXPECTED_COPIES = 5`,正则抓出每处、`_normalize`(去空白、去引号、去 `a.` 别名)后必须**只剩一个字符串**,第二条测试钉住 clause 里 `? IS NULL` / `holder_id = ''` / `$.scope')='everyone'` / `? <> ''` / `holder_id = ?` / `value = ?` 六个特征还在。第一版正则 `\(\? IS NULL[^;]*?` 会把 `(? IS NULL OR modality = ?)` 这类过滤谓词一起吃掉,读出 4 份不同 clause——那是正则错,不是规则漂移。 + - 修前是真的漏:`browse.py`(`GET /api/atoms` 与 `/api/atoms/{id}/image`)**完全没有可见性规则**,无 token 就能翻页读到别人的记忆正文和图片;`store_search.py:103` 与 `vector_index.py:288` 的规则是(行号是 as_of 之后的,`83dfc14` 时它们是 81-86 / 245-252) `(? IS NULL OR holder_id = '' OR scope='everyone' OR holder_id = ? OR …)`,`as_holder IS NULL` 短路成「整库」,所以无 token 搜索也看见全部。现在五处副本统一成 `(? IS NULL OR holder_id = '' OR json_extract(visibility_json,'$.scope') = 'everyone' OR (? <> '' AND (holder_id = ? OR EXISTS (… value = ?))))`,**四个参数同一个值**。 + - 规则为什么写五份而不抽常量:p0-1 那轮本仓跑 SQL 注入门时,`connection.execute(f"…{模块级常量}…")` 被拒过,那轮的门是 opengrep(评审第 1 轮 D7:这个容器现在 `which semgrep` / `which opengrep` 都是空,所以这条是**当时观察到的**,今天在这台机器上重跑不了)。今天真正防漂移的是 `backend/tests/test_visibility_rule.py`,它不依赖那个工具:`EXPECTED_COPIES = 5`,正则抓出每处、`_normalize`(去空白、去引号、去 `a.` 别名)后必须**只剩一个字符串**,第二条测试钉住 clause 里 `? IS NULL` / `holder_id = ''` / `$.scope')='everyone'` / `? <> ''` / `holder_id = ?` / `value = ?` 六个特征还在。第一版正则 `\(\? IS NULL[^;]*?` 会把 `(? IS NULL OR modality = ?)` 这类过滤谓词一起吃掉,读出 4 份不同 clause——那是正则错,不是规则漂移。 - [x] p2-4.2 默认可见性:answer-only 转介(p0-5 的转介现在被 ACL 兜住) - p0-5 只做了一半:`ask` 命中别人的时候只回指针不回正文(`_pointer`),但**搜索本身**还是能读到正文,所以「只给指针」是客气不是边界。现在无 token 的 `search_atoms` 搜不到那句私钥(smoke 实测),`ask` 的 `answer` 仍为空、`secret` 在整个 referral JSON 里不出现,而 `who_knows` 照旧能用——目录路由**故意不设卡**,因为它只出计数、分数、contact 和声明过的话题,不出记忆正文(`api_holders.py` 注册处一行注释写明)。`visibility` 三档实测:默认 `holder`(只有主人)、`everyone`(无 token 可搜到)、`visible_to: [husband]`(主人 + 被指名的人能读,陌生人和第三个 holder 不能)。 - [x] p2-4.3 能力卡:让外部 agent 能路由进 ely-eye - `GET /api/card`(整库)与 `GET /api/card/{holder}`(一个人),CLI `ely-eye card`,MCP `ely_eye_card`(Go `apiclient.Card` / `HolderCard`,空 id 在**发请求之前**拒)。卡是**派生的不是声明的**(`card.build_card`):`PRAGMA user_version`、`sources` 计数、`v_atoms_current` 按模态分组、每人 `(条数, MAX(ingested_at))`、每人模态/场景、合并目录、`has_audio = "audio" in senses`、挂载状态。所以它不能承诺一个 store 里没有的模态——`has_audio: false` 就是把视觉/音频腿的缺口在**别人提问之前**说出来。 - 无 token 就能读(smoke 实测 HTTP 与 MCP 两条路都通),且卡里**不含任何记忆正文**(smoke 断言 `secret not in json.dumps(card)`);`token_issued` 只说「这个人有 token」,不发 token。卡的 schema 版本与整库卡一致这条也进了 smoke 的 tokenless 分支。 - - 偏差(都是跑出来的):`/api/memory/working` 与 `/api/memory/conflicts` 现在拒绝「谁也不是」的调用者(422,消息含「somebody」),因为这两件事本来就属于某个人;`compiler.py:41` 的缓存 key 加了眼睛——先前写 `as_holder or ""` 会把 operator 的上下文和陌生人的**撞成同一个 key**(两边都哈希 `""`),于是陌生人那份空 pack 会端给 operator;`forget` 的级联、卡带成员、目录都不因 ACL 改动。 + - 偏差(都是跑出来的):吊销过的 token 是**硬拒**(401「this token is neither the operator token nor a holder token」,`api_auth.py:59`),不降级成匿名;匿名调用者带 `?holder=`(空串)也是 403,不是「没声称」;能力卡除计数、分数、contact、声明过的话题之外还带每人的 `newest_memory` 时间戳与 `token_issued`,两者都不含记忆正文。`/api/memory/working` 与 `/api/memory/conflicts` 现在拒绝「谁也不是」的调用者(422,消息含「somebody」),因为这两件事本来就属于某个人;`compiler.py:41` 的缓存 key 加了眼睛——先前**根本没有身份成分**(`semantic_key(question, profile.value, self.db.revision())`;评审第 1 轮 D3:我写的「先前写 `as_holder or ""` 两边都哈希 `""`」那套机制在这个仓里从来没存在过),所以 operator 的上下文和陌生人的共用一个 key,陌生人那份空 pack 会端给 operator;现在 key 里带 `"the whole library"` 或 `as holder {as_holder!r}`,两种顺序实测四个 trace id 全不同(`None`→1 hit、`''`→0、`husband`→1、`nobody`→0);`forget` 的级联、卡带成员、目录都不因 ACL 改动。 - 验收:`pytest backend/tests/test_holder_acl.py backend/tests/test_visibility_rule.py backend/tests/test_transactive.py` → **13 + 2 + 19** 全绿(两 holder 互不可见、无 token 读不到私钥、`everyone` 无 token 可搜、`visible_to` 只放行被指名的人、声称别人 403 且点名两人、token 只出现一次且库里只有 sha256、吊销后旧 token 401、卡无 token 可读且不含正文、陌生人的图片 404 而无主的 200、`compile(as_holder="")` 返回 0 hits 且 `cache_trace_id` 与 `as_holder="wife"` / `None` 都不同)。跨进程:`bash scripts/mcp_write_smoke.sh` → 两行 PASS,第二行是「a caller with no token sees only public memory, a holder's token sees her own, naming somebody else is refused, and the capability card answers without a token」——它先证明无 token 搜不到私钥,再用 operator token 铸出妻子的 token、证明她能搜到自己的、搜不到 `local` 写的 `the oven needs descaling`,最后**把 MCP 进程不带 `ELY_EYE_AUTH_TOKEN` 重启一遍**,证明 Go 那条路守同一条规则(不是假设)。 - 顺手修的两条自己写的断言缺陷(都是跑出来的):smoke 里 `if secret in found(None, token=token)` 是同义反复(搜的还是那句话,当然命中),改成拿**别人写的**记忆当探针;指纹探测 `GET /api/memory/working?holder=fingerprint` 现在返回 **403**(路由在、但匿名不能声称 holder),所以探测必须带 operator token——旧树上没有这条路由仍是 404,判别力保住。 + - **评审第 1 轮 FAIL**(同一独立 pi,`209f2d0..83dfc14`,736 工具轮):**功能面它全部实测成立**,记录面 8 条对不上,已全部按实测改掉——D1 「比对用 `compare_digest`」对 holder token 是假的(库里只有摘要,`verify_token` 是 SQL 等值,`compare_digest` 只用在 operator 的明文上);D2 指针错(`register_minimal` 在 `memory.py:94`,不是 `:120`);D3 「先前 `as_holder or ""` 两边哈希 `""`」描述的机制从来没存在过(旧 key 根本没有身份成分);D4 `browse.py:14` 注释说「four — two here」而实际五份、这里三份(`:52`/`:66`/`:93`);D5 指针被 as_of 改动挪了行(`vector_index.py:288`、`store_search.py:103`);D6 我 prompt 里写「33 条路由」而实测父提交 34 个装饰器 / 31 条不同路径、HEAD 38 / 35;D7 semgrep 那条在它的环境里无法复现(`which semgrep` / `which opengrep` 都空),已改成「当时观察到的」并把防漂移的责任交给不依赖那个工具的测试;D8 「holder 也只能是 caller 自己…由 token 保证」与实测相反(只有 operator 能写,归属来自 `default_holder`,真正的保护是 `RememberRequest` 没有 holder 字段)。它同时实测确认:三条漏在父提交上是真的、在 HEAD 关上;38 条路由里会吐正文/字节的 7 条全带眼睛;11 个攻击全关(含吊销 token 401、holder token 不能写);三态没被照瞎(CLI 命中、`bench.leg_check --probes 20` recall@10 0.900 / p50 72.3 ms、smoke PASS);五份副本它自己数过,把 `? <> ''` 改掉立刻让 `test_visibility_rule.py` 红;缓存 key 两种顺序四个 trace id 全不同;smoke 新增那段是真判别子(父提交树会把私钥搜出来)。另采纳四条精度说明(吊销硬拒、匿名空串 403、能力卡还带时间戳与 `token_issued`、`leg_check` 的 commit 行是 cwd 的 HEAD)。 - 门禁:`pytest -q` **401 passed**;`ruff check` 对 22 个改动文件干净;`bench/filesize_check` 干净;`bench.audit --product` → `audited 32 harness files, 2 reports, 6 set files` / `clean`;mypy 冷缓存 **24 errors in 9 files (checked 112 source files)**,与 `9cb46c1` 基线(24/9)**净新增 0**;`./node_modules/.bin/pyright` 对 17 个后端源文件 + 5 个测试文件 → **0 errors**;`go build` / `go vet` / `go test`(apiclient ok、mcpserver ok)+ `gofmt -l` 空;`npm run build` → `dist/assets/index-CSDHCFNo.js 221.48 kB`(bundle 哈希与 `246dae9` 相同,与「本轮没动前端」一致)+ eslint exit 0;`bash scripts/mcp_write_smoke.sh` 3.3s 两行 PASS。 - [x] **p2-5** 文档单一真相 - [x] p2-5.1 `AGENTS.md` 重写并停止 gitignore @@ -460,4 +462,12 @@ ## 终验 - [ ] **final-accept** Gaps.md §6「钥匙测试」7 条场景逐条跑通 - - 验收:核对表列场景、命令、实测数字、通过与否;未通过不标绿;benchmark 报告与基线、外部基线、chance 行并排 + - 命令:`bash scripts/key_test.sh`(自建临时 home、假模型快照、起 API、Go MCP 走 stdio、CLI 挂卡带;一张表,任何 FAIL 退出码非 0)。实测:**6 PASS + 1 NOT MEASURED**,exit 0。 + - 1 随手记 PASS:`POST /api/memory` 一次往返 → `POST /api/search` 答出来,holder=wife origin=self scenario=home event_time=2026-09-30 citable=True。 + - 2 找老婆 PASS:MCP `who_knows(护照)` → holder=wife、confidence 0.683、basis 三条;`ask(护照在哪)`(无 token)→ `status=referred`、`answered_by=wife`、`atom_ids` 为空——**过去的是指针不是正文**;`ask(土星的光环…)` → `no_holder_knows`,不是硬编一个答案。 + - 3 知识更新 PASS:supersede 之后 `现在` → 「钥匙现在在车里」,`as_of 2026-10-06` → 「钥匙放在玄关抽屉里」,旧记忆从现行列表里消失(它那个 source 0 行)但没被删。这条是终验逼出来的新能力,见 p2-3 那条 as_of。 + - 4 分歧共存 PASS:两条日期不同的冲突记忆都在库里,一页只给新的一条(`retrieval.py:_settle_conflicts` 摘掉未裁决的旧侧),`GET /api/memory/conflicts?holder=wife` 记下双值(1 条 open),`as_of 36 小时前` 拿回 22 度那条。 + - 5 抗污染 PASS:`origin=third_party` 的无佐证说法可被主人搜到但 `quarantined=True`(编译器把它挡在 prompt 外,`CompiledContext.quarantined_excluded`,由 `test_trust_quarantine.py` 钉住),换个 holder 问则完全答不出。 + - 6 卡带即作用域 PASS:`ingest --cartridge-name 甲/乙` + `finalize-cartridge` + `mount/switch/unmount`,挂载后搜索只从卡带出(月岩灰 1/花岗岩 0 → 切换后 0/1 → 卸载后 1),把模型快照的 rope factor 改成 2.0 之后 `mount 甲` 拒绝并点名 `rope: factor: cartridge 4.0 vs local 2.0`(还带 model_hash)。 + - 7 卡带省算力 **NOT MEASURED**:这条断言是 TTFT 与命中率,本仓从没跑过 9B 生成器(树里没有模型快照),而且没有 `/api/compile*`、`/api/cache*` 路由(`/api/chat` 无运行时 503),所以连「命中率可观测」这半边也没有面可达。今天存在的是作用域(mount/switch/unmount/append)和 `profiles.py` 里那些尚未接地的启动旗标。 + - 未标绿的原因(两条都量着):场景 7 未测;验收线 recall@10 ≥ 0.90 仍未达(shipped 0.863 / 300 探针,外部对手 holder 作用域 0.866,chance 0.0002;缺口全在视觉与音频腿:video 0.455、image 0.720、ui_screenshot 0.818,冻结库里 0 个 audio atom)。报告并排:`bench/reports/BASELINE.md`(本项目基线)、`BASELINE_EXTERNAL.md`(Mem0/Zep 式对手 + chance 行)、`LEGS.md`(当前各腿)、`QUANT.md`/`DENSE.md`/`SCALE.md`(向量与规模)、`VISUAL.md`(图片腿)、`ASR.md`(语音)。 diff --git a/backend/src/ely_eye/browse.py b/backend/src/ely_eye/browse.py index 7a2f80d..9cf71f8 100644 --- a/backend/src/ely_eye/browse.py +++ b/backend/src/ely_eye/browse.py @@ -11,7 +11,7 @@ from .retrieval import decode_cursor, encode_cursor from .schemas import AtomPage, Modality from .storage import ObjectStore -# The visibility rule is spelled out in four literal statements — two here, one in store_search, one in vector_index — because the SQL gate rejects a concatenated statement and a view cannot take a parameter; backend/tests/test_visibility_rule.py fails if the copies disagree. +# The visibility rule is spelled out in five literal statements — three here, one in store_search, one in vector_index — because the SQL gate rejects a concatenated statement and a view cannot take a parameter; backend/tests/test_visibility_rule.py fails if the copies disagree. @dataclass(frozen=True)