Repository navigation
perf(context): read scoped User bodies from one snapshot - #7767
loopx-agent merged 3 commits into
Conversation
Signed-off-by: shangzh0 <97216392+shangzh0@users.noreply.github.com>
songoow
left a comment
There was a problem hiding this comment.
Reviewer: model_agent — GPT-6 Astra Pro — OpenAI — self_reported
动机 / Motivation
执行 quota should-run 的 Agent 在接收当前工作上下文时,需要拿到当前作用域内开放的 User Todo 完整正文。 同一 Goal 有三条可见 User Todo 时,旧路径先查清单,再为每条正文重查完整权威来源,共四次查询;新路径在一次权威快照中筛选并交付全部正文。 独立 File 与 SQLite 对照均确认三条时四次变一次,十九条时二十次变一次,完整记录和正文尾部保持相等。 本次只减少 User 上下文的重复来源查询,不宣称模型 token、整轮延迟、成本或任务得分下降。
本次完整复审覆盖 base 21367015cce45294dcf99f54a3211d66f5d842c5 到 head 8dd7134d9f4d6278ec6f26c356deb82e3c146f30 的全部六个文件,并读取真实 guard、Todo 查询和上下文消费链。当前没有确认的生产代码阻塞缺陷;审查结论暂为 REQUEST_CHANGES(验证保留),原因是该 head 的两条 CI 失败还没有充分归因,下面分别说明功能证据与剩余资格缺口。
改动思路 / Approach
完整正文与 Agent 作用域是既有核心保证,由现有 TypeScript Todo read owner 同时完成;Python 只传输请求并核验交付确认,不增加缓存或第二套权限判断。 当前 PR 的边界是已发货 quota should-run 工作上下文的一次快照读取及相应失败拒绝;普通 Todo CLI 展示保持原样。
quota should-run 经既有 attach_work_context 进入 _user_context,后者请求 full_text=True。权威读取仍由 readCanonicalTodoProjection 和带版本检查的 snapshot owner 完成;现有 selector 先决定哪些 Todo 属于当前 Agent、仍开放且未归档,随后才从同一份原始记录恢复正文。交付完成后返回明确确认,Python 不会把忽略新字段的旧 runtime 当作已支持完整正文。
不改变实现会继续在每次 guard 上支付重复完整来源查询;改成 Python 自己筛原始记录则会复制作用域规则。本 PR 使用已有 owner,删除逐条查询和跨查询版本比较,代价是一张瞬时身份索引与一个请求/确认字段。它不引入持久缓存、迁移、额外 CLI 开关或新的用户确认步骤。#7761 的 field_index 解决字段发现往返,和这里的来源查询合并互补。
| 同一合成输入,真实 CLI 与 provider | base | head | 正文与作用域 |
|---|---|---|---|
| File:3 条可见 User Todo | 4 次 | 1 次 | 完整记录相同 |
| SQLite:3 条可见 User Todo | 4 次 | 1 次 | 完整记录相同 |
| File:19 条、无 index、另有16条 peer Todo | 20 次 | 1 次 | 19条全文保留,peer排除 |
| SQLite:同上 | 20 次 | 1 次 | 同上 |
这些是 User-context 路径的查询数;没有把字节、查询比例或文件生成量换算成模型 token。
具体改动 / Changes
整个 diff 为 +94/-18:三个现有生产文件 +32/-18,两个现有测试文件 +49,一段双语文档 +13。没有新增模块、状态文件、provider 或公开 CLI flag。
关键代码讲解
_user_context(context_readback.py:111) 把「清单加逐条详情」收敛为一次list_goal_todos。role=user、status=open和agent_id仍显式传入,返回给上下文消费者的仍是 source、authority_read、todos,内部交付确认不会成为新的模型指令。todoListPayload(read_transaction.ts:59) 在现有筛选完成后恢复正文,身份使用 todo_id、role、archive_state;重复键会标记为不明确并拒绝,而不是任选一份。full_text 只关闭这条完整正文路径的 hot presentation cap,普通列表与原 exact-detail 分支保留。Map 持有源记录引用,不新建一套权威数据。list_goal_todos(list_readback.py:22) 默认不发送 full_text;启用时拒绝 compact/thin 组合,并要求响应确认严格为 true。没有确认会抛出明确错误,随后沿既有上下文失败路径停止依赖该来源的交付。attach_work_context(context_readback.py:122) 是实际消费与拒绝边界,而不只是测试 helper。复审直接通过loopx.entrypoint.main → quota should-run验证它:完整正文进入 agent_channel;旧 runtime 不确认时,work_context.complete=false、delivery_allowed=false;恢复支持后,fresh guard 再次 complete。
规范依据为已接受的 docs/reference/protocols/turn-envelope-v0.md,spec_revision 21367015cce45294dcf99f54a3211d66f5d842c5,没有拿本 PR 新写的说明作为自证:
| 原规范章节 | 本次判断与实际验证 |
|---|---|
| Native Turn Host capture | 完整 User 义务、Agent scope、失败后 fresh guard、内容不授予权限均保留;长正文尾部、peer/done/archive 排除、原 publication gate 与安全 fallback 均通过。 |
| Budget warnings and allocation | 完整义务不能为展示预算截短;19条超过 hot cap 且每条超过摘要长度的输入仍完整交付,普通 bounded/exact/hot/thin/limit 列表行为不变。 |
独立 source fixture 的重复 Todo id 被真实 coordination.source.project 在 provider 写入前拒绝;修正为唯一 id 后,File/SQLite 的真实 guard 都恢复完整交付。这证明合法来源边界和恢复;没有声称用损坏的 canonical 数据执行了下游 Map 的拒绝分支。
对主干的风险 / Risks
主要风险是为省查询而扩大 scope、丢失正文尾部,或把旧 runtime 的摘要误标为完整上下文。同输入对照覆盖了这三个方向:初始与累积 User 记录完全相等;六种普通 CLI 读取在两种 provider 上的完整 payload 也一致,只归一化观察时钟、测试目录及独立临时数据库的实例标识。没有删除诊断文本、排序、counts 或 authority flags 来得到相等结果。base 的同一「应只有一次查询」断言失败,head 通过,证明测试能够识别原 N+1 行为。
PASS: tests/control_plane/test_selected_work_requirements.py 10 passed;tests/control_plane_ts/todo_read.test.ts 20 passed、0 skipped;TypeScript typecheck、三个变更 Python 文件编译、diff check、三份公开 docs/tests 边界扫描通过。扫描另有本地 registry 不存在的两项环境警告;扫描本身无遗漏、无边界告警。新模式冲突及非 boolean 请求也由真实 typed reader 测试拒绝。本地没有 Ruff,精确 head 的 kernel-static-checks 已完成其 lint;真实 PostgreSQL store/admission CI 为成功,未冒充本地执行或本次 User caller 的 PostgreSQL 专项测量。
语义与 CI 对齐
新字段是既有 Todo read request/result 的瞬时展示扩展;scope、status、archive 与上下文完整性仍由原 typed owner 决定。diff advisory 检查三个生产源文件,未检测到支持范围内的新词汇 carrier;这项空报告不证明没有语义变化,实际判断来自上述 caller 对照。新文档清楚区分完整正文与权限,没有把强制拒绝描述成可忽略的建议。
当前还必须保留两个 FAIL / 归因未完成:
- typescript-core (2/3), job124642204014:
task_lease_acquire_cli.test.ts:163的 malformed-input case 需要一行 JSON,CI 观察到0行。独立对 base213/head8dd 执行相同not-json原生 CLI,Node24.22.1 下两侧均 exit1、完整相同 invalid_json 输出、stderr为空;源码也显示 JSON 解析先于 acquire 与此次完整正文路径。但这没有解释 CI Node22.22.3 的零输出,不能直接认定环境噪声或既有问题。 - dashboard-browser (2), job124642204054:
goal-workspace-m2.mjs:206的已加载视图切换有一次 1514.054ms > 冻结1000ms。前序 main04c 的原生 CI 曾同样在该断言失败(1267ms);相关场景源码连续进入 base213。不过它不是精确 base213 同条件复现,也不足以证明当前 head 没有恶化。冻结阈值与失败记录均应保留。
最小补充证据是先取得租约失败子进程的完整 stdout/stderr/exit/signal,并在 CI 对应运行时重跑该精确 case;对视图预算保留原阈值,补同条件基线/当前测量或独立基础设施归因。重跑变更不变量时仍保留上述 File/SQLite caller 验证。无需为这次 PR 强行修改无关功能,也不能仅凭文件不相交撤销红灯。pending Python shards 本身不是这里的阻塞理由。
截至 2026-11-01 01:19 UTC 的 exact-head 读回共有40项检查:24 success、7 skipped、6 pending、3 failure。第三条失败是 aggregate checks,依赖上面两项失败,不是第三个独立问题;下游 coverage/acceptance 的 skipped 也没有算成通过。
我的整体评价 / Verdict
就已验证的局部目标,这是一项合适的 existing-owner 优化:long_horizon 的重复取数成本改善,user_experience 保持原流程与零新增交互轮次,默认未启用 full_text 的共享表面已做基线对照。完整正文与 Agent 作用域是既有核心保证,由现有 TypeScript Todo read owner 同时完成;Python 只传输请求并核验交付确认,不增加缓存或第二套权限判断。 当前 PR 的边界是已发货 quota should-run 工作上下文的一次快照读取及相应失败拒绝;普通 Todo CLI 展示保持原样。 原 Python 重读循环已经删除,进一步拆 helper 或增加缓存没有当前收益依据,保留普通详情和旧 runtime 的明确拒绝有实际兼容需求。
此次仅改变 quota should-run 的内部取数;已检查 live_decision、context_readback 和 Todo CLI 调用链,没有渲染或布局改动。没有新界面需要视觉资格;整个现有 Dashboard 的冻结性能 CI 红灯另行保留。
没有确认的阻塞代码 finding;当前不能给出 APPROVE,原因是上述精确 head 的验证失败仍有实质归因缺口。 本次结论是验证保留,不是把 CI 波动包装成该补丁的漏洞。没有验证模型 token、模型实际采用、端到端延迟/RSS、实验得分或重新安装 wheel;查询减少不能替代这些证据。最后读回 PR 仍为 open、head 8dd7134d9f4d6278ec6f26c356deb82e3c146f30、base 21367015cce45294dcf99f54a3211d66f5d842c5;发布前还应按 packet 再核对。补齐失败资格后,可基于 unchanged-head 的证据重新判断,不需要重新发明这项优化。
English verdict: REQUEST_CHANGES — head 8dd7134; scoped full-body and default-caller invariants pass, but current required CI failures remain insufficiently attributed. No blocking production-code defect was confirmed.
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> # Conflicts: # loopx/control_plane/todos/list_readback.py # loopx/control_plane/todos/read_transaction.ts
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
huangruiteng
left a comment
There was a problem hiding this comment.
Reviewer: model_agent | OpenAI | owner-delegated exact-head approval
动机 / Motivation
Selected User work context must include every visible User Todo body without re-reading the complete canonical source once per row. The reviewed change moves body restoration into the existing TypeScript Todo read owner after its Agent/status/archive selector, reducing a three-item User context from four canonical queries to one while preserving peer exclusion and complete bodies.
改动思路 / Approach
Reuse the existing canonical snapshot, selector, bounded list response and Python delivery acknowledgement. full_text disables only the compact presentation cap and restores bodies from the same source records; duplicate/ambiguous identities fail closed. The current-main summary queue mode remains independent, and combining full_text with thin, json_references or summary is rejected.
具体改动 / Changes
Exact head 41e9df28c33f23bbfcd0cf491a77830392af40b5 is based on current main 2f2c4efadf0c3ac21c51f7fc09f4985c8447642e. The final diff remains six files. Conflict resolution with current main preserves both the PR's full-text path and main's newer summary overview without adding persistent state, a second paginator, a cache, a CLI flag or another permission owner.
对主干的风险 / Risks
No blocking code or validation finding remains. The highest risks are broadening Agent scope, returning only summary bodies, mixing full_text with compact views, or accepting an old runtime that ignores the delivery acknowledgment. The File/SQLite suites exercise scoped and peer-excluded bodies, exact parity, old-runtime refusal, invalid booleans and compact-mode conflicts; the current body and summary modes are mutually validated.
Exact-head validation passed: selected-work and summary Python suites 20/20; Todo read and summary TypeScript suites 42/42; malformed task-lease CLI envelope 1/1 under the current Node runtime; packaged goal-workspace M2 passed 200 items with five loaded-view switches of 91, 92, 114, 66 and 74ms against the unchanged 1000ms limit. Chat build, typecheck, Ruff, compile and diff checks passed. Standard premerge passed 6 direct and 17 selected checks plus CQR and boundary scan with zero failures or manual holds. CQR cqr_8930c96dd0caf8aa507f is valid for the exact six-file scope.
The previous CI failures remain historical observations. Their relevant malformed-input and loading-budget findings now have fresh passing evidence at the current head; pending remote shards and broader latency/token benefit remain separate qualifications.
我的整体评价 / Verdict
APPROVE. The change is a bounded existing-owner optimization with explicit mode isolation and retained scoped-body guarantees. The prior verification hold is resolved by current-head reruns, while no product regression or contract gap was found.
English verdict: APPROVE — 41e9df28c33f23bbfcd0cf491a77830392af40b5 preserves scoped full-body delivery and summary compatibility, passes the formerly unresolved CI counterexamples, and needs no second reader or cache.
Resolved at 41e9df2: the malformed task-lease CLI case returns its typed JSON envelope under the current Node runtime, and packaged goal-workspace-m2 passes all 200 items with loaded-view switches of 91/92/114/66/74ms under the unchanged 1000ms budget. Functional full-body/scope tests and standard premerge pass; no product-code finding remains.
Goal And Delivered Outcome
Inline work context currently fetches a scoped User Todo inventory and then repeats a whole canonical query for each body. Read the complete selected bodies from the same canonical snapshot instead. A synthetic case with three visible User Todos drops from four Todo queries to one, with record equality against the old exact reads.
中文:User Todo 内联上下文改为一次快照查询;先由现有 TypeScript owner 筛选,再恢复完整正文,保留 Agent 隔离与权限边界。
Author Declaration
Written by: model_agent — OpenAI GPT-6 family.
Implemented against the existing complete/scoped work-context contract in
docs/project-agent-todo-contract.mdand the canonical Todo read transaction at main21367015cce45294dcf99f54a3211d66f5d842c5. TypeScript continues to own scope, status, archive selection and body matching. Python carries the internal full-text read request and requires its delivery acknowledgement, so an older runtime cannot silently supply a truncated inventory as complete context.Complete for the User context N+1 query path. No persistent cache, permission, default CLI presentation, new CLI flag, screen or model prompt. Ordinary inventories and exact reads preserve their paths. Unknown or ambiguous bodies remain a refusal, not permission. This complements #7761's separate field-discovery work; it does not replace it.
Self-check: inspected default-off behavior, canonical source identity, peer isolation, exact-body parity and packaged runtime integration. No independent review is claimed.
Validation
Tested revision: 8dd7134; synthetic fixtures only.
One local rerun initially scoped the qualified Node environment to only the first shell command; Python then used the old unqualified SQLite runtime. Explicit PATH/LOOPX_NODE_BIN fixed the test environment and the final suite passed without relaxing driver qualification. The first installed synthetic fixture omitted canonical schema/source-section fields; the fixture was corrected, not the validator.
The observed 75% reduction is in this three-item query count only. It is not a measured token, cost, whole-run latency or native-score improvement. No model, evaluator or benchmark run was launched. Remote CI and independent review remain separate.
Frontend And Boundaries
Internal data acquisition behind the shipped work-context journey; no visual/layout changes, screenshots N/A. No raw private trajectories, verifier output, keys or machine paths. Dedicated branch, explicit staging and DCO signoff. No merge performed.
Current-Main Integration And Review Gap Closure
Exact head:
41e9df28c33f23bbfcd0cf491a77830392af40b5, based on currentmain2f2c4efadf0c3ac21c51f7fc09f4985c8447642e.The current-main conflict was limited to the Todo list request and TypeScript read transaction. Resolution preserves both this PR's
full_textone-snapshot path and main's subsequentsummaryqueue overview. The request modes are explicit and mutually exclusive:full_textrejectsthin,json_referencesorsummary.Validation on the integrated head:
goal-workspace-m2passed all 200 items; the five loaded-view switches were 91, 92, 114, 66 and 74ms, below the unchanged 1000ms budget.cqr_8930c96dd0caf8aa507fis valid for fingerprint8930c96dd0caf8aa507f685475f33312e375fb31d8a5452b7006e85cc00b381d.The earlier CI failures are therefore retained as historical observations, not relabeled as product regressions.