Skip to content

feat(service-knowledge): a search_knowledge hit carries its source's declared metadataFields values - #38353

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/area-o1C-38291
Nov 28, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/area-o1C-38291

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #38291
Clause-②: yes (widening) — each search_knowledge hit gains the values of its source's declared metadataFields
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:AI 用知识检索查到条款这类子记录时,每条结果直接带上所属的政策等字段,不必再额外查一次记录。
  • 为什么做:替 BrightRule 这类按条款建索引的应用省掉每问一次的额外查询,把单轮用量压低。
  • 出错会怎样:只回传数据源当前声明、且调用者有权查询的字段;万一有问题,撤回此改动即恢复原来的结果形状。
  • 要你做什么:无

What changes

packages/services/service-knowledge/src/knowledge-tools.ts

  • SearchKnowledgeHit gains an optional metadata member (an object from field name to value): for a hit of an indexed record, the values of the fields its source lists in metadataFields now, read from the metadata the index already stores with the passage, keyed by field name in the order the source lists them (declaredMetadataOf).
    • A stored key for a field the source no longer lists is not answered.
    • A listed field whose stored value is absent or null is left out; no listed value ⇒ no metadata member (a file or web source's hit carries none).
    • Own keys only (hasOwnProperty), so a listed name that is also an Object.prototype member never answers the prototype's value; the object is built with Object.fromEntries.
  • No new argument, no live record read. groupValue under groupBy is unchanged (same code path, untouched).
  • The tool description now tells the model that a hit of an indexed record carries metadata and that the parent or status it names needs no record read.
  • content/docs/ai/knowledge-rag.mdx: the "Each hit carries" paragraph names the new member. This file is one beyond the claim's declared surface (the hit-shape paragraph would otherwise go incomplete); skills/** is untouched.

Why it is safe (verified on main 600197a): KnowledgeService.admitSources runs admitSourceFields for every non-system caller before a source is searched; servedFieldsOf adds every metadataFields member to the served set, and one served field that is not QUERYABLE by the caller refuses the whole source (knowledge-source-admission.ts, ADR-0161 K8). So no value this member answers is one the caller could not query. The existing service-level pin is knowledge-source-admission.test.ts › "title and metadataFields are served fields too: either one hidden refuses the source"; this PR adds the same pin through the tool.

Tests

src/__tests__/knowledge-tools.test.ts, new describe "a hit carries the values of the fields its source lists in metadataFields":

  • every hit carries exactly the listed fields' values, in listed order;
  • after the declaration drops status, a corpus indexed under ['policy', 'status'] answers policy only (and declared: [] answers no member);
  • null and absent values are left out, an unlisted stored key (secret) never reaches the answer, a listed constructor with no own stored value answers nothing;
  • field gate through the tool: a caller who may not query status gets no hit and the source is never searched; a caller who may gets the values.

Updated: the whitelist pin now expects metadata beside groupValue; the groupBy pin no longer asserts that status is absent (that was the behaviour this card changes); the description pin names `metadata`.

Readings (head 1c8472c)
  • pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 — Test Files 19 passed (19), Tests 686 passed (686); typecheck (tsc + check:test-typecheck over tsconfig.test.json) exit 0. Lock verdict command-exit 0.
  • Ablation (scripts/ablation-replace.mjs, on src: the tests import ../knowledge-tools.js, no dist hop): anchor for (const field of new Set(listed)) { → for (const field of Object.keys(stored)) {, landed (anchor 1 → 0, blob b07dfa562bce → cd682e3614cf). knowledge-tools.test.ts: 2 failed | 57 passed — "a field the source no longer lists is not answered…" and "a listed field whose stored value is null or absent…". Restored: blob == HEAD, git diff HEAD empty.

Acceptance notes

  • A field that became internal or credential-class after the index was built is no longer in the gate's served set, while a stale stored passage may still carry its value until the rebuild that recipe change triggers. The same holds today for groupValue, the scope metadata terms and the snippet text itself. This PR adds no new exposure class. Recorded as a boundary, not filed.

Verification

Local gate subset (dispatch-gates --commands, head 1c8472c)
  • 99 derived families: 98 exit 0. check:dual-build-cjs-loads exit 3 (PREREQUISITE NOT MET: reads every package's dist, needs a full build) is NOT MEASURED locally, so CI owns it. check:skill-examples first exit 3 (client-react dist missing); after building @objectstack/client-react... it exits 0.
  • dispatch-gates --ran: "99 derived famil(ies) accounted for — 98 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)".
  • Head 5282883 changes only the changeset's Clause-② line (copied verbatim from the claim); the changeset families were re-run there: check-adr-0087-registration, check-changeset-no-major, check-empty-changeset and check:nul-bytes, each exit 0.
  • Not merged with origin/main: the 9 commits since the branch point touch no file under packages/services/service-knowledge (only packages/spec/src/ai/dataset-tools.zod.ts nearby).

Read first (by risk): knowledge-tools.ts declaredMetadataOf and its call in hitOf; the field-gate test in knowledge-tools.test.ts.

Two-minute check: pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/knowledge-tools.test.ts. Expect 59 passed, including the four tests under "a hit carries the values of the fields its source lists in metadataFields".


Generated by Claude Code

…declared metadataFields values

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…e declared metadata values

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

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

4 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • 1 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 — 4 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 f38a3ca8469368dcdcca177f4b8a94ba9ac5bf1d → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 7ac23e1fe2210e608c9908502dda6ac38fc220b0 — the merge of head 5282883f38580bad2195589f1628b29e38bc7ebc into base f38a3ca8469368dcdcca177f4b8a94ba9ac5bf1d, 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 7ac23e1fe2210e608c9908502dda6ac38fc220b0 && git checkout 7ac23e1fe2210e608c9908502dda6ac38fc220b0
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin f38a3ca8469368dcdcca177f4b8a94ba9ac5bf1d 5282883f38580bad2195589f1628b29e38bc7ebc && git checkout -B drift-repro f38a3ca8469368dcdcca177f4b8a94ba9ac5bf1d && git merge --no-ff 5282883f38580bad2195589f1628b29e38bc7ebc

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

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

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 5282883f38580bad2195589f1628b29e38bc7ebc
Local-runs: none

The review is owed by the declaration alone (Clause-②: yes (widening)). No path of the diff is a published-schema, governed or narrowing face, so this is the lane's own record at TIER_DEFAULT. It reads the net diff of the head against merge base 600197a6ae, the card and the head's check-runs.

① Derived judgments

  • The widening is declared, and true. SearchKnowledgeHit gains one optional member, metadata?: Record, and the search_knowledge description gains one sentence saying so. No argument, schema, status or refusal changes, and groupValue is unchanged.
  • declaredMetadataOf answers exactly the declared fields.
    • It walks the source's metadataFields as it lists them now, de-duplicated, in order.
    • It reads own keys of the stored metadata only, so a listed name that is also an Object.prototype member never answers the prototype's value.
    • It drops undefined and null, and answers no member when nothing is left.
    • A stored key the source no longer lists is never answered, and neither is a key no listed field names.
    • A file or web source has no objSource, so its hit carries none.
  • No value the caller may not query is served. The field gate is source admission (ADR-0161 K8, admitSourceFields), which runs before the source is searched and refuses a listed field that is hidden from the caller or served to them masked. The new test pins that at the tool level: a caller who may not query one listed field gets no hit from that source, and one who may gets its values. The area reports that ablating the gate turns 2 cases red, and restoring it turns them green. The values come from the passage's stored metadata, the same store groupValue already reads, so no live record read is added.
  • The whitelist stays a whitelist. hitOf still names each member, and chunkId and docHash stay out. The test asserts the hit's exact key set.

② Semver level

@objectstack/service-knowledge at patch, which is right. Metadata-protocol: none, since a tool answer's optional member is not authorable metadata, and AGENTS.md ships a non-protocol widening as patch.

③ Boundary flags

  • The dev's boundary note. A field that becomes internal or credential-class after a build keeps its stored value until the recipe-change rebuild. That is true, and it is the same for groupValue and the snippets today, so this PR adds a reader to an existing window and does not open a new one. The caller's queryability is judged at every search, so a permission change takes effect at once. Only the field's classification waits for the rebuild. Recorded as N1, for the owner of ADR-0161 K8.
  • The doc sentence beyond the claimed surface. The one sentence in content/docs/ai/knowledge-rag.mdx matches the code: the listed fields now, by name, as stored, with nulls and stale keys left out, and admission before the search.
  • At this reading the check-runs were 13 success, 15 skipped, 14 in progress, and none had failed. The landing waits for all-green.
  • SQL push-down: no data read is added.
  • No open_questions.

N1: the classification window above is worth one line in ADR-0161's K8 notes, or a follow-up card, now that a third reader serves stored values. It does not affect correctness here.

No must-fix, no should-fix.

Implemented-by: claude/area-o1C-38291
Reviewed-by: session_016WV4czzx9dtSEm3jWWL9c3

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3

L1 verdict (L1-a): ACCEPT at head 5282883f38580bad2195589f1628b29e38bc7ebc (Fixes #38291), on the code. Landing waits for all-green at this head.

Review summary

  • Shape. 4 files, +159/-16. Not governed. Clause-②: yes (widening) · Metadata-protocol: none · @objectstack/service-knowledge patch.
  • The change. Each search_knowledge hit of an indexed record carries metadata: the stored values of exactly the fields its source lists in metadataFields now. They come in list order, from own keys only, with null and absent values left out, and there is no member when nothing is left. There is no new argument, no record read, and no change to groupValue.
  • The gate. Source admission (ADR-0161 K8) refuses a listed field the caller may not query before the source is searched. It is pinned at the tool level, and the area reports an ablation of 2 red, restored green.
  • The record. The declaration-face record 7240932655 at TIER_DEFAULT is PASS with one nit. N1: a field reclassified after a build keeps its stored value until the rebuild, as groupValue and snippets already do. One line in ADR-0161 K8's notes, or a follow-up card, would record that.
  • Scope. The one knowledge-rag.mdx sentence beyond the claim matches the code.
  • Gates. When checked: 13 success, 15 skipped, 14 in progress, 0 failed.

Next: Tier S. The area marks it ready and lands it once every check is green at this head.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP

Landing · area o1-C · head 5282883f38 · 2026-11-28T15:08Z · ACCEPT → PR #38353 comment 7240945515 (L1-a), with declaration-face record 7240932655 (PASS, TIER_DEFAULT)

Probe Reading
check-runs at 5282883f38 42 success · 15 expected skip · 0 failed · 0 pending
check-governed-merges.mjs --pr 38353 NOT governed · +159 / −16
landing-k.mjs --pr 38353 K = 4 < 15

State: ready + auto-merge; #38291 closes on merge via Fixes. Clause-②: yes (widening), Metadata-protocol: none. Record N1 (a field reclassified after a build keeps its stored value until the rebuild, as groupValue and snippets already do) is a note for ADR-0161 K8's owner.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 28, 2026 15:08
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⛔ merge queue 构建失败 — 先分诊,再决定要不要重排

队列构建 46158339477 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集),
所以失败的测试可能在本 PR 没碰过的包里 —— 那不是重排能修的。每次盲目重排都会让排在后面的所有 PR 重建一轮。

分类:failure —— 按下面的日志分诊。

失败的 job(日志抽取,best effort):

  • Test Core (5/12) — 失败步骤: Run this shard's tests

    @objectstack/runtime:test:  FAIL   local  src/domains/packages-knowledge-source-gate.test.ts > /packages — duplicate admits each knowledge source it copies for the caller (guard two) > a source naming
      ↳ 失败原因: @objectstack/runtime:test: AssertionError: expected "vi.fn()" to be called with arguments: [ { name: 'faq', …(3) }, …(1) ]
    

↳ 失败原因 是判读的关键:超时(Test timed out in … / Hook timed out in …)多半是负载/时序,不是本 PR 的回归;
断言(AssertionError: …)才指向真实的行为改变。两者的 FAIL 行长得一模一样,只有这一行能区分。

⚠️ 断言这一侧有一类例外,判据是断言在测什么,不是它是不是 AssertionError。 断言的对象是产品行为(一个值、一个形状、一次拒收)⇒ 照上面读:真实的行为改变,去查,⛔ 不要重排掉;
断言的对象是这次实验自身的有效性前提(跑完的耗时、负载下的先后、任何只在时间预算内才成立的条件)⇒ 它跟超时是同一类,同样对负载敏感,重排一次是合法的判别手段。
识别是机械的:断言的消息或它比较的值本身点名了一段时长、一个时间戳、一个耗时计数。实测过的一对 —— AssertionError: SecurityPlugin.init() ran: expected false to be true 测的是产品行为(真回归);
AssertionError: this run took over a second, so second-precision stamps could have differed too: expected 1006 to be less than 1000 测的是实验前提:它守护的那条不变式当时是绿的,同一个 head 原样重排一次即成功。
穿着 AssertionError 外衣的时间测量,仍然是时间测量。(⛔ 这只改「怎么读一次红」,不改「哪些测试可以重排」——后者由别处管。)

跨 PR 相同签名(24h,按失败测试文件聚合):

历史信号:

  • 本 PR 过去 24h 无队列失败记录(首次)。
  • 过去 24h 队列共有 18 个失败构建(不含本次)。

分诊清单:

  1. 失败测试在本 PR 改动的包里 → 真回归,修 PR。
  2. 失败测试与本 PR 无关 → 看上面的「跨 PR 相同签名」;已有汇总 issue ⇒ flaky/环境问题实锤,去那张 issue 上谈,修好前重排只会再烧一轮全队列。
  3. 两者都不是 → 可能与同组 PR 语义冲突;等前面的 PR 落地或失败出队后再重排一次即可,不要连续重排。

Generated by Claude Code · merge-queue-triage workflow (#4859)

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP

Re-queue · area o1-C · head 5282883f38 (unchanged) · 2026-11-28T15:41Z · ACCEPT → comment 7240945515 (L1-a) still names this head

Queue build 46158339477 ejected this PR only as a stack-mate: its failing case (packages-knowledge-source-gate.test.ts, the duplicate unmounted-adapter case) came from #38341, stacked ahead of it, which conflicted with #38224 and is fixed at 221e401b11. This PR touches none of that file. landing-k OK, K = 9 < 15; check-runs at this head 42 success · 15 expected skip · 0 failed.

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 size/m 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.

search_knowledge: hits do not return the source's metadataFields, so a child-record passage needs an extra read to find its parent

2 participants