Repository navigation
feat(mcp, objectql, driver-sql): query_records latestPer, each X with its latest Y in one call - #35199
Conversation
…WIP) Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
… engine and tool Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
Each account's, owner's and deal's latest row under the member's row policy, field withholding and the organization wall; the cap and truncated flag. Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
… Turso remote face; changeset Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
…truncation flag stays local to the latestPer answer Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
…he stdio door counts its total Claude-Session: https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi Co-authored-by: Claude <noreply@anthropic.com>
…; declare the new read site and module to their ledgers Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
…nNotice Claude-Session: https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi Co-authored-by: Claude <noreply@anthropic.com>
…claude/issue-35145-mcp-latest-per-and-related-read # Conflicts: # packages/mcp/src/mcp-http-tools.ts # packages/mcp/src/stdio-data-bridge.stored-metadata-body.test.ts
…p-latest-per-and-related-read # Conflicts: # packages/mcp/src/mcp-http-tools.ts # packages/mcp/src/stdio-data-bridge.stored-metadata-body.test.ts
📓 Docs Drift CheckThis PR changes 6 package(s): 52 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 11 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 59 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin aef3a0d6acac5ac50c523b0307a8fe9181c1dcbb && git checkout aef3a0d6acac5ac50c523b0307a8fe9181c1dcbb
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin ba6556c617bc201f1d4b635c609b28b589583c36 303482dda2b7d2aebe857f06b5ef9b4b709daad4 && git checkout -B drift-repro ba6556c617bc201f1d4b635c609b28b589583c36 && git merge --no-ff 303482dda2b7d2aebe857f06b5ef9b4b709daad4
node scripts/docs-audit/affected-docs.mjs --json ba6556c617bc201f1d4b635c609b28b589583c36
|
|
repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL Contract-review-claim: session_01JQwxbaX2qDxUq9sF93EqqL · head |
|
repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL Contract reviewServed-tier: Inputs read: card #35145 (body, triage 6972038283, claim 6973844822, amendment 6974061928, the two regrades, os-dev-report 6979530359), PR #35199 (body, 27-file list, net diff against ① Derived judgmentsPublic surface, each change judged:
Read-path bound: is every row the new shape returns held to the same walls a plain
② Semver levelThe changeset Both declaration lines appear, line-initial, in the PR body and the changeset body:
These are right. The change adds a read form on the published MCP tool surface and new exports, and it adds no spec key, no accepted metadata value and no metadata type. The AGENTS.md changeset rule then ships a non-protocol widening as Clause-②: yes (widening): matches the diff. A published MCP tool input is widened, and every pre-existing call is unchanged. ③ Boundary flags
Implemented-by: VERDICT: PASS |
|
repo:objectstack#1 · os-warren · session_01JQwxbXr9wLAH24MEgxaLud 席位核对L1 full · ACCEPT · Head-sha: Net diff against merge base Against the card
Rules checked at the head
Declarations, docs, merge
Nits (none blocks)
Not mine, still owed before landing
|
|
repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL Landing · 2026-11-18T13:45Z. Head
Marked ready, and auto-merge is armed. |
… the aggregate order and cut Five adjacent-insertion conflicts, each resolved keeping both sides: the engine exports and the runtime imports of AGGREGATE_ORDER_CUT beside LATEST_PER (objectql index, runtime action-execution and domains/mcp), the two Symbol.for read options in the stdio bridge, and the aggregation-entry test, where the order-and-cut describe block and #35202's lookup-label block both land after the served-schema block. mcp-http-tools.ts merged without conflict. Claude-Session: https://claude.ai/code/session_01JQwxbWDsbbJizuYnDwBxT8 Co-authored-by: Claude <noreply@anthropic.com>
…e order and cut One conflict, in packages/mcp/src/stdio-data-bridge.ts, resolved keeping both sides: the two Symbol.for read-option constants (this branch's STDIO_AGGREGATE_ORDER_CUT and #35199's STDIO_LATEST_PER), each under its own docblock, then #35225's stdioExpandMap byte-identical to main, then unwrapRows under its own docblock. mcp-http-tools.ts and runtime domains/mcp.ts merged without conflict. Claude-Session: https://claude.ai/code/session_01JQwxbWDsbbJizuYnDwBxT8 Co-authored-by: Claude <noreply@anthropic.com>
Part of #35145 (PR 1 of 2:
latestPeronquery_records; the card's second half stays open for PR 2)Clause-②: yes (widening): a new read form on the published MCP tool surface. Judged from the card content; the build confirms it
Metadata-protocol: none
维护者速读
query_records新增latestPer参数,一次调用就能回答“每个客户的最新一笔商机”这类“每组取最新一条”的问题,每组恰好返回一行。latestPer的调用完全不变;新参数只在 SQL 驱动上执行,其它驱动直接拒绝、不读任何数据。回滚即撤销本 PR,无数据迁移。packages/objectql/src/latest-per.ts(哪些驱动、哪些对象、哪些字段允许)、packages/drivers/driver-sql/src/sql-driver-latest-per.ts(窗口子查询,注意租户条件与 where 在窗口内部生效)、packages/objectql/src/engine-find.ts(请求在安全条件合成之后才交给驱动)。pnpm --filter @objectstack/driver-sql exec vitest run --maxWorkers=2 src/sql-driver-latest-per.test.ts,预期 SQLite 8 条全绿(每个客户只回最新一笔,平局按 id,空日期排最后)。What changes
query_recordstakeslatestPer: { by, orderBy }and answers one row per group: the group's first row in the given order.bynames 1 to 3 fields;orderBy1 to 3 keys,ascordesc. A tie goes to the record id in the direction of the last key; an empty order value ranks last.packages/mcp): the argument is bounded in the tool's input schema (strict object, 1 to 3 of each).limitcounts groups and is capped like any list. The answer is{ object, records, hasMore }and never atotal; when more groups exist than came back it carriestruncated: true, set byquery_records' sharedservedQueryPage(feat(mcp): query_records says truncated: true on a capped page, and the stdio door counts its total #35185) from the door'shasMore(the door reads one group past the page). A plainquery_recordscall is unchanged here.McpLatestPeris a new exported type. A bridge answer that is not one page of groups is a coded server fault, never passed on as a list. The stdio bridge carries the request the same way.packages/runtime:domains/mcp.ts,action-execution.ts;packages/metadata-protocol:findData): the request rides an in-process symbol member, never a wire or query key.findDatachecks the partition and order fields exist and meet the same stored-field rules asorderBy, refuseslatestPerwithgroupByor aggregations, readslimit + 1, and confirms the engine served the window before answering.packages/objectql: newlatest-per.ts,engine-find.ts): the request is checked before anything is read. Its partition and order fields join the read's sort keys while the read is judged, so every field it reaches meets the same checks asorderBy(a field the caller may not read is refused). The directive is handed to the driver only at the executor boundary, on the fully composed read, and the judged keys are taken back off. Served by the SQL driver anddriver-sqlite-wasm, and by the Turso driver on a local or embedded-replica database. Refused withINVALID_QUERY/ 400, nothing read: every other driver (in-memory, Turso's remote face, MongoDB), a federated object, an object with anafterFindhook or object-scoped read middleware. A computed, JSON or multi-value field, or a dotted path, is refused as a partition or order field (INVALID_FIELD).packages/drivers/driver-sql: newsql-driver-latest-per.ts,sql-driver-crud.ts):findadds one predicate,id IN (SELECT id FROM (SELECT id, ROW_NUMBER() OVER (PARTITION BY … ORDER BY …, id) FROM t WHERE tenant AND where) WHERE rn = 1). The window is chosen among the rows the read's own scope andwhereadmit, so the organization wall and every composed condition hold inside the choice. The read's own ORDER BY, projection, limit and offset apply to the groups; no helper column reaches the rows. The Turso driver's remote face refuses the directive itself too.@objectstack/specis unchanged. Docs:content/docs/ai/connect-mcp.mdxgains alatestPersection.Tests
packages/drivers/driver-sql/src/sql-driver-latest-per.test.ts, on the live dialect matrix: one row per group, ties to id, NULL last, ascending, awherethat hides a group's newest row (the newest admitted row answers), the tenant wall, two partition fields, the read's own ORDER BY / limit / offset / projection, no helper column, a control without the directive, a malformed directive refused.packages/objectql/src/latest-per.test.ts: the directive lands on the composed read after middleware; middleware sees the judged keys; the field gate refuses with no driver call; the driver allowlist and every refusal (memory, MongoDB, Turso remote and faceless,afterFind, object middleware, field kinds, shape); controls served on sqlite-wasm and Turso local and replica.packages/metadata-protocol/src/protocol.find-data-latest-per.test.ts:limit + 1on the engine option, nototaland no COUNT, an unserved window isINTERNAL_ERROR/ 500, an undeclared field refused before the engine, no combining withgroupBy.packages/mcp/src/mcp-query-records-latest-per.test.ts: the tool's bounds, forwarding, the cap,truncated, the no-answer case; the stdio bridge's option and probe.packages/drivers/driver-sqlite-wasm/src/sqlite-wasm-latest-per.test.tsandpackages/drivers/driver-turso/src/remote-transport-latest-per-refusal.test.ts: the wasm dialect serves the window; the Turso remote face refuses with no statement sent.packages/qa/dogfood/test/latest-per-over-mcp.dogfood.test.ts: the CRM example over the live/mcptransport with the security plugin and a real two-organization wall. A member's agent asks for each account's, each owner's and each deal's latest row. A row policy hides the newest deal of one account: the answer is that account's newest row the member can read, never the hidden one and never nothing. Also: a partition or order field the member may not read is refused and a withheld field stays withheld; the other organization's newer rows never win; 55 groups answer 50 rows withtruncated: true; a control withoutlatestPer. Armed controls check the wall is real, the hidden row is the newest at rest, and the row policy binds.Acceptance notes
latestPerreaches only the object named inobjectName.Refs #35145; this body usesPart of #35145, which is the non-closing spelling the dev standard names. Neither closes the card.Verification
All readings below are from head
303482dda2bunless a block says otherwise.Targeted suites on the final head (os-verify-lock VERDICT command-exit 0)
@objectstack/mcpfull suite: Test Files 73 passed (73), Tests 1292 passed (1292)latest-per.test.ts+federated-injected-column-readers.test.ts: Tests 28 passed (28)sql-driver-latest-per.test.ts: Tests 16 passed, 1 skipped (SQLite and a local Postgres 16 cell at Asia/Shanghai; the MySQL cell had no server here)protocol.find-data-latest-per.test.ts: 5 passedlatest-per-over-mcp.dogfood.test.ts: Tests 7 passed (7)Full suites of the touched packages (head 837e5b6, before the two merges; TZ=America/New_York, Postgres at Asia/Shanghai)
Dogfood battery on the final head
pnpm --filter @objectstack/dogfood testunder os-verify-lock: VERDICT command-exit 0 · Test Files 481 passed, 3 skipped (484) · Tests 4132 passed, 18 skipped (4150).Ablation of the driver directive (head a40fc2c; the driver code is unchanged since)
node scripts/ablation-replace.mjsturnedif (latestPer !== undefined) {insql-driver-crud.tsintoif (latestPer !== undefined && false) {(anchor 1 to 0, blob ddd18cc to 453444f).sql-driver-latest-per.test.tswent red: 5 failed, 3 passed (one row per group, ascending, the hidden newest, two partition fields, paging and projection). The three that held do not depend on the predicate: the tenant wall, the control and the malformed directive. Restore: blob back to ddd18cc,git diff HEADempty.Derived gates
node scripts/pm/dispatch-gates.mjs --commandson head303482dda2b: 124 families. All run locally, every exit 0.check:type-check-debtwas re-run under the lock and printed OK.check:pm-dispatch-gatesexited 0 at headd8341c37620; none of its inputs changed after that.--ranreconciliation: 124 derived, 124 run, 0 unrun.node scripts/check-platform-checklist.mjs --changed-from origin/main: OK, 0 anchors lost.Generated by Claude Code