Repository navigation
feat(knowledge): a knowledge source orders its hits for the person asking (source.affinity) - #38606
Conversation
…ntity census row Claude-Session: https://claude.ai/code/session_01QsR2jSArETHHmJzkH5368W Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 5 package(s): 55 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 16 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 192 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 c7fbb8d5531f3da03273f568512b3873ca770d82 && git checkout c7fbb8d5531f3da03273f568512b3873ca770d82
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin d042837c104dcfef351fb7dc6952e83e90da1d00 aafe5783036bb60b236ee0f9a44b546e328cb87c && git checkout -B drift-repro d042837c104dcfef351fb7dc6952e83e90da1d00 && git merge --no-ff aafe5783036bb60b236ee0f9a44b546e328cb87c
node scripts/docs-audit/affected-docs.mjs --json d042837c104dcfef351fb7dc6952e83e90da1d00
|
|
repo:objectstack#1 · zhuangjianguo · session_01QsR2jSyQBDMyRnrrWKy7WS Contract-review-claim: session_01QsR2jSyQBDMyRnrrWKy7WS · head 3a730ce · 2026-11-29T14:40Z Seat 1's review thread R1 starts an isolated contract-review sub-agent at |
|
repo:objectstack#1 · zhuangjianguo · session_01QsR2jSyQBDMyRnrrWKy7WS Contract reviewServed-tier: First contract review of PR #38606 (card #38503, part 1 of 2), one full round. Read: the card and its five comments, the PR body and its 45 files, the net diff against merge base ① Derived judgments
② Semver levelThe changeset names every package the diff moves: The move: ③ Boundary flagsThe dev report is read on the card. It carries no
SQL push-down. The re-order runs in memory on the list the search already holds (at most Check-runs on the head, read last just before this verdict (2026-11-29T15:05Z): 76 in all, none still running. 63 concluded ④ Design judgment
What a caller can learn or reorder that they could not before. Nothing, as far as the tree shows. The facts come from the search's
M1 (must-fix) — the head reds S1 (should-fix) — the caller facts are resolved more widely than the note rules. The note: "The platform resolves a fact from the execution context the search already carries, at most once per search and only when a searched source declares an entry that reads it." The card's What repeats it. The head ( N1 (nit) — the bound is one entry's, and its sentence reads wider. Entries add, their number is unbounded, and a repeated N2 (nit) — two equalities the sentences state are not pinned. N3 (nit) — the save door offers a N4 (nit) — sentences left behind. N5 (nit) — the changeset's The nits are not fixed on their own: N1 goes to the approver, N2 to a follow-up. The fix of M1 and S1 moves the head and earns a delta review; N3 to N5 may ride that commit or stay as accepted deviations, at the seat's word. Implemented-by: VERDICT: FAIL |
|
repo:objectstack#1 · zhuangjianguo · session_01QsR2jSyQBDMyRnrrWKy7WS The brief the isolated reviewer was handed for contract-review record 7257817094, as it stood (2026-11-29T15:06Z). The reviewer ran at BriefContract review brief — PR #38606 @
|
|
repo:objectstack#1 · zhuangjianguo · session_01QsR2jSyQBDMyRnrrWKy7WS 席位核对 — REWORK · L1 · seat repo:objectstack#1, review thread R1 · Head-sha
|
… classify the save door's target read The affinity reader resolves at most once per search, only when a hit in the list belongs to a declaring source, and only the facts its entries read: `user` is the search's own user id and reads no row, `business_unit` reads the caller's user row and units as the caller, and no organization row. A fault reading the units leaves them out and keeps the user fact. The #22661 pin classifies knowledge-source-admission.ts as not a served read, naming where the feature reads sys_user and sys_business_unit rows and why those fixed-object reads are outside what the pin holds. Claude-Session: https://claude.ai/code/session_01QsR2jSArETHHmJzkH5368W Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#1 · zhuangjianguo · session_01QsR2jSyQBDMyRnrrWKy7WS Contract-review-claim: session_01QsR2jSyQBDMyRnrrWKy7WS · head f55fdc0 · 2026-11-29T16:09Z Seat 1's review thread R1 hands this head to the isolated reviewer of record 7257817094 at |
|
repo:objectstack#1 · zhuangjianguo · session_01QsR2jSyQBDMyRnrrWKy7WS Contract reviewServed-tier: Delta round on PR #38606 (card #38503, part 1 of 2). It follows my record on ① Derived judgmentsThe delta moves none of them. The accept-set is unchanged: ② Semver levelLevels and both declaration lines are unchanged, and ③ Boundary flags
SQL push-down. The delta adds no read and removes several: a Check-runs on the new head, read last just before this verdict (2026-11-29T16:40Z): 72 in all, none still running, none failed. 63 concluded ④ Design judgmentM1: closed. S1: closed. Read against the note's sentence, "at most once per search and only when a searched source declares an entry that reads it".
Would the pins fail without the fix? By reading, yes, each of them. The The rewritten reader, judged as new code.
The other hunks.
N1: carried, card #38615. N6 (nit) — the row's last clause credits the wrong guard. It says "the target refusal keeps an entry from naming any other object". That holds at the save door; a source that does not pass it is not refused until PR 2. What keeps the reads to N7 (nit) — the No must-fix, no should-fix. N6 and N7 are not fixed on their own; they may join #38615 or stay as accepted deviations, at the seat's word. Implemented-by: VERDICT: PASS |
|
repo:objectstack#2 · os-warren · session_01JQwxbZFEo6URsCoWYcL8ub 速读
席位意见: ACCEPT. Seat 2 takes over seat 1's L1 on this PR (takeover claim 7264997030 on #38503, the maintainer's word quoted there). This is the delta L1 against REWORK 7257846388; the delta contract review 7259099085 ( 席位核对 — ACCEPT · L1 delta · seat repo:objectstack#2 (zone o2-S1) · Head-sha
|
|
repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu 2026-11-30T00:55Z · Landing · seat lands this Tier S pull (not governed; Clause-② widening with the contract-tier review PASS 7259099085 at this head
|
The pull left the merge queue when main moved. One conflict, in the generated content/docs/references/index.mdx (schema counts): resolved by regenerating from this tree (spec build, then gen:docs); check:docs reports all 248 generated files in sync. The AI module gains the three knowledge-affinity schemas this branch adds (102 -> 105; total 1745). Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXyLoBzNYY1U8SNPFu
|
repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu 2026-11-30T02:18Z · Re-landing after the queue drop · the pull left the merge queue at 01:18Z when Regen-provenance: 7259099085 ·
|
Requested by Jianguo · project thread
Part of #38503
Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: follow-up #38610
维护者速读
What changes
PR 1 of 2 for the card. This PR lands the key, its parse refusals, its save-door refusal and its first reader. The
os validatehalf of the target-field refusal is PR 2 (the lint package is held by another card's queue). The card's three-arm measurement was run on this branch's build (see Acceptance notes).ObjectKnowledgeSourceSchemagainsaffinity?: KnowledgeAffinityEntry[], each{ field, caller, mode, places? }(KnowledgeAffinityEntrySchema, strict; author and…Parsedaliases per ADR-0122).callerisuserorbusiness_unit;modeisboostornearest. Refused at parse, each with a sentence naming the fix: afieldnot inmetadataFields;mode: 'filter'(narrowing is the search scope, who may read a record is sharing) and any other mode; a caller outside the two; a secondnearest;nearestwithcaller: 'user';placesmissing onboost, present onnearest, or outside 1 to 20. The cross-key rules are refinements JSON Schema cannot state, ledgered indropped-refinements.baseline.json(the entry schema, plus the two source schemas and four installed-package response schemas that embed it; header totals updated).placesbound: 20 (KNOWLEDGE_AFFINITY_MAX_PLACES, stated on the key). It is the most hits onesearch_knowledgeanswer carries (SEARCH_KNOWLEDGE_MAX_TOP_K). A boost ofplets a match standing at numbernin its tier land just behind numbern − p, so withpat the largest answer a match is brought into an answer from at most one answer's length below it. A larger number adds nothing an author can see in an answer and drifts toward "matches first", which the note keeps fornearestonly.@objectstack/core—resolveCallerIdentity(mcp: tell the model who is signed in — the asker's user and business-unit chain reach the ask route (cloud#5099) but not an MCP client #38363), with its types andCALLER_UNIT_CHAIN_MAX_DEPTH, moved unchanged frompackages/runtime/src/domains/mcp.tsintopackages/core/src/caller-identity.ts, so the knowledge service (which does not depend on the runtime) calls the same functionget_current_userdoes. The runtime imports it from core and re-exports it for its own tests;get_current_userbehaviour is unchanged andmcp-asker-38363.test.tsstill pins it through that re-export. This settles where the resolver lives (the note's slice line).knowledge-affinity.tsholds the two halves.resolveAffinityFactsresolves only the facts a declared entry reads:useris the search's ownctx.userIdand reads no row;business_unithands the resolver the user id alone, so it reads the caller's user row for the primary unit and each unit up the chain, by id as the caller throughdataEngine.findwith the search'sExecutionContext(a unit the caller may not read ends the chain), and no organization row; the system identity has no facts.orderByAffinityis the note's rule exactly: per source among the places its units hold; judged on the hit standing for each unit;nearesttiers (own unit, each parent in order, every other unit, a hit with no value among them; a multi-value lookup takes its nearest element); inside a tier key = number − sum of matchedplaces, ties to the larger sum then the earlier number; values compared as a scope term compares them; no score written. InsearchByKey,affinityOrderForresolves the facts at most once per search, only when a hit in the list belongs to a source that declares an entry, and only those its entries read; the order runs after the score sort and beforeslice(0, topK)(chunk granularity) or insideanswerByRecord'sleads()before its cut (record granularity, so the freshness check checks the re-ordered top). The rounds, the refill and the re-check are untouched. Moves go to thedebuglog only. A unit read that fails for a reason other than a refusal leaves the units out, reported once atwarn, and keeps theuserfact, so aboostby user still applies (a functional degradation: every hit is still answered).admitAuthoredSourcerefuses an entry whosefield(listed inmetadataFields) does not point atsys_user(foruser) orsys_business_unit(forbusiness_unit), judged byreferenceTargetOf:400 VALIDATION_ERROR,fieldset, after the documentBy arm and before every permission arm (affinityTargetRefusalTextinknowledge-source-admission.ts).content/docs/permissions/system-context.mdxgains row 46a: under the system identity a source'saffinitymoves nothing and no user or unit is read (resolveAffinityFacts, the oneisSystemread; the register is regenerated).affinityis in neither the index fingerprint nor the recipe hash; pinned with a control that the recipe hash still readsmetadataFields.widget: 'json', with its regenerated translation bundles.content/docs/protocol/knowledge.mdxgains "Ordering for the asker";content/docs/ai/knowledge-rag.mdxrewrites "sorted by score, and capped attopK", which this code makes untrue for a declaring source, and gains a short "Ordering hits for the asker". TheIKnowledgeService.searchjsdoc says the same.Tests
packages/services/service-knowledge/src/__tests__/affinity-38503.test.ts(new, 24): the order rule on its own (tiers, places, ties, a multi-value lookup, values compared as strings); through the service:nearestunder chunk granularity attopK5 answers p8, p9, p4, p2, p1 with their original scores; the caller's user row and units read once per search, as the caller, and no organization row;boost, with auser-only source reading no row; no fact read when no hit belongs to a declaring source; record granularity (the re-ordered top is what the freshness check sees); a source withoutaffinityunchanged with no identity read; the system identity; a parent unit the caller may not read (403) ends the chain; a 500 on the unit read leaves the units out with onewarnand keeps the user boost; nothing dropped or added;affinitychanges neither hash (with ametadataFieldscontrol); the save door's target refusals, each with no record read (anearestentry pointed at aboost). Forcing the reader to return no facts turns 6 of them red; reading every fact regardless of the entries turns 2 red.packages/spec/src/ai/knowledge-source.test.ts: 10 new parse cases (a positive control, the bound at 20 and 21,placestype and presence per mode,filter, an unknown caller, a secondnearest, a field outsidemetadataFields, an unknown key).test:repo1,608 tests; core 158 files / 3,818 andtest:repo110 (the security(data, analytics): a lookup target's exposure declaration is not judged when the data door's$expand, or the dataset door's dimension-label pass, reads it — detail withheld pending maintainer #22661 pin included); service-knowledge 25 files / 830; platform-objects 130 files / 2,218; runtimemcp-askerandmcp-authoring91. Every touched package's typecheck exits 0. The dogfood battery at f55fdc0: 495 files / 4,187 tests passed, 3 files skipped.dispatch-gatesderived 127 commands and all 127 ran (--ranreconciles 127 of 127). Two were red and are fixed in this PR (check:spec-parsed-alias,check:system-context-census). Three stopped on a missing prerequisite and pass once it is met (check-plugin-teardown-shape --self-test,check:skill-examples,check:published-readme-exports).check:dual-build-cjs-loadsneeds the whole workspace built and is left to CI.Acceptance notes
Three-arm measurement, as measured. BrightRule's eval (07e21ac), the 44
unit_scopequestions, 3 reps each (132 records per arm), asked over MCP against a server started on this branch's build, answered and judged blind on the container's local plan (the AI gateway key generated embeddings only). Tier and effort for both the answering and the judging model are recorded with the run files.nearestonowning_unitThe English questions moved from arm 2 to arm 3 41.7% → 55.6% (18 records), the Chinese questions 93.8% → 91.9% (105 records). No arm leaked. Four judge replies (two in arm 2, two in arm 3) did not parse and were scored by the rules alone. Security model: should every plain member read their own primary business-unit chain by default (asker identity for #38503's arm 2)? #38515 has not landed, so the personas are members who already read the units (BrightRule grants employees that read). Arm 3's
affinityentry was added in a local clone only. The maintainer ruled at 2026-11-29T14:44Z that ordering hits by the asker's relation needs no comparison to justify it, so no conclusion is drawn from these numbers and nothing gates on them.Not in this PR: the
os validaterule for the target field (PR 2,packages/lint);expand.window(knowledge_source: a hit brings its neighbouring content (expand, siblings slice of the #38412 ruling) #38504);expand.follow(knowledge_source: a hit brings one declared lookup hop (expand.follow, #38412 ruling) #38505); afiltermode, date decay, other caller facts and any opt-out argument (out of the card).Skills-docs:
skills/objectstack-ai/SKILL.mddocuments the source keys and does not yet teachaffinity; the follow-up is skills: objectstack-ai teaches a knowledge source's affinity key (order hits by the asker's relation to a declared field), which #38503 adds #38610.Ordering by position means a declaring source's answer may no longer be in descending
score; this is the note's rule (5) and is pinned.Verification
Read first, by risk:
packages/services/service-knowledge/src/knowledge-affinity.ts#orderByAffinity(the rule),knowledge-service.ts#affinityOrderForand the two call sites insearchByKey/answerByRecord(where the order sits relative to the cut),packages/spec/src/ai/knowledge-source.zod.ts(the key and its refusals).Two-minute check:
pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/affinity-38503.test.ts— 24 passed, including a search where the caller's own unit's policies (ranked 8th and 9th) answer first with their original scores.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01QsR2jSArETHHmJzkH5368W