Skip to content

feat(knowledge): a knowledge source declares its document unit (source.documentBy); record search groups by it by default - #38564

Merged
objectstack-fleet[bot] merged 13 commits into
mainfrom
claude/issue-38537-knowledge-document-by
Nov 29, 2026
Merged

objectstack-fleet[bot] merged 13 commits into
mainfrom
claude/issue-38537-knowledge-document-by

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread

Part of #38537
Clause-②: yes (widening)
Metadata-protocol: added

维护者速读

  • 用户能看到什么变化:知识源可以声明“文档单位”(指向父记录的字段);AI 按记录检索时,同一份父记录(如一份制度)下的多条子记录(条款)只返回一条命中,原来是每条子记录各一条;Studio 知识源表单多了一个“文档单位”选择框。
  • 为什么做:属于“知识源声明文档单位、按父记录计数与聚合”专题,替把段落写成子记录的应用(例如制度下的条款)解决按记录检索时同一份制度刷屏的问题,也是云端按父记录计文档数的前置。
  • 出错会怎样:只有声明了该字段的知识源受影响,索引内容不变、不触发重建;若分组有误,AI 检索会多返回或少返回命中,删掉该字段即恢复原行为。
  • 要你做什么:无。

What changes

PR 1 of 2 for the card. This PR lands the key, its parse rule, its save-time refusal and its first reader; the os validate rule (in the lint package, held by another seat until it is released) is PR 2, which closes the card.

  • Spec — ObjectKnowledgeSourceSchema gains documentBy?: string. A refinement refuses a value that metadataFields does not list, with a message that names the field, the list, and the fix (add it to metadataFields, name a listed field, or remove the key). The refinement is a cross-key rule JSON Schema cannot state, so it is ledgered in dropped-refinements.baseline.json (two schemas plus the four installed-package response schemas that embed a source; header totals updated).
  • Parent-link rule, exported — knowledge-search-scope.ts now exports parentLinkRule(schema) (the rule scopeTermsFor already used, factored out of the private parentLinksOf, which now calls it; scope behaviour unchanged) and documentUnitOf(field, schema) (the rule plus "not multiple: true"). Both are pure functions of the object definition, so PR 2 can call them with no knowledge service.
  • Save door — admitAuthoredSource refuses a documentBy that metadataFields lists and that is not a single-valued parent link: 400 VALIDATION_ERROR, field set, after the "does not exist" arm and before every permission arm. The sentence is built by documentUnitRefusalText in knowledge-source-admission.ts, one wording per reason (undeclared, withheld, not a link, no readable target, multiple). A documentBy that metadataFields does not list is left to the parse, which already names that fix.
  • Reader (ADR-0049, ADR-0161 K4) — in searchByKey, with record granularity and no groupBy, groupKeyOf now asks documentKeyOf(hit, documentBy): parent:SOURCE#VALUE when the hit's source declares documentBy and the hit carries a parent, else the existing per-record key. The explicit groupBy path, sourcesGroupableBy and chunk granularity are untouched.
  • Tool — hitOf sets groupValue to the parent under the default grouping too (absent for a record with no parent). documentUnitValueOf is the one predicate both the service key and the tool read. Like its groupBy arm, the tool serves the parent only for a source that lists documentBy in metadataFields.
  • Hashes — documentBy is in neither the index fingerprint nor the recipe hash (both enumerate their inputs explicitly); __tests__/index-fingerprint.test.ts is unchanged and green.
  • Form — the form-coverage gate (metadata-form-zod-reconciliation.test.ts) refused the key without a form row, so the single picker is added beside metadataFields (widget: 'field-ref', dependsOn: 'object') with its form test. This folds in the form half of Studio form, docs and skill text for knowledge source documentBy #38538; the docs and skills/** half stays there. The row brings its regenerated translation bundles (ja-JP, es-ES and zh-CN authored, the rest the extractor's fill) and the catalog's positive-control count (866 to 867).
  • Regenerated: authorable-surface, the reference page, the liveness ledger row and counts.
  • Changeset — minor for @objectstack/spec (the new authorable key), @objectstack/service-knowledge (the reader and the save refusal) and @objectstack/platform-objects (the form row's translated label and help), with Metadata-protocol: added: a new key a metadata author can write.

Zone 2 choices

  • Where the parent value is read from: the hit's own metadata[documentBy], the value assembly stored beside the passage. The parse holds documentBy in metadataFields, so every hit of such a source carries it; grouping runs over the hits the adapters already answered and reads no record (SQL first: no per-hit read was added). The freshness check and the permission re-check are unchanged.
  • Default key spelling: parent: + index key of the hit's source + # + String(value). The source key keeps two sources apart on equal parent ids; the parent: prefix keeps it apart from record: and document: keys; String() compares values as a scope term does. A value that is absent, null, empty, or not a string or finite number falls back to the per-record key, so those records are never dropped.
  • Form row: forced by the gate (it reported knowledge_source.source: accepted by the Zod but unauthorable in the form — documentBy), so it is in this PR.

Acceptance

Card acceptance line Test
Parse refuses documentBy absent from metadataFields knowledge-source.test.ts › "refuses a documentBy that metadataFields does not list…", "…when metadataFields is omitted…"
Save refuses a text field, a user field, an internal lookup and a multiple lookup, each naming the fix document-by-38537.test.ts › "refuses a text field / a user field / an internal lookup / a multiple lookup, 400 VALIDATION_ERROR, naming the field and the fix" (+ positive controls: lookup and master_detail admitted)
6 records under 2 parents + 1 null parent, record granularity, topK 10 → 3 hits document-by-38537.test.ts › "6 records under 2 parents plus 1 with no parent…: 3 hits"
Explicit groupBy: 'clause_hash' unchanged; a source without documentBy unchanged document-by-38537.test.ts › "an explicit groupBy is answered as before…", "a source without documentBy is answered as before…", "chunk granularity is answered as before"
Fingerprint pins unchanged index-fingerprint.test.ts unchanged and green; document-by-38537.test.ts › "the fingerprint and the recipe hash are the same with and without documentBy"
Default key includes the source; hitOf sets groupValue "two sources never share a group…", "search_knowledge: each hit carries its parent as groupValue…"

Ablation

Both legs run with scripts/ablation-replace.mjs (mutation verified on disk, restore verified as blob equal to HEAD and an empty git diff HEAD). No build was needed: both suites import the subject from src/.

Reader reverted (default key back to the per-record key): 4 red

Anchor if (groupBy === undefined) return documentKeyOf(...) replaced with return recordKeyOf(hit) in knowledge-service.ts. document-by-38537.test.ts: 4 failed / 12 passed — the 3-hit test, the empty-parent test, the two-sources test and the groupValue test. Restored: blob c98a03680da8 equals HEAD.

Parse rule removed (the refinement dropped): 2 red

Anchor .superRefine(refuseDocumentByOutsideMetadataFields) removed from knowledge-source.zod.ts. knowledge-source.test.ts: 2 failed / 35 passed — both refusal tests. Restored: blob 211cb6dc13af equals HEAD. (A first attempt was refused by the tool before running anything, because its replacement text already occurred in the file; it was re-run with a distinct replacement.)

Delta round 1: the tool's metadataFields guard removed: 1 red

The condition && objSource.metadataFields?.includes(objSource.documentBy) removed from hitOf in knowledge-tools.ts (on-disk count 0). document-by-38537.test.ts: 1 failed / 16 passed, the stub-service test ("expected … to not have property groupValue"). Restored from a copy (on-disk count 1) before commit 12cd7dc8a6, whose blob e49165a005 carries the condition. This leg used a copy-and-restore, not ablation-replace.mjs.

Tests

Delta round 1 (contract review 7254573293, PASS with S1 open), head e0ebb9ad8e. S1: the documentBy docblock names the save refusal alone, and says a source registered in code or installed with a package meets no save and is not judged yet. N1: the docblock and the changeset say where each surface carries the parent: metadata[documentBy] on IKnowledgeService.search, and also groupValue on a search_knowledge hit. N2: the form help reads "Setting it rebuilds nothing; adding the field to Filter fields does." The changeset says the same, and the zh-CN, ja-JP and es-ES help is retranslated. The eleven bundles are regenerated: check:i18n reports all in sync, and check:i18n-stale-fill finds no new stale fill. N3: the hitOf guard, pinned by one stub-service test with a positive control. Claim widening: the contract TSDoc and the tool description above. Readings on e0ebb9ad8e:

Delta round 1, second commit, head 43de68d58f. The claim was amended to add the topK TSDoc and the tool's granularity input description. Both now say what the fixed docblocks say: "for a source that declares documentBy (its document unit), one hit per parent record instead". So do the other record-unit sentences in the two files (see Acceptance notes). Readings on 43de68d58f:

The @objectstack/mcp knowledge-tool tests compare the listed description with the definition itself and pin no text, so they were not re-run here.

Earlier, the head was 5bbac4b457, a clean merge of main that brings in #38509 (the record sync change in knowledge-service.ts). Re-checked on that head: @objectstack/service-knowledge test 23/23 files, 802/802 tests; its typecheck exits 0; @objectstack/spec check:generated reports all 14 artifacts up to date; overlap-check finds origin/main merges cleanly. Below it, 231e7c6339 changes only the changeset (level minor, Metadata-protocol: added); the changeset families were re-run there (check-changeset-no-major with this body as its event payload, check-empty-changeset, check-adr-0087-registration, all exit 0). The gate union was re-run after the last code commit, at a92874657e (the translation commit landed while it ran, and the families that read it, check:i18n, check:i18n-stale-fill and check:nul-bytes, were run again on a92874657e).

Package suites and typecheck
  • pnpm --filter @objectstack/service-knowledge test — Test Files 23 passed (23), Tests 788 passed (788). typecheck (tsc + test layer) — exit 0.
  • pnpm --filter @objectstack/spec test — Test Files 912 passed / 1 failed (913), Tests 28895 passed / 1 failed: the dropped-refinements ledger's header totals; corrected, scripts/dropped-refinements.test.ts re-run 30/30. typecheck — exit 0.
  • pnpm --filter @objectstack/platform-objects test — Test Files 130 passed (130), Tests 2218 passed (2218). typecheck — exit 0.
  • pnpm --filter @objectstack/spec check:generated — two stale artifacts found (reference page, liveness counts), regenerated with --fix, re-checked green.
Derived gate families (dispatch-gates --commands, 120)

node scripts/pm/dispatch-gates.mjs --ran — "120 derived, 120 run, 0 NOT-MEASURED, 0 UNRUN"; every family exit 0 on the re-run. On the first run three families refused with exit 3 (prerequisite not met: no built CLI, client-react or package dists); each was built and re-run green, and check:i18n then reported the form row's bundles drifted, regenerated in this PR.

Not run locally: check:i18n-coverage (not derived for this diff; prerequisite needs the example apps built) and every CI-only family; CI reports them on this PR. Dogfood: n/a (no ! in the title, no (narrowing) arm).

Acceptance notes

  • Files beyond the original claim's list, each forced by a Zone 1 line (recorded by the claim amendment on the card): the save refusal is wired in admitAuthoredSource in knowledge-service.ts (the save-time admission lives there, not in knowledge-source-admission.ts, which holds the sentence); dropped-refinements.baseline.json (the parse rule is a refinement, which the spec build refuses unledgered); the platform-objects translation bundles and the catalog positive control (forced by the form row the gate required).
  • Spec contract prose: with the widened claim, this PR now updates the TSDoc of KnowledgeSearchOptions.granularity and groupBy (packages/spec/src/contracts/knowledge-service.ts) and the search_knowledge description: a source's documentBy sets the unit for record-level results. After the claim's second amendment, every other sentence in those two files that stated the record-level unit as "record" now names the document unit too: the topK TSDoc and the groupBy "instead of by record" line in the contract; in the tool, the topK, granularity and groupBy input descriptions, the matching SearchKnowledgeInput and SearchKnowledgeOutput.hits TSDoc, and the granularity refusal sentence. Left for Studio form, docs and skill text for knowledge source documentBy #38538, outside those two files: content/docs/ai/knowledge-rag.mdx (the granularity row) and content/docs/protocol/knowledge.mdx (the record-level paragraph).
  • Not judged: a source registered in code passes the parse (membership in metadataFields) but no save door, so the parent-link rule does not judge it; PR 2's os validate rule covers packaged sources.
  • For PR 2 (the os validate rule), left undecided here: @objectstack/lint does not depend on @objectstack/service-knowledge, and parentLinkRule / documentUnitOf are pure over the object definition (they read @objectstack/core's withheld-field collectors and the spec's referenceTargetOf). Two ways for PR 2 to call them: (A) add the @objectstack/lint to @objectstack/service-knowledge dependency and import the functions, which first need a line in that package's index.ts: today they are module exports only, not on its exports surface; (B) move the pure rule to a package lint already reads (for example @objectstack/core) and have knowledge-search-scope.ts import it from there. PR 2 chooses.
  • Live check: no pgvector or turso live suite touches record granularity or groupBy (grouping runs in the service over adapter answers), so no live cluster was started.
  • Overlap: overlap-check is clean against main and feat(service-knowledge): record sync consumes the database queue in batches of 100, and a large backlog is reconciled #38509 (shares knowledge-service.ts). It reports textual conflicts with two open drafts on hand-maintained counters: feat(spec)!: actions that act on many records are placed at selection; a list view's bulkActions is retired #38550 (the dropped-refinements ledger and the catalog positive control) and feat(objectql): a record in a closed state, and its lines, are closed to change (closedStates, ADR-0162) — trunk #38497 (the positive control). Whichever lands second re-applies its lines.

Read first

  1. packages/services/service-knowledge/src/knowledge-service.ts — groupKeyOf / documentKeyOf (the reader) and the new arm in admitAuthoredSource.
  2. packages/services/service-knowledge/src/knowledge-search-scope.ts — parentLinkRule replaces the body of parentLinksOf; check the scope still behaves the same.
  3. packages/spec/src/ai/knowledge-source.zod.ts — the key and its refinement.

Two-minute check: pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/document-by-38537.test.ts — 16 passed, including "…: 3 hits, each parent's best and the orphan".

Session: https://claude.ai/code/session_01FEkQ5oQLfL8thb6wtUHnTb

🤖 Generated with Claude Code

…unit by default; the save refuses a document unit that is no single-valued parent link

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oQLfL8thb6wtUHnTb
…usals and the unchanged hashes

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oQLfL8thb6wtUHnTb
…dles for the knowledge source's document unit row

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oQLfL8thb6wtUHnTb
…-ES, and count its label in the catalog's positive control

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oQLfL8thb6wtUHnTb
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation protocol:ai tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/platform-objects, @objectstack/service-knowledge, @objectstack/spec, touching 32 documentable anchor(s). ⚠️ 4 changed file(s) yielded no anchor (packages/spec/authorable-surface/ai.json, packages/spec/dropped-refinements.baseline.json, packages/spec/liveness/knowledge_source.json, …), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

4 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/ai/knowledge-rag.mdx (via KnowledgeSearchOptions (symbol, a top-level interface), KnowledgeService (symbol, a top-level class), knowledge_source (symbol, a field of const object arMetadataForms; a field of const object deMetadataForms; a field of const object enMetadataForms; a field of const object esESMetadataForms; a field of const object frMetadataForms; a field of const object jaJPMetadataForms; a field of const object koMetadataForms; a field of const object ptBRMetadataForms; a field of const object ruMetadataForms; a field of const object zhCNMetadataForms; a field of const object zhHantMetadataForms))
  • content/docs/getting-started/quick-reference.mdx (via knowledge_source (symbol, a field of const object arMetadataForms; a field of const object deMetadataForms; a field of const object enMetadataForms; a field of const object esESMetadataForms; a field of const object frMetadataForms; a field of const object jaJPMetadataForms; a field of const object koMetadataForms; a field of const object ptBRMetadataForms; a field of const object ruMetadataForms; a field of const object zhCNMetadataForms; a field of const object zhHantMetadataForms))
  • content/docs/permissions/system-context.mdx (via admitAuthoredSource (symbol, a method of class KnowledgeService), knowledge_source (symbol, a field of const object arMetadataForms; a field of const object deMetadataForms; a field of const object enMetadataForms; a field of const object esESMetadataForms; a field of const object frMetadataForms; a field of const object jaJPMetadataForms; a field of const object koMetadataForms; a field of const object ptBRMetadataForms; a field of const object ruMetadataForms; a field of const object zhCNMetadataForms; a field of const object zhHantMetadataForms))
  • content/docs/protocol/knowledge.mdx (via KnowledgeSearchOptions (symbol, a top-level interface), KnowledgeService (symbol, a top-level class), knowledge_source (symbol, a field of const object arMetadataForms; a field of const object deMetadataForms; a field of const object enMetadataForms; a field of const object esESMetadataForms; a field of const object frMetadataForms; a field of const object jaJPMetadataForms; a field of const object koMetadataForms; a field of const object ptBRMetadataForms; a field of const object ruMetadataForms; a field of const object zhCNMetadataForms; a field of const object zhHantMetadataForms))
What this run could not see
  • 4 changed file(s) yielded no anchor (packages/spec/authorable-surface/ai.json, packages/spec/dropped-refinements.baseline.json, packages/spec/liveness/knowledge_source.json, …) — pages documenting those are invisible to this run
  • 1 anchor(s) matched too much of the corpus to be a work list: VALIDATION_ERROR (literal, 40 pages)
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 253 client-bound route-ledger rows — the other 184 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 184: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 125 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 181 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json a133c8ad1b9066ec2141fa1f112f2063f45bd26a → packageMentionDocs.

Which tree this was computed on

This run read content/docs from b420270a95aed080cc8cdf672edbd938dde4950a — the merge of head 43de68d58f094661a1f28d332f5becd486fe02bc into base a133c8ad1b9066ec2141fa1f112f2063f45bd26a, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin b420270a95aed080cc8cdf672edbd938dde4950a && git checkout b420270a95aed080cc8cdf672edbd938dde4950a
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin a133c8ad1b9066ec2141fa1f112f2063f45bd26a 43de68d58f094661a1f28d332f5becd486fe02bc && git checkout -B drift-repro a133c8ad1b9066ec2141fa1f112f2063f45bd26a && git merge --no-ff 43de68d58f094661a1f28d332f5becd486fe02bc

node scripts/docs-audit/affected-docs.mjs --json a133c8ad1b9066ec2141fa1f112f2063f45bd26a

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs a133c8ad1b9066ec2141fa1f112f2063f45bd26a → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5oQLfL8thb6wtUHnTb

Contract-review-claim: session_01FEkQ5oQLfL8thb6wtUHnTb · head 5bbac4b · 2026-11-29T10:24Z

Face: schema (packages/spec/src/ai/knowledge-source.zod.ts, knowledge-source.metadata-form.ts: the new authorable key documentBy), so CONTRACT_REVIEW_TIER, run by an isolated model: fable sub-agent of the area, independent of the implementing dev; the area posts its record with tier evidence.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5oQLfL8thb6wtUHnTb

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 5bbac4b4573970a1d34ca2db1b036eefce1bc6e3
Local-runs: none
Scope: packages/spec/src/ai/knowledge-source.metadata-form.ts, packages/spec/src/ai/knowledge-source.zod.ts + packages/services/service-knowledge/src/knowledge-service.ts, packages/services/service-knowledge/src/knowledge-search-scope.ts, packages/services/service-knowledge/src/knowledge-source-admission.ts, packages/services/service-knowledge/src/knowledge-tools.ts

PR #38564, PR 1 of 2 of card #38537 (Part of; it carries no lint rule). Read: the card body and its three comments (claim 7253127987, dev report 7254182965, claim amendment 7254200774), the PR body, its 35-file list, the net diff against main at this head (merge base a5fe764), and the head's check-runs. The cited code was read in the tree at the head. The PR's author login is objectstack-fleet[bot]: written through the relay.

The rest of the diff is the lane seat's ACCEPT at TIER_DEFAULT: the three test files and the form test, the changeset, the generated spec artifacts (authorable-surface/ai.json, dropped-refinements.baseline.json, liveness/**, the reference page) and the platform-objects translation bundles with their positive-control count.

Check-runs on this head, latest run per name, read at 10:37Z: 33 green, 10 skipped, 27 still running, none red. Green: Build Core, Check Changeset, Spec property liveness, Governed Surface Queue Guard, PR-body guards, Lint · PM dispatch-gates, every other Lint row, Type Check · workspace, source gates, consumer gates and debt ledger, Live E2E UI, and three of the twelve Test Core shards. Still running: Test Core (9 shards), Test UI (16 shards), Type Check UI, Build & E2E UI. One earlier Check Changeset run on this head (141311778549) was red: it read the PR body before the added correction and refused Metadata-protocol: none beside a moved authorable-surface shard; its re-run on the edited body (141311921677) is green and is the one that stands. The running shards hold the acceptance pins and the form-coverage gate. This record judges the diff and does not stand in for them: landing waits for every check green on this head, and a red there reopens the round.

① Derived judgments

  1. ObjectKnowledgeSourceSchema accepts a new optional key, documentBy: string. Right, and a widening: the shape is a strictObject, so before this diff the key was refused as undeclared. ObjectKnowledgeSource (z.input) gains one optional member. The authorable-surface shard gains one row, ai/ObjectKnowledgeSource:documentBy, which is what added names.
  2. The refinement refuseDocumentByOutsideMetadataFields narrows nothing. It returns at once when documentBy is absent, so it fires only on inputs that carry the new key, every one of which was refused before. Under Zod 4 .superRefine keeps the object type (precedent: ask-question.zod.ts), so no export changes kind.
  3. The refinement cannot project to JSON Schema, and it is ledgered: two schemas (ai/KnowledgeSource at source, ai/ObjectKnowledgeSource at its root) and four embedding sites (manifest.knowledgeSources.element.source), header totals 281 → 283 schemas and 1239 → 1245 sites, which is 2 and 6. Right; Build Core is green on it.
  4. A stack's knowledgeSources collection and the installed-package responses accept the key through the same schema (the four embedding sites). Right, the same widening.
  5. Form: one row, source.documentBy, widget: 'field-ref', dependsOn: 'object', optional. Right. Precedent: ai-context.metadata-form.ts (field, same widget, same dependsOn). The picker's "None" writes an empty string and the form host's compositeWith drops a cleared sub-field's key, so a cleared picker omits documentBy and does not meet the membership rule.
  6. @objectstack/service-knowledge public surface: unchanged. parentLinkRule, documentUnitOf, their verdict types, documentUnitRefusalText and documentUnitValueOf are module exports. src/index.ts and src/testing.ts are not in the diff and re-export none of them, so nothing new is reachable through the package's exports map.
  7. Runtime answers that change, each only for a source that declares the key: a record-level search with no groupBy answers one hit per parent; the search_knowledge hit carries groupValue under granularity: "record"; a save is refused 400 VALIDATION_ERROR for a listed documentBy that is no single-valued parent link. No answer changes for a source without the key, an explicit groupBy, or chunk granularity (each pinned in document-by-38537.test.ts).
  8. parentLinksOf now calls parentLinkRule. Read arm by arm against the body it replaces: an undeclared field, a withheld field, a type outside lookup / master_detail and an unreadable target each skip the field as before; multiple is reported, and the scope still takes such a field. Scope behaviour is unchanged.
  9. @objectstack/platform-objects: the eleven metadata-form bundles gain the row's label and help, and the extractor-filled locales gain its two source hashes. Additive.
  10. Index: unchanged. The knowledge-service.ts hunks are one import, groupKeyOf, the admitAuthoredSource arm with its jsdoc, and documentKeyOf. recordToDocument, split/, the adapters and knowledge-index-fingerprint.ts are not in the diff, and computeIndexFingerprint and computeRecipeHash enumerate their inputs and read no documentBy. Topic Topic: an app declares the document unit of a knowledge source (documentBy) — counted and grouped by parent record, index unchanged #38536's "index unchanged" holds: nothing here changes what is indexed or how a passage is cut.
  11. Not moved by this diff and now incomplete: the TSDoc of KnowledgeSearchOptions.granularity and topK in packages/spec/src/contracts/knowledge-service.ts. See ③.

② Semver level

Changeset .changeset/38537-knowledge-document-by.md: minor on @objectstack/spec, @objectstack/service-knowledge and @objectstack/platform-objects. Its body and the PR body carry the same two lines, Clause-②: yes (widening) and Metadata-protocol: added. Check Changeset is green on the edited body, level axis included.

Kind: added is right. A new authorable key; no meaning or default of an existing key changes and no value accepted before is refused now, so neither semantic nor narrowed. (widening) is right by ① 1 and 2.

Level, package by package (AGENTS.md, Post-Task step 3: a kind takes at least minor on a package the diff moves):

  • @objectstack/spec: minor is right. It carries the key, and it is the package the level axis needs at minor.
  • @objectstack/service-knowledge: minor is right. The diff moves its published source, and it is the key's reader: the floor an app that writes documentBy must be able to name includes the runtime that groups by it. An older service refuses the key at load (the closed shape), which is the case a minor floor exists for.
  • @objectstack/platform-objects: minor is right by the rule's letter, since the diff moves its published bundles. On substance it ships one label and one help text. All three packages sit in the one fixed group of .changeset/config.json, so the group publishes at its highest level whatever this entry says, and the choice changes no published version.

No major. The body states the change to granularity: 'record' for a declaring source, as the card asked. One wording point on the changeset, a prose face: N1.

③ Boundary flags

  • Open question 1 (dev report), Metadata-protocol none or added: answered by claim amendment 7254200774, added and minor. The head carries it in both places. Right (②).
  • Open question 2, where PR 2's lint reads the rule from (A: lint depends on service-knowledge; B: the pure rule moves to a package lint already reads): left undecided by the seat's split ruling, and not judged here. What this diff commits toward either: nothing. packages/lint/** is untouched and no dependency edge is added. The functions are module exports only (① 6), so B leaves no public export behind and A still needs its own index.ts line. The save refusal names no os validate rule id, unlike the "does not exist" arm beside it. parentLinkRule's jsdoc says only that a lint can ask it. One correction to the PR body for whoever writes PR 2: under A the functions are not importable "as they are", because they are not on the package's exports surface today.
  • Dev flag, out of scope 1: the granularity and topK TSDoc in packages/spec/src/contracts/knowledge-service.ts, and the search_knowledge description in knowledge-tools.ts ("one hit per record ... topK counts records", with groupValue described under groupBy only), state the old rule. For a source that declares documentBy they are wrong from this merge on. The claim (7253127987) excludes the search_knowledge description, docs and skills/** to Studio form, docs and skill text for knowledge source documentBy #38538, so the deferral is declared and carried. Escalated to the seat on two points this review cannot read from its inputs: (a) that Studio form, docs and skill text for knowledge source documentBy #38538's scope names the contracts TSDoc, which the claim's exclusion list does not; that file is a schema-face path, so its PR owes its own review at this tier; (b) that Studio form, docs and skill text for knowledge source documentBy #38538 lands before a release is cut, so no published version carries the reader without its description.
  • Dev flag, out of scope 2: a source registered in code or installed with a package passes the parse and meets no save door (admitAuthoredSource admits isSystem; registerSource asks no admission), so the parent-link rule does not judge it until PR 2. Accurate. The consequence, read in the code: such a source naming a text or user field groups by that field's value; a multiple lookup, a withheld field or an object value groups nothing, because documentUnitValueOf answers undefined and each record is its own hit. No record is dropped and nothing a caller may not read is served. Carried by PR 2. It is also what gives S1 its weight.
  • Files beyond the claim's list: each is named by claim amendment 7254200774 and matches the file list. The claim provided for the form row folding in Studio form, docs and skill text for knowledge source documentBy #38538's form half.
  • SQL push-down (Prime Directive 5): no new id materialisation and no in-app join. Grouping runs over the hits the adapters already answered, at most topK × SEARCH_REFILL_FACTOR per source, the bound that stood before. The parent is read from the hit's stored metadata; no parent row and no extra record is read. The save arm reads the registered definition, not rows. The PR body gives this reason and the code agrees. No finding.
  • Seat condition, index or chunking: unchanged (① 10).
  • Seat condition, PR 2: no pre-commitment to A or B (open question 2 above). S1's sentence states PR 2's outcome as a present fact, without choosing between them.

④ Design judgment

No must-fix.

S1 (should-fix) — the schema's jsdoc says os validate refuses a documentBy that is no parent link; nothing at this head does.

In packages/spec/src/ai/knowledge-source.zod.ts, the documentBy docblock: "Saving and os validate also refuse a field that is not a single-valued parent link". Saving does (admitAuthoredSource). os validate does not: packages/lint/src/validate-knowledge-source.ts at this head lists five verdicts and reads no documentBy, and no file under packages/lint, packages/cli, packages/metadata-core, packages/runtime or packages/rest names the key. The rule is PR 2, held behind #35143's release, with no date. Until then the sentence is untrue for exactly the sources os validate exists for, the packaged and code-registered ones that meet no save door: an author runs os validate, gets green on documentBy: 'title', and the source groups by title (③, out of scope 2). The changeset and the form help say only what this head does; the schema's own contract text should too.

Fix: state the save refusal alone at this head, and if wanted that a packaged or code-registered source is not judged yet. PR 2 adds os validate to the sentence in the commit that adds the rule. One file moves, and the delta review is of that hunk.

Nits:

  • N1 (nit) — same docblock, "the hit carries that parent as its groupValue". True of the search_knowledge hit (SearchKnowledgeHit). KnowledgeHit, what IKnowledgeService.search answers, has no groupValue: the spec declares none, and there the parent is metadata[documentBy]. The changeset says the same of search. May ride S1's commit; the changeset is a prose face.
  • N2 (nit) — form help, "The index is unchanged and nothing is rebuilt", in the sentence after "also listed in Filter fields". True of the key. Listing a field in Filter fields for the first time changes the recipe hash (computeRecipeHash reads metadataFields) and starts one complete rebuild. An author who follows the help on a source that did not list the parent yet gets the rebuild the help says does not happen. Suggested: "Setting it rebuilds nothing; adding the field to Filter fields does." A change regenerates the eleven bundles, so it is a follow-up on Studio form, docs and skill text for knowledge source documentBy #38538 unless it rides S1's commit.
  • N3 (nit) — hitOf in knowledge-tools.ts. The groupBy arm serves metadata[groupBy] only when the source lists the field, and declaredMetadataOf filters to the listed fields. The new arm serves metadata[documentBy] with no such condition and rests on the parse. That is safe for KnowledgeService, whose two doors both parse with KnowledgeSourceSchema, so a registered source always lists the field. The tool binds to any IKnowledgeService, though, and the file's own rule ("of its stored metadata only the fields its source lists") would hold by construction with one metadataFields.includes condition. May ride S1's commit.

File by file:

On knowledge-source.zod.ts (hits). Against the card: the key, the membership rule and a message naming the fix are all present; the message names the field, the list (or "the list is empty") and three ways out. Against its first consumer, sentence by sentence:

  • "The index is unchanged ... neither the index fingerprint nor the recipe hash": holds (① 10).
  • "grouped by the parent the field holds, one hit per parent (its best passage)": holds. groupKeyOf asks documentKeyOf, and answerByRecord takes each group's best member that is not stale.
  • "A record with no parent is its own hit": holds. An absent, null, empty or non-scalar value falls to recordKeyOf; pinned for null, empty and absent.
  • "Two sources never share a group": holds. The key carries hit.sourceId; pinned.
  • "An explicit groupBy is answered as before": holds. That branch is untouched, and the pin compares the answers with and without the key.
  • The two sentences that do not hold as written are S1 and N1.

The .describe text is accurate. An empty string sent through the API is refused by the membership rule, whose message then suggests adding '' to the list; it still ends on "or remove documentBy", and the form never sends one (① 5). No effect.

On knowledge-source.metadata-form.ts (hits). The row matches the schema (one field, optional, scoped by source.object), and the form test pins the widget, dependsOn and optionality. The help is accurate except N2. The file's header list of pickers does not mention the new row; no effect.

On knowledge-service.ts. Tried to break the reader:

  • Permission. applyPermissionFilter runs on the raw hits before any grouping, so a parent whose best clause the caller may not read is answered by its best readable clause, not dropped. The removed count stays in the debug log.
  • Freshness. stale is keyed by source and record, and a group's lead is its first member that is not stale, so a group of several records falls back across records. computeDocHash covers metadata, so a clause moved to another policy since it was indexed reads stale when it leads and is repaired; it is not served under its old parent.
  • An index built before the field was listed. Adding a field to metadataFields changes the recipe hash, so that index is refused until rebuilt, never answered ungrouped.
  • Keys. parent: + source + # + value cannot meet a record: or document: key. String and number ids compare as strings, as a scope term compares them.
  • The cap. With many clauses per parent, the first round more often names fewer than topK parents and takes the one refill; past topK × SEARCH_REFILL_FACTOR passages per source the answer is short, logged at debug. This is the bound an explicit groupBy on the parent has today. Said here so the first large adopter is not surprised by it.

The save arm agrees with its jsdoc: after the "does not exist" arm and before admitObject; 400 VALIDATION_ERROR with field; 503 when the definition cannot be read; no judgment for a disabled package's object or a definition with no field map; isSystem admitted. It answers ahead of the permission arms and names a field's type, its multiple flag or its withheld class to the saver. Read at the REST door (meta-item-write-routes.ts): manage_metadata is asked first, and the MCP and runtime doors place the admission after their capability and walled checks as well. So the sentence tells the saver nothing the metadata plane withholds from them, as documentUnitRefusalText's jsdoc says.

On knowledge-search-scope.ts. parentLinkRule and documentUnitOf agree with their jsdoc and with the card's rule: lookup / master_detail only, never withheld, never multiple. Refactor equivalence: ① 8.

On knowledge-source-admission.ts. documentUnitRefusalText covers the five reasons, each naming the field, why, and the fix. undeclared is reachable only for an injected system column, since a name declared nowhere is caught by the arm before, and the sentence says so.

On knowledge-tools.ts. hitOf and documentUnitValueOf agree with the service: the tool and documentKeyOf read one predicate, and the tool's condition (granularity === 'record', no groupBy) is the service's. groupValue is absent for a record with no parent and under chunk granularity; pinned. N3 above. The tool description and the granularity input description in this file still read "one hit per record": the claim's declared exclusion, carried by #38538 (③), not graded here.

Round: S1 earns a delta review of its fix, by this reviewer. N1 to N3 are accepted as they stand unless they ride that commit.

Implemented-by: claude/issue-38537-knowledge-document-by
Reviewed-by: session_01FEkQ5oQLfL8thb6wtUHnTb

VERDICT: PASS

…ad does

The documentBy docblock names the save refusal alone (a packaged or
code-registered source is not judged yet) and where each surface carries
the parent: metadata[documentBy] on IKnowledgeService.search, groupValue
on the search_knowledge hit. The form help and changeset say that listing
the parent in Filter fields for the first time does rebuild. hitOf serves
the parent only for a source that lists documentBy in metadataFields, as
its groupBy arm does, with a pin over a stub service. The granularity and
groupBy contract TSDoc and the search_knowledge description name the
document unit.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oQLfL8thb6wtUHnTb
… unit

The topK TSDoc in the knowledge-service contract, and in search_knowledge
the topK, granularity and groupBy input descriptions, the matching input
and output TSDoc and the granularity refusal, say that for a source that
declares documentBy (its document unit) a record-level result counts one
hit per parent record instead.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oQLfL8thb6wtUHnTb
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5oQLfL8thb6wtUHnTb

Contract-review-claim: session_01FEkQ5oQLfL8thb6wtUHnTb · head 43de68d · 2026-11-29T11:18Z

Delta round 1 of record 7254573293 (S1 should-fix open; N1–N3), plus the contract TSDoc widened by claim amendments on #38537. Face: schema, so CONTRACT_REVIEW_TIER, a fresh isolated model: fable sub-agent; the area posts its record with tier evidence.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5oQLfL8thb6wtUHnTb

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 43de68d58f094661a1f28d332f5becd486fe02bc
Local-runs: none
Scope: packages/spec/src/ai/knowledge-source.metadata-form.ts, packages/spec/src/ai/knowledge-source.zod.ts, packages/spec/src/contracts/knowledge-service.ts + packages/services/service-knowledge/src/knowledge-tools.ts, packages/services/service-knowledge/src/knowledge-service.ts, packages/services/service-knowledge/src/knowledge-search-scope.ts, packages/services/service-knowledge/src/knowledge-source-admission.ts

Delta round 1 on PR #38564 (PR 1 of 2 of card #38537), from head 5bbac4b4573970a1d34ca2db1b036eefce1bc6e3 (record 7254573293: PASS, should-fix S1, nits N1 to N3) to this head. Read: the card body and its five comments (claim 7253127987, dev report 7254182965, claim amendments 7254200774, 7254588475 and 7254921447), the PR body and its comments, the 36-file list, the delta 5bbac4b457..43de68d58f, the net diff against main at this head, and the head's check-runs. The cited code was read in the tree at the head.

The delta is three commits and no merge: 12cd7dc8a6, e0ebb9ad8e, 43de68d58f. The merge base with main is still a5fe76457e, so every hunk in it is this PR's own. It moves ten files: the schema docblock, the form help, the contract TSDoc, knowledge-tools.ts, one test, the changeset body and four translation bundles.

The file list gained packages/spec/src/contracts/knowledge-service.ts, and reviewFace returns it as a third hits path on this file list (the template printed over the 36 paths names three). The Scope line carries it with the other two, and ④ judges it as a hits file.

The rest of the diff is the lane seat's ACCEPT at TIER_DEFAULT: the test files, the changeset, the generated spec artifacts and the platform-objects bundles with their positive-control count.

Check-runs on this head, latest run per name, read at 11:25Z: 23 green, 10 skipped, 36 still running, none red. Green: Check Changeset (both runs), Spec property liveness, Governed Surface Queue Guard, PR-body guards (one earlier run cancelled, its re-run green), Lint · PM dispatch-gates and every other Lint row under Lint & Repo Gates, Type Check · source gates, Build Docs, Build UI Deps. Still running: Build Core, Type Check · workspace, consumer gates and debt ledger, the twelve Test Core shards, the UI lint, type-check, test and E2E jobs. The running shards hold the acceptance pins, the new stub-service pin and the type-check of the hitOf condition. This record judges the diff and does not stand in for them: landing waits for every check green on this head, and a red there reopens the round.

① Derived judgments

  1. Accept-set: the delta changes none. The schema shape, the refinement, the form row's widget and dependsOn, authorable-surface/ai.json and dropped-refinements.baseline.json are the round-1 blobs. Round-1 ① 1 to 10 stand at this head as written.
  2. KnowledgeSearchOptions (@objectstack/spec/contracts): the TSDoc of topK, granularity and groupBy gains the document unit. No member, type or default moves. Right: text only.
  3. search_knowledge definition: the description, the topK, granularity and groupBy input descriptions and the granularity refusal sentence change. The JSON Schema of the arguments is the same (types, enum, bounds, additionalProperties). Every door lists this one definition, so an MCP client reads the new text; nothing it may send or receive changes. No test pins the old text (mcp-knowledge-tools.test.ts compares the listed description with the definition).
  4. hitOf gains one condition: under the default grouping, groupValue is served only for a source that lists its documentBy in metadataFields. For KnowledgeService no answer changes, since both of its doors parse a source and the parse holds the membership. For another IKnowledgeService whose source skipped the parse, an unlisted field's value is no longer served. Right, and no narrowing of anything published: the arm first ships in this PR.
  5. Form: the help string of source.documentBy changes; the row is the same. The en bundle and the three authored locales (zh-CN, ja-JP, es-ES) carry the new sentence.
  6. Index: unchanged. The delta touches no indexing, splitting, adapter or fingerprint file, and knowledge-service.ts and knowledge-index-fingerprint.ts are the round-1 blobs. Topic Topic: an app declares the document unit of a knowledge source (documentBy) — counted and grouped by parent record, index unchanged #38536's "index unchanged" holds at this head.
  7. @objectstack/service-knowledge package surface: src/index.ts is still not in the diff. Nothing new is reachable through the package's exports map.

② Semver level

Changeset .changeset/38537-knowledge-document-by.md: minor on @objectstack/spec, @objectstack/service-knowledge and @objectstack/platform-objects, front matter unchanged by the delta. Its body and the PR body carry Clause-②: yes (widening) and Metadata-protocol: added. Check Changeset is green on this head.

Kind: added is right. One new authorable key; no meaning or default of an existing key changes and no value accepted before is refused now. (widening) is right: the shape is a strictObject that refused the key before.

Level, package by package:

  • @objectstack/spec: minor is right. It carries the key, and now the contract text that describes its reader.
  • @objectstack/service-knowledge: minor is right. It is the key's reader and its save refusal, and an app that writes documentBy needs a floor that names the runtime that groups by it.
  • @objectstack/platform-objects: minor is right by the rule's letter (AGENTS.md, Post-Task step 3: a kind takes at least minor on a package the diff moves). It ships a label and a help text. The three packages are in one fixed group, so this entry changes no published version.

No major. What the delta adds publishes nothing above this: TSDoc, description text, one tighter condition on an arm that is new in this PR, and help strings. The changeset body's two edits are judged under N1 and N2 below.

③ Boundary flags

  • Open question 1 (dev report), Metadata-protocol none or added: answered by claim amendment 7254200774. The head carries added and minor in both places.
  • Open question 2, where PR 2's lint reads the rule from: left undecided by the seat's split ruling, and not judged. What the delta commits toward A or B: nothing. No path under packages/lint, no package.json, no index.ts is in the diff. The schema docblock's new sentence says the rule "does not judge it yet" for a packaged or code-registered source and names no route. The PR body's option A now says the functions first need an index.ts line, which is the round-1 correction.
  • Round-1 escalation (the contract TSDoc and the search_knowledge description would ship stale): answered by claim amendments 7254588475 and 7254921447. Both texts are in this PR and are judged in ④. The two docs pages (knowledge-rag.mdx, protocol/knowledge.mdx) are not in this PR and are not graded here, per the brief.
  • Dev flag, a source registered in code or installed with a package meets no save: still accurate (admitAuthoredSource admits isSystem on its first line; registerSource parses and asks no admission) and still carried by PR 2. The schema docblock now says so itself.
  • Files beyond the claim's first list: the contract file and the tool's descriptions are named by the two later amendments and match the file list.
  • SQL push-down (Prime Directive 5): the delta adds no read, no id materialisation and no join. The one new condition is a membership test on the source definition already in hand. Round 1's reading of the reader stands on the same blob.
  • Seat condition, split: this PR carries no lint rule, and nothing in it pre-commits PR 2 (open question 2 above).
  • Seat condition, index or chunking: unchanged (① 6).
  • Seat condition, minor on the three packages: right for each (②).
  • For the seat: the brief's hits list names two paths. At this head the contract file is a third, so the tier evidence should be read over three.

④ Design judgment

No must-fix, no should-fix.

  • S1: closed. The documentBy docblock now reads "Saving a source also refuses a field that is not a single-valued parent link", and adds that a source registered in code or installed with a package meets no save, so the rule does not judge it yet. Both sentences agree with the head: the save arm in admitAuthoredSource is the only judge, and no file under packages/lint names the key. No sentence in the diff claims an os validate rule for documentBy any more (searched in the three hits files, the four implementing files and the changeset).
  • N1: closed. The docblock and the changeset say where each surface carries the parent: metadata[documentBy] on IKnowledgeService.search, and also groupValue on a search_knowledge hit. Read in the code: the service answers the adapter's hit with its stored metadata whole, and KnowledgeHit declares no groupValue.
  • N2: closed. The form help ends "Setting it rebuilds nothing; adding the field to Filter fields does", and the changeset says the same. True both ways: computeRecipeHash reads metadataFields and no documentBy.
  • N3: closed. hitOf serves the default-grouping groupValue only when the source lists the field, the same condition its groupBy arm holds. Its jsdoc says so, and one stub-service test pins it with a positive control.

New, both nits:

  • N4 (nit) — contracts/knowledge-service.ts, topK: "For a source that declares documentBy (its document unit), it counts parent records instead." The sentence carries neither condition the code holds. Parents are counted only under record granularity with no groupBy (groupKeyOf asks documentKeyOf only when groupBy is undefined; with one, a declaring source counts groupBy groups like any other), and a record with no parent counts as one. Both conditions are stated beside it, in the granularity bullet and in the last sentence of groupBy, so the three docblocks agree when read together and no caller is told a wrong count. Left as it stands. A wording for the next commit that touches the file: "it counts parent records in their place (a record with no parent counts as one), unless the search names a groupBy".
  • N5 (nit) — knowledge-service.ts, the search jsdoc section "Records, not chunks" and the debug line under it still describe the record-level answer as "the best passage of the record — or of the groupBy value" and count "records". For a declaring source the group is the parent. groupKeyOf and documentKeyOf beside them say it right, and no caller reads either text. Left as it stands.

File by file.

On knowledge-source.zod.ts (hits). The delta moves the docblock only. Every sentence was read against the head again: the index sentence, "one hit per parent (its best passage)", "a record with no parent is its own hit", "two sources never share a group" and "an explicit groupBy is answered as before" hold as in round 1; the two that did not are S1 and N1, now right. "Must be one of metadataFields" is the refinement.

On knowledge-source.metadata-form.ts (hits). One help sentence, N2. The row and its test are unchanged.

On contracts/knowledge-service.ts (hits), sentence by sentence against searchByKey, groupKeyOf, documentKeyOf and answerByRecord, for a source with and without documentBy:

  • granularity, "'record': one hit per record ... so topK counts records": the path of a source without the key, unchanged (documentKeyOf answers recordKeyOf when the source declares none; pinned).
  • "For a source that declares documentBy, one hit per parent record instead": holds. The group key is parent: plus the source plus the value.
  • "the best passage among that parent's records": holds. answerByRecord takes each group's first member, best first, that is not stale. It is the best the caller may read, since the permission re-check runs before grouping.
  • "the parent read from the hit's metadata[documentBy]": holds, for the key and for what the caller receives.
  • "so topK counts parent records": holds. distinctGroups and the final cut count group keys.
  • "a record with no parent is its own hit": holds for an absent, null, empty or non-scalar value.
  • "two sources never share a parent": holds. The key carries hit.sourceId.
  • "Each hit returned is checked against the record as it reads now": still true of the hit returned. For a parent's group, a stale lead falls back to the parent's next record.
  • groupBy, "instead of by record (or by parent record, for a source that declares documentBy)" and "An explicit groupBy takes the place of a source's documentBy for this search": hold. With a groupBy, groupKeyOf never reads documentBy, and hitOf serves the groupBy value.
  • topK: holds for the case it names; N4.

Tried to break it with a search over two sources, one declaring and one not: topK is one cap over group keys, parents for the first and records for the second, which is what the per-source wording says. With an explicit groupBy equal to the documentBy field: the key is value: with no source, so two sources do share a group there, as the groupBy text says ("whichever source they come from") and the card asked.

On knowledge-tools.ts. The description, the three input descriptions, the SearchKnowledgeInput and SearchKnowledgeOutput.hits TSDoc and the refusal sentence each say "one hit per parent record instead" under record for a declaring source, and each is true of searchByKey. The description's "which the hit carries as groupValue (a record with no parent is its own hit)" is hitOf: groupValue is set under granularity: "record" with no groupBy for a listing source, and absent when documentUnitValueOf answers nothing. The executor and the service read one predicate for the value. For a source without the key every sentence reads as before and groupValue is absent. An agent cannot see which sources declare a unit (sources lists id, label and description); it reads the unit off the hit, where a groupValue means the hit stands for a parent. That is enough for the description as written.

On knowledge-service.ts, knowledge-search-scope.ts and knowledge-source-admission.ts. Not moved by the delta: each is the blob round 1 read, and its findings there stand. N5 is the one addition.

Generated output and the PR body, for the lane seat, not graded: the seven extractor-filled bundles (ar, de, fr, ko, pt-BR, ru, zh-Hant) still hold the previous English help with its recorded source hash. That is the extractor's merge rule, and setup.translation.ts reads the generated hashes and serves the current source for a leaf whose hash no longer matches, so those locales show the new English sentence. The PR body's "Two-minute check" line still says 16 passed, where its own Tests section reads 17 of 17 after the delta; a body edit moves no head.

Round: S1 is closed on this head and nothing new earns a delta review. N4 and N5 are accepted as they stand.

Implemented-by: claude/issue-38537-knowledge-document-by
Reviewed-by: session_01FEkQ5oQLfL8thb6wtUHnTb

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5nNJM8FQkBco82NDFb

席位核对 — L1 ACCEPT · head 43de68d · 2026-11-29T11:33Z

I read the diff at 43de68d (36 files, +784/−41) against the L1 checklist, card #38537 and its claim 7253127987 with three amendments. The contract face is the contract review's: round 1 7254573293 PASS, delta 7255137073 PASS. At reading, the checks on this head were 31 success, 11 skipped, 30 pending and 0 failed. One cancelled "PR-body guards" run at 11:17:38Z was superseded by a green run at 11:17:55Z. This verdict is on the diff, so landing waits for green.

Part of #38537 is right. The card's Scope wires the rule into packages/lint/src/validate-knowledge-source.ts as well. That os validate rule is PR 2, which closes the card; the lint package is held elsewhere until #35143 releases. The body names this, and lays out PR 2's A/B choice for how lint reaches parentLinkRule / documentUnitOf. The card stays open as the carrier, which is the normal shape for PR 1 of 2.

Every acceptance line of the card is pinned:

  • The parse refuses a documentBy that metadataFields does not list, including when metadataFields is omitted.
  • Save refuses a text field, a user field, an internal lookup and a multiple lookup, each with 400 VALIDATION_ERROR, naming the field and the fix. lookup and master_detail positive controls are admitted.
  • 6 records under 2 parents plus 1 with no parent give 3 hits.
  • An explicit groupBy, a source without documentBy, and chunk granularity are unchanged.
  • The fingerprint and recipe hash are the same with and without the key, and index-fingerprint.test.ts is untouched.

What I checked in the code:

  • parentLinkRule is a faithful factoring of the old parentLinksOf body. The same four exits (undeclared, withheld, not a link, no target) still mean "no link" for the scope, and parentLinksOf now just maps over it, so scope behaviour is unchanged. documentUnitOf adds only "not multiple".
  • documentKeyOf keys the group as parent:<sourceId>#<String(value)>, so two sources never merge on equal parent ids. An absent, null, empty, non-string or non-finite value falls back to recordKeyOf, so no record is dropped. The tool's groupValue reads through the same predicate, documentUnitValueOf.
  • The save arm runs after the "does not exist" arm and before every permission arm. It is judged from the definition alone, and its wording tells a manage_metadata holder nothing the metadata plane does not already serve. I found no security-class issue.
  • The changeset is minor on spec, service-knowledge and platform-objects (one fixed group), with Metadata-protocol: added and Clause-②: yes (widening), for a new authorable key. The dropped-refinements ledger, authorable surface, liveness row and the form row with its translated bundles are all regenerated. The form row was forced by the form-coverage gate, and the body says this folds in the form half of Studio form, docs and skill text for knowledge source documentBy #38538.

Measured by me: spec knowledge-source.test.ts passes 37/37 in a worktree at this head. The service-knowledge suites need built workspace dists that this container lacks, so I rely on CI and on the body's three ablations: reader reverted (4 red), refinement dropped (2 red), tool guard removed (1 red).

The two notes the reviewer passed on:

  • The seven extractor-filled bundles keep the previous English help under its old source hash. setup.translation.ts compares hashes when serving, so those locales show the current English until a translator fills them. That is the designed stale-fill fallback, not a wrong string. The body says check:i18n-stale-fill found no new stale fill.
  • Body nit: the "Two-minute check" says "16 passed", while Tests says 17/17 (the delta added the stub-service case). If the body is edited again, change the 16 to 17.

Out of scope here: the "one hit per record" sentences in knowledge-rag.mdx:206 and protocol/knowledge.mdx:355 belong to #38538, and the body names them as left there.

ACCEPT once the pending checks finish green. Not governed, so the area lands it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5oQLfL8thb6wtUHnTb

Landing: head 43de68d · L1-a ACCEPT 7255197091 · CONTRACT_REVIEW_TIER review 7254573293 (PASS, S1 should-fix) and delta 7255137073 (PASS; S1, N1–N3 closed; N4, N5 nits stand) · Part of #38537 (PR 1 of 2; PR 2, the lint rule, after #35143 releases; the card stays open as its carrier) · Clause-②: yes (widening), Metadata-protocol: added, minor on spec, service-knowledge and platform-objects (one fixed group) · CI on this head: every check run success or expected skip, none failed · check-governed-merges --pr 38564: NOT governed. Topic #38536's "index unchanged" holds (no indexing or chunking file touched, per both review rounds). Docs pages that still say "one hit per record" are #38538's, with seat 1.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 29, 2026 11:48
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit 62eecbc Nov 29, 2026
76 of 77 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-38537-knowledge-document-by branch November 29, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation protocol:ai size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants