Repository navigation
feat(service-knowledge): search_knowledge takes scope, granularity and groupBy - #37393
Conversation
…d groupBy ADR-0161 K9 rule 2: the one search_knowledge definition gains the three arguments the knowledge service reads; the executor bounds and hands them over, the hit gains headingPath and groupValue, and MCP pins the real definition over HTTP and stdio. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXPpBL56eaDCJ6MFm4
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXPpBL56eaDCJ6MFm4
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXPpBL56eaDCJ6MFm4
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXPpBL56eaDCJ6MFm4
📓 Docs Drift CheckThis PR changes 2 package(s): 20 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 5 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 13 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 0aa1be7c32a6d38e81eff394b446644c5cc2da3a && git checkout 0aa1be7c32a6d38e81eff394b446644c5cc2da3a
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e8740c55f0eaba7571c16a5588c833fe29e176ac 44e00dcf1b4ff8bdda1910184d03f2c0fbed1ea7 && git checkout -B drift-repro e8740c55f0eaba7571c16a5588c833fe29e176ac && git merge --no-ff 44e00dcf1b4ff8bdda1910184d03f2c0fbed1ea7
node scripts/docs-audit/affected-docs.mjs --json e8740c55f0eaba7571c16a5588c833fe29e176ac
|
…ilter check:objectql-double-limit flagged the MCP transport test's find double as limit-blind; the service-knowledge double gets the same bound. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXPpBL56eaDCJ6MFm4
|
repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U 维护者速读
席位核对REWORK — the executor is correct against K9 rules 2, 3, 5 and 6 and every check at the head is green, but one sentence of the definition's description (repeated in the docs and the changeset) is false for Head-sha: First review of this PR. Five commits on merge base 形态
门禁 check-runs (at
逐项核对与消融 (27 single-change ablations at this head, each restored with an empty
dev 三条备注的裁定
逐句核的散文面
修复清单 (grades are in the contract record below)
接受的偏差
范围外去向
落地条款
Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
M1 (must-fix) — the description, and the docs and changeset after it, say a source that does not index the S2 (should-fix) — no case goes red when the S3 (should-fix) — no case goes red when the JSON quoting of caller strings is removed. S4 (should-fix) — the listed schema is not compared whole with the real definition; a transport-side edit of bounds and descriptions stays green. S5 (should-fix) — the MCP bound case pins no shape, and the docs and PR body state the coded refusal for shapes an MCP client's schema check refuses first. Implemented-by: VERDICT: FAIL |
… pin the guard, the quoting and the listed schema The description, the docs and the changeset said a source without the groupBy field answers nothing; a file / http source answers one hit per document with no groupValue. Pin the groupValue guard, the JSON quoting of a short caller string, the listed MCP schema against the definition, and what each MCP door answers for a schema-level and an executor-level refusal. The scope bounds are read from the service's constants. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXPpBL56eaDCJ6MFm4
|
repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U 维护者速读
席位核对ACCEPT — the five findings of round 1 are closed at this head, each by a case that goes red when its line is removed, and the delta changes no behaviour. Every check at the head is green or an expected skip. One nit is declined with a reason and stays an accepted deviation. Head-sha: Delta review: one commit on 形态
门禁 check-runs (at
逐项核对与消融 (5 single-change ablations at this head, each restored with an empty
逐句核的散文面 (delta sentences)
修复清单
接受的偏差 (round 1's, plus one)
范围外去向 (unchanged)
落地条款
Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
M1 (must-fix): closed. S2 (should-fix): closed. S3 (should-fix): closed. S4 (should-fix): closed. S5 (should-fix): closed. Implemented-by: VERDICT: PASS |
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 45747428966 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 分类: 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 45751264432 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 分类: 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
Requested by Warren · project thread
Fixes #37311
Clause-②: yes
Metadata-protocol: none
维护者速读
What changes
ADR-0161 K9, rule 2: the one
search_knowledgedefinition (packages/services/service-knowledge/src/knowledge-tools.ts) gainsscope,granularityandgroupBy, the optionsIKnowledgeService.searchalready reads (#37103 for the last two, #37308 for the first). No transport adds or edits an argument: the MCP HTTP door and stdio register the definition as handed over, and the hosted agent registers the same one through objectstack-ai/cloud#4933.The definition.
SEARCH_KNOWLEDGE_PARAMETERSdeclares:scope:minItems: 1,maxItems: 10entries of{ object, ids }(additionalProperties: false),idsminItems: 1,maxItems: 500; every name and idminLength: 1,maxLength: 255.granularity:enum: ['chunk', 'record'].groupBy:minLength: 1,maxLength: 255.The description tells the model when to use each one, and names the two new hit members,
groupValue(the stored value: a string, a number or a list) andheadingPath. UndergroupBy, an object source that does not list the field answers nothing, and afile/httpsource answers one hit per document with nogroupValue.topK's text now says it counts records or groups in those modes. New exports:SEARCH_KNOWLEDGE_MAX_SCOPE_ENTRIES(10) andSEARCH_KNOWLEDGE_MAX_SCOPE_IDS(500), read from the service's ownSEARCH_SCOPE_MAX_ENTRIES/SEARCH_SCOPE_MAX_IDS, andSEARCH_KNOWLEDGE_MAX_NAME_LENGTH(255), with the typesSearchKnowledgeScopeEntryandSearchKnowledgeGranularity.The door (
parseInput). The executor refuses each malformed valueVALIDATION_ERROR(400) before the service is asked, and the message names the argument. Over MCP, a shape the schema states (an empty or over-longscope, a string over 255 characters, an unknowngranularityor key) is refused first by the SDK's input validation:-32602, naming the argument, with no ADR-0112 code. The coded refusal answers what the schema cannot state (a NUL,groupBywith"chunk"), and everything the in-product agent sends. Carried from the #37308 reviews:sys_recycle_bin.record_id/object_name,maxLength: 255).JSON.stringify, so a control character reads as its escape, and cuts it to 64 characters. It lists at most five strings, then "and N more". At the executor, this also covers the two refusals that existed before this PR: an unknown key, and an unknownsourceIdsentry. Over MCP, the SDK's refusal of an unknown key repeats it as sent; that path predates this PR and the seat files it separately.groupBywithgranularity: 'chunk'is refused at the door, naminggroupBy. The service refuses it too.The executor. It hands
scope,granularityandgroupBytosearchWithRefusalsas its options of the same names.aiExposedstays enforced here (K9 rule 3). The service is asked only about exposed sources, so ascopeentry orgroupByfield that only a withheld source would answer gets exactly the answer one no source answers: no hits.The answer.
hitOfstays a whitelist and gains two members:headingPath, where the passage has one.groupValue: undergroupBy,metadata[groupBy], and only for an object source that lists that field inmetadataFields. Source admission holds every listed field queryable by the caller.chunkId,docHashandmetadatanever reach the answer. Nothing in the answer counts hits that the permission re-check or the scope removed (K9 rule 6).Docs.
content/docs/ai/knowledge-rag.mdxgains a section on thesearch_knowledgetool: the six arguments, the hit's members, where the tool is stricter than the service, and the withheld-source rule.Surface widened (claim amended by the seat at 2026-11-26 01:15Z, for this test only).
packages/mcpnow dev-depends on@objectstack/service-knowledge, with one source alias inpackages/mcp/vitest.config.tsand its importer line inpnpm-lock.yaml. This is the same arrangementservice-record-contextalready has. The transport test needs the REAL definition:registerKnowledgeToolssilently registers nothing whenz.fromJSONSchemacannot convert a definition (mcp-http-tools.ts,registerKnowledgeTools), and the nestedscopeschema is the shape that could trip that conversion. It converts whole: no change to the definition's shape was needed.Tests
service-knowledgeknowledge-tools.test.ts(56 cases, 22 of them new refusals) checks the following against the realKnowledgeService:searchWithRefusalsunchanged;groupByone per group with itsgroupValue, andscopeonly the named records;groupByover afilesource whose hit carriesmetadata[groupBy]: one hit per document, nogroupValue(the guard inhitOf);headingPathandgroupValuepresent;docHash,chunkIdandmetadataabsent);toEqual, carrying no count when the re-check and the scope both removed hits;scopeand agroupBythat only a withheld source would answer, compared with an absent object and an absent field. The answers are identical, the withheld adapter is never asked, and the adapters asked are the same.mcpmcp-knowledge-tools.test.ts(18 cases, 6 of them new) runs the real definition and executor behind a stdio bridge, over HTTP and over stdio:tools/listreturns byte-identicalsearch_knowledgedefinitions with the three arguments. Stdio is read raw off the transport, because the SDK client's result parse re-orders an input schema's keys. The listed input schema, less$schema, equals the definition'sparametersbytoEqual, so any transport-side schema edit is red.granularity: 'record',groupByandscopeeach answer the same text on both doors, with the expected hits.isError,-32602, namingscope, the same text on both doors.VALIDATION_ERRORnamingscope, the same text on both doors.Local runs at 44e00dc, 1ebae53 and 4a2b34e
44e00dcf(the L1 round):knowledge-tools.test.ts56/56;mcp-knowledge-tools.test.ts18/18; both packages'typecheckgreen;eslint --no-inline-configon the three touched source/test files clean;check-nul-bytesOK. Ablations throughscripts/ablation-replace.mjs, each restored blob == HEAD: thegroupValueguard removed, 1 red (S2);JSON.stringifyreplaced by plain quotes inquoted, 1 red (S3);registerKnowledgeToolsrewritinggroupBy's schema before conversion, 2 red over MCP (S4).1ebae539:knowledge-tools.test.ts54/54;mcp-knowledge-tools.test.ts17/17;pnpm --filter @objectstack/service-knowledge --filter @objectstack/mcp typecheckgreen.1ebae539only bounds the two new engine doubles by the caller'slimit(CI'scheck:objectql-double-limitcaught the MCP one as limit-blind at4a2b34e8; it is green locally now).4a2b34e8:pnpm --filter @objectstack/service-knowledge test: 13 files, 414/414;pnpm --filter @objectstack/mcp exec vitest run: 85 files, 1520/1520.node scripts/check-nul-bytes.mjs: OK.4a2b34e8, run in a scratch worktree throughscripts/ablation-replace.mjs(dependencies'dist/linked in), one change each. Every one was restored with blob == HEAD and an emptygit diff HEAD.scopenot handed to the service: 4 red inknowledge-tools.test.ts; 1 red over MCP (scope on both doors).granularitynot handed over: 1 red over MCP.groupBynot handed over: 1 red over MCP.docHashadded tohitOf: 2 red (the whitelist, the whole answer).groupValuenever set: 2 red.groupBy).aiExposedfilter removed: 9 red.Acceptance notes
scopeand an entry with no ids are refused at the tool, whereIKnowledgeService.searchanswers them with no hits. This matches the tool's own rule for an emptysourceIds: a call that names nothing would answer no passage, which the description tells the model to report as "nothing matched". The service keeps its row-11 behaviour for its own callers. The reviewer should confirm this reading of "bounded as row 11 bounds it" (card item 1).groupValueis the stored value, unparsed. It is a string for a text or lookup field and can be a number, a boolean or a list (amultiplelookup). It is typedunknownand the description does not promise a type. Afile/httphit undergroupBycarries none, because it stands for its document.sourceIdsitems gain no length bound. Only the refusal message cuts them. The carried rule names the scope's ids, and addingmaxLengthtosourceIdswould change an existing argument's schema.Verification
Read first, by risk:
knowledge-tools.ts,parseScope/isName, and the executor'ssearchOpts.knowledge-tools.ts,hitOf: the whitelist and thegroupValueguard.mcp-knowledge-tools.test.ts, the lastdescribe(the real definition on both doors).Two-minute check:
pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2 src/mcp-knowledge-tools.test.ts→ 18 passed, including "tools/list over HTTP and over stdio answer byte-identical definitions, carrying scope, granularity and groupBy".Gates. The local derived set:
dispatch-gates --commands, 114 commands, reconciled with--ran. 111 exited 0. 3 exited 3, PREREQUISITE NOT MET, and are NOT MEASURED locally; CI runs them:check-plugin-teardown-shape --self-test: the clone is shallow.check:skill-examples(spec): the clientdist/is not built.check:dual-build-cjs-loads: a package has nodist/.Commands 1 to 60 ran on the
4a2b34e8tree, and 61 to 114 on1ebae539. The only change between the two is the test doubles.CI at
1ebae539: 64 success, 11 expected skips, 0 failed,mergeable_stateclean (the seat's reading). CI at44e00dcf: to be read at hand-back. The local derived set above was not re-run for44e00dcf: its delta is one description sentence, two constants now read from the service, test cases and prose.The docs drift check names 20 hand-written pages. I re-read the six that name
search_knowledge, and none of them is falsified.connect-mcp.mdx's tool row does not mention the three new arguments, but it is still true as written.🤖 Generated with Claude Code
https://claude.ai/code/session_01JQwxbXPpBL56eaDCJ6MFm4
Generated by Claude Code