From 384fc0f5318516aea89fcf512df47a65f0514d7e Mon Sep 17 00:00:00 2001 From: aihop <4408344+hhyykk@users.noreply.github.com> Date: Fri, 23 Oct 2026 13:58:54 +0800 Subject: [PATCH] perf(todos): push exact selection into canonical projection Signed-off-by: aihop <4408344+hhyykk@users.noreply.github.com> --- .../rfcs/typescript-control-plane-migration-v0.md | 3 +++ .../typescript-control-plane-migration-v0.zh-CN.md | 2 ++ loopx/control_plane/todos/read_projection.ts | 3 +++ tests/control_plane_ts/todo_read.test.ts | 12 ++++++++++++ 4 files changed, 20 insertions(+) diff --git a/docs/architecture/rfcs/typescript-control-plane-migration-v0.md b/docs/architecture/rfcs/typescript-control-plane-migration-v0.md index 519d12ed6c..55a581d47e 100644 --- a/docs/architecture/rfcs/typescript-control-plane-migration-v0.md +++ b/docs/architecture/rfcs/typescript-control-plane-migration-v0.md @@ -181,6 +181,9 @@ before materializing requested evaluations. Source fingerprinting still reads every admitted byte and rechecks freshness; sequential reads avoid starting a thread pool in each process. Healthy read commands use canonical registry/path owners and defer mutation error imports until needed. +Exact detail queries push selection into the existing source projection after +complete source validation. Queries that report unfiltered counts retain the +complete first projection. The output measurements above retain their original controlled-transport scope. [#6874](https://github.com/loopx-project/loopx/pull/6874) records the original normal-IPC, package and complete-command evidence. Follow-up measurements apply diff --git a/docs/architecture/rfcs/typescript-control-plane-migration-v0.zh-CN.md b/docs/architecture/rfcs/typescript-control-plane-migration-v0.zh-CN.md index 9875fdcc6d..3ae639aacb 100644 --- a/docs/architecture/rfcs/typescript-control-plane-migration-v0.zh-CN.md +++ b/docs/architecture/rfcs/typescript-control-plane-migration-v0.zh-CN.md @@ -146,6 +146,8 @@ Canonical 摘要仅在某角色组包含恢复条件时准备恢复历史。 该 owner 先校验并索引完整图,再生成需要返回的评估。 源码指纹仍读取每个已准入字节并复查新鲜度;顺序读取省去每个进程的线程池创建。 正常读取直接使用注册表和路径的 canonical owner,发生错误时才导入相关错误类型。 +精确详情查询在完整来源校验后,将筛选下推到既有来源投影。 +需报告未筛选数量的查询仍保留完整的首次投影。 上述输出测量保留原受控传输范围。 [#6874](https://github.com/loopx-project/loopx/pull/6874) 记录原始正常 IPC、安装包及完整命令证据。 后续测量仅适用于各自记录的精确版本。 diff --git a/loopx/control_plane/todos/read_projection.ts b/loopx/control_plane/todos/read_projection.ts index a4a0c4d41d..02c352c625 100644 --- a/loopx/control_plane/todos/read_projection.ts +++ b/loopx/control_plane/todos/read_projection.ts @@ -206,6 +206,8 @@ export async function projectCanonicalTodoFields(input: JsonObject): Promise requireJsonObject(value, "Todo lineage")) : all; const lineageFacts = input.lineage_facts ?? lineage.map(successionFacts); + const query = input.kind === "query" && input.selection == null ? object(input.query) : {}; + const detailId = query.agent_id == null && query.limit == null ? query.todo_id : null; const fields: JsonObject = {}, evaluations: JsonObject = {}; for (const role of ["user", "agent"]) { const section = role === "agent" ? "Agent Todo" : "User Todo / Owner Review Reading Queue"; @@ -214,6 +216,7 @@ export async function projectCanonicalTodoFields(input: JsonObject): Promise readResume(row.resume_when)) ? all.map(row => structureCanonicalTodo(row, row.role ?? null, row.source_section ?? section)) : []}); if (grouped.rejection) return grouped; diff --git a/tests/control_plane_ts/todo_read.test.ts b/tests/control_plane_ts/todo_read.test.ts index 5504bd1255..a6a28cb2ec 100644 --- a/tests/control_plane_ts/todo_read.test.ts +++ b/tests/control_plane_ts/todo_read.test.ts @@ -183,6 +183,9 @@ test("query display limits preserve complete source coverage and report the fina {name: "thin", query: {thin: true}, available: 30, shown: 4}, {name: "references", query: {json_references: true, limit: 1}, available: 30, shown: 2}, {name: "exact", query: {todo_id: items[0].todo_id}, available: 1, shown: 1}, + {name: "exact agent scope", query: {todo_id: items[0].todo_id, agent_id: "agent-a"}, available: 1, shown: 1, unfiltered: 30}, + {name: "exact limit", query: {todo_id: items[0].todo_id, limit: 1}, available: 1, shown: 1, unfiltered: 30}, + {name: "exact other role", query: {todo_id: items[0].todo_id, role: "agent"}, available: 0, shown: 0}, {name: "missing", query: {todo_id: "todo_missing"}, available: 0, shown: 0}, ]; for (const scenario of cases) await t.test(scenario.name, async () => { @@ -201,5 +204,14 @@ test("query display limits preserve complete source coverage and report the fina assert.equal(coverage.shown_count, scenario.shown); assert.equal(coverage.available_count, scenario.available); assert.equal(coverage.truncated, scenario.shown < scenario.available); + if ("unfiltered" in scenario) assert.equal(payload.unfiltered_todo_count, scenario.unfiltered); }); + const invalidItems = items.map((item, index) => index === 1 ? {...item, updated_at: 123} : item); + const invalid = {...projection, todos: invalidItems, + todo_read_model: coordinationTodoReadModel(invalidItems, TODO_CANONICAL_READ_RECORD_SCHEMA)}; + assert.equal((await store.commitAuthority({expected_provider_revision: committed.provider_revision, + operation_id: "invalid-unselected-coordinate", events: [], next_projection: invalid, receipts: []})).status, "applied"); + await assert.rejects(() => readTodo({schema_version: TODO_READ_REQUEST, kind: "query", + source: {runtime_root: root, goal_id: goal}, observed_at: Date.parse(now) / 1000, evaluated_at: now, + query: {goal_id: goal, todo_id: items[0].todo_id, read_scope: "active", state_file: state}}), /invalid summary completion coordinates/); });