Repository navigation
agent_turn_recall: route the canonical hash through the digest envelope owner - #8611
Conversation
…pe owner Refs loopx-project#5336. Signed-off-by: psychologister <230141834+psychologister@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.1-sol · OpenAI · runtime_reported · reasoning_effort=max
评审提交 2e47312。
当前提交没有阻断性发现。
动机 / Motivation
依赖回合召回的 Agent、读取旧召回收据的运行时,以及维护摘要规范的开发者。 同一次召回的收据靠 SHA-256 摘要辨认。原实现单独组装摘要前缀,规则改变时需要同步修改每个写入处。当前提交把前缀和校验交给已有的公共函数。 用相同输入生成的三个摘要逐字节一致,升级前形成的收据还能在同一回合中直接读回。 交付范围是回合召回的一个摘要生产者、原架构检查和兼容性。 这项迁移只完成回合召回,其他目录由同一问题下的后续迁移处理。
改动思路 / Approach
回合召回继续决定哪些字段进入摘要、如何排序和编码。公共生产者从同一字节串生成摘要,并用现有的跨运行时正则校验输出。 现有共享函数恰好拥有字节到带前缀摘要的格式不变量。把 JSON 策略也提上去会把召回模块的字段取舍绑到其他调用者。 保留领域模块自己的 JSON 编码和作用域输入,只共享 sha256 摘要封装。回合和查询标识、错误和收据重试由原消费者使用。 digest_envelope.sha256_envelope 拥有生产格式,生成的 content_digest.ENVELOPED_SHA256_PATTERN 拥有识别形状,召回模块拥有规范 JSON 字节。
具体改动 / Changes
关键代码讲解
- 同一组 sort_keys、ensure_ascii 和紧凑分隔符得到 UTF-8 字节。PR 只把字节交给统一生产函数。 _canonical_hash
- 保留 SHA-256 十六进制和固定前缀,输出通过共享正则全值校验。生成的格式模块只声明形状。 sha256_envelope
- 情况摘要排除当前回合 ID,回合摘要再绑定真实回合 ID。材料输入和回合身份的变化可分别观察。 build_agent_turn_situation
- 验证匹配的 Goal、Agent 和 Turn 后,检查现有收据 ID 与配置修订。已有收据直接去重,错误身份在调用外部 provider 前被拒绝。 handle_agent_turn_recall_command
- 把回合召回列入前缀构造扫描。直接字符串和可静态折叠的等价拼接会被守卫发现。 CONVERTED_SURFACES
根据 #5336 的迁移约束和目标分支 43b4699 上已有的生产函数与架构规则逐项对照。
- shared-production-owner。生产仍使用同一个生成正则校验,领域模块保留自身字节输入。
- byte-for-byte-parity。三个可观察摘要、旧收据和拒绝路径与旧版一致。
- converted-surface-guard。测试加入已迁移目录和独立参考摘要,原形状所有者检查保留。
提交只动两个文件,+8/−3。PR 分支和当前 main 做了无冲突合入模拟,模拟树的变更仍是这两个文件。同一场景用真实本地 CLI 做预览与读回,另跑 File/SQLite 的宿主交付、架构守卫与回合召回定向测试。源码核对了 prefix 读取和截断短摘要,两者保持其原用途。
对主干的风险 / Risks
一旦 JSON 转成 ASCII 转义或改变嵌套字段顺序,旧收据的回合 ID 将不匹配并进入新查询路径。含 Unicode 的精确比较与旧收据读回覆盖此风险。 目标基线 319 项通过,合入模拟 320 项通过。独立真实 CLI 的 8 组输出逐字节相同,包括 Unicode、旧收据读回、身份拒绝及默认关闭。 旧收据保持原字节,未配置 Goal 或同 Goal 未启用的 Agent 都无 provider 调用、配额消耗或授权。作者曾报告两条宿主交付测试失败。这次相同当前 main 与合入模拟的完整文件均通过,历史失败原因仍未知。独立 CLI 对照使用隔离注册表和合成收据。真实外部记忆 provider 与托管 CI 未运行,已有定向测试使用受控 provider 测试替身。
我的整体评价 / Verdict
回合召回的写入格式收敛到了共享 owner,旧收据读回与新回合身份分离均保留。允许分批迁移其他生产者,保持现有每个领域的序列化规则。
English verdict: APPROVE at 2e47312. The shared envelope owner preserves the canonical bytes and existing recall receipt replay.
What
agent_turn_recall/core.pybuilt its canonical hash by hand ("sha256:" + hashlib.sha256(...).hexdigest()). This routes it through the shared ownerloopx.control_plane.digest_envelope.sha256_envelope— the production half of the digest-envelope migration.Refs #5336.
Why
tests/architecture/test_content_digest_single_owner.pynames hand-built envelope producers as "the other half of the decision" and converts them one surface at a time.agent_turn_recallis one such surface; this converts it and adds it toCONVERTED_SURFACES.Behavior
The JSON byte recipe is unchanged (
ensure_ascii=False,sort_keys=True, compact separators), so the digest is byte-identical. A parity case compares the migrated helper against the expression it replaced. The.removeprefix("sha256:")reader and the bare short hash elsewhere are left as-is (exempt forms).Tests
tests/architecture/test_content_digest_production_owner.py(extended guard + parity): pass locally.test_turn_host_context_delivery.pyfailures reproduce identically on the clean base tree.