Repository navigation
feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations - #37256
Conversation
….organizationIds (ADR-0161 K8 item 9) Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1 Co-authored-by: Claude <noreply@anthropic.com>
…mory adapter filters before ranking; contract cases Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1 Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1 Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1 Co-authored-by: Claude <noreply@anthropic.com>
…onId Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1 Co-authored-by: Claude <noreply@anthropic.com>
…ssion's one system bypass Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1 Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1 Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 3 package(s): 35 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 10 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 176 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 99f48902f4d11cae1fef938986d85c78bb8309b2 && git checkout 99f48902f4d11cae1fef938986d85c78bb8309b2
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 9171bed0a65ab242567f243969368ead786cd830 6e978db363c73dc9d151549ef46d6c141bc679ac && git checkout -B drift-repro 9171bed0a65ab242567f243969368ead786cd830 && git merge --no-ff 6e978db363c73dc9d151549ef46d6c141bc679ac
node scripts/docs-audit/affected-docs.mjs --json 9171bed0a65ab242567f243969368ead786cd830
|
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentClaims checked against the code at this head:
Findings:
The docHash question: option A, and the ADR note lands before this PR. Implemented-by: VERDICT: FAIL |
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — REWORK · L1 · head
|
…the event sync on an unreadable posture; TSDoc on organizationId with docHash Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1 Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1 Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Contract reviewServed-tier: Delta record. It continues the record at ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentPrior items, by id:
On N5's behaviour, warn and keep. It is safe as stated, with one consequence worth writing down. The row is re-read before the posture is read, so a row that is gone or no longer matches is still deleted from the index; only a row that still matches is kept as stored. That stored document can then be stale in content or in organization (the record was edited, or moved to another organization, while the posture was unreadable). A stale organization means the old organization's callers can still have the document take a ranking place; the permission re-read then returns nothing for them, so nothing is served across the wall, and the new organization does not see it ranked. The repair is the row's next event or a complete reindex (the hash differs). Both alternatives are worse: an upsert without the posture would write an unstamped document, and a delete would drop a document whose row still matches. A reindex under the same fault refuses to write, so the two paths agree. The gap is the same class as a missed event, which K1's reconcile exists for. Findings:
Why M1 stays a grade and is not carried as a Implemented-by: VERDICT: FAIL |
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — REWORK · L1 · head
|
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Contract reviewServed-tier: Close-out record. It continues the delta record at this same head (comment 7158593765) and the record at ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentPrior items, by id:
No new finding. The head did not move, and the eight commits on main since the merge-base reach none of this PR's files, so no closed item reopens. Implemented-by: VERDICT: PASS No must-fix, no should-fix. |
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ 席位核对 — ACCEPT · L1 · head
|
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Landing · 2026-11-25T10:01Z · PR #37256 at
|
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Re-queue after a merge-queue kick · 2026-11-25T10:22Z · PR #37256, head
|
repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ
Fixes #37097
repo:objectstack#4 · os-justin · session_01QSeKYkS1d2QkEUgqhneuU1
Clause-②: yes
Metadata-protocol: added
Skills-docs: none — no skill under
skills/**teachesKnowledgeDocument,AdapterSearchOptionsor the adapter contract suite;skills/objectstack-ai/SKILL.mdteachesKnowledgeSourceauthoring only.content/docs/protocol/knowledge.mdxgains the members and an "Organization scope" section here.维护者速读
What changes
ADR-0161 K8, item 9, with
knowledge-memoryas its first reader:KnowledgeDocument.organizationId?(packages/spec/src/ai/knowledge-document.zod.ts). The service sets it when it assembles a document from a record: the record'sorganization_idunder thegroupandisolatedpostures. It is absent undersingle, forfile/httpsources and for a record with no organization.indexDocumentrefuses a caller-supplied value, as it refuses a caller-supplieddocHash. The TSDoc also says that an adapter storingdocHashstoresorganizationIdfrom the same version on.AdapterSearchOptions.organizationIds?(packages/spec/src/contracts/knowledge-adapter.ts). The service computes it perobjectsource inknowledge-organization-scope.tsand derives nothing itself:classifyAdmissionTenancyPostureover the kernel'stenancyservice.KnowledgeServicePluginwires it as the newresolveTenancyPostureoption, next toresolveSecurity; the mount logic is untouched. The wiring is pinned through real kernels (LiteKernelandObjectKernel): walled, notenancyservice, and atenancyservice that cannot be read;computeTenantLayer0Verdict(@objectstack/core) for the source's object, over the context'stenantId/accessible_org_ids.isolatedgives the active organization andgroupthe deduplicated membership set. Adenyverdict becomes[];none(an object outside tenancy, or with noorganization_idcolumn) gives no filter;single, for the system identity and forfile/httpsources.The TSDoc spells out the three cases: absent means no filter, a set means filter before ranking,
[]means rank nothing (never "no filter").knowledge-memorystoresorganizationIdand filters byorganizationIdsbefore it scores, sotopKis filled from in-scope documents only.The permission re-read is unchanged and remains the access decision. Nothing new is logged or returned about how many hits a filter removed.
docHashcoversorganizationIdonly when the document has one.DOC_HASH_VERSIONstaysv1, so a document without an organization hashes byte-for-byte as before (pinned against the old recipe).A posture that cannot be read (a
tenancyservice is registered but unreadable): a search leaves everyobjectsource unsearched for that call and logs aterror; a reindex stops before writing and returnsok: falsewith the reason. An event sync logs atwarnwith the reason and leaves the stored document as it was (no upsert, no delete; pinned).Contract suite (
@objectstack/service-knowledge/testing):implements.organizationIdsis required, which is fine because the suite has not been released yet. It adds adapter-only cases and cases through a realKnowledgeServiceunderisolated,groupandsingle, plus the upgrade case for documents indexed before this change.PM mechanism assumptions, measured
KnowledgeSearchOptionshas no organization member, and the service buildsorganizationIdsitself. A caller's opaquefilter: { organizationIds: [...] }stays insidefilter(pinned), andsearch_knowledge's closed input set refuses anorganizationIdsargument (pinned). The only callers are the MCP bridges throughknowledgeTools(); no REST route reachessearch.[]and absent are different.[]filters to nothing in the TSDoc, inknowledge-memoryand in the suite. Underisolatedwith no active organization, and undergroupwith no membership, the adapter is handed[](pinned).organizationId. Behind a wall a filtered search excludes them until a complete reindex writes them again. Their hash changes once the organization is included, so that reindex does not skip them. Undersinglenothing changes. This is documented in the TSDoc, the protocol doc and the changeset, and tested in the contract suite ("a document indexed without its organization is not ranked behind a wall until a complete reindex writes it again").runKnowledgeAdapterContractwas extended, not a memory-only test.Tests
Local runs on the final head 6e978db (origin/main d62f9e9 merged; two commits since 3df745d add tests and a TSDoc sentence)
pnpm --filter @objectstack/knowledge-memory exec vitest run: Test Files 2 passed, Tests 29 passed.pnpm --filter @objectstack/service-knowledge exec vitest run: Test Files 8 passed, Tests 197 passed.pnpm --filter @objectstack/service-knowledge --filter @objectstack/knowledge-memory run typecheck: exit 0 (tsc + test-typecheck, 0 debt).pnpm --filter @objectstack/spec build && … check:generated: "All 14 generated artifacts are up to date". Before the merge, one artifact was stale (check:docs) and was regenerated with--fix. That diff is theorganizationIdrow and thedocHashdescription incontent/docs/references/ai/knowledge-document.mdx.authorable-surface/ai.jsongainedai/KnowledgeDocument:organizationIdfrom the spec build.Derived gate families (dispatch-gates --commands, 117), with --ran reconciliation
pnpm check:system-context-censusexited 1 because the new organization scoping held two system-identity elevation reads with no row on the system-context page. Fixed at 44494ec by moving the scoping underadmitSources' existing system bypass (row 46). The system identity's search therefore skips the organization filter through the one read the page already documents, and the census reads OK (202 sites, register matches).check-plugin-teardown-shape.mjs --self-testneeds a deeper clone (the same exit 3 on the main base d7f299c);check:skill-examplesneeds@objectstack/client-reactbuilt;check:dual-build-cjs-loadsneeds every package's dist. These are left to CI.dispatch-gates --ran: 117 derived, 114 run, 3 NOT-MEASURED, 0 UNRUN.Ablations (scripts/ablation-replace.mjs; each mutation proven on disk and restored to the HEAD blob)
organizationsforcedundefined): 6 contract cases red (the 3 adapter-only filter cases, both service cases under isolated and group, and the upgrade case). Restored to blob 70dc64b28dca.organizationIddropped from the hashed body: 2 red (the contract upgrade case, and the service hash pin). Restored to fe7502ad5613.organizationIdsto the adapter: 4 contract cases and 5 service cases red. Restored to fe7502ad5613.resolveTenancyPosturewiring replaced byasync () => undefined: 3 service cases red (both walled kernel cases and the unreadable case); the no-tenancy case stays green. Restored.Acceptance notes
organizationId, but only when the document has one. Without that, a complete reindex would skip every document indexed before this change, and those documents would never gain their organization behind a wall. Documents without an organization keep their exactv1hash. The contract review (7157191417, M1) asks for a dated note on ADR-0161 to land first; that note is PR docs(adr): ADR-0161 dated note — the document hash covers the organization of a document that has one (K8 items 2 and 9) #37263, merged first as8032d958f2.computeTenantLayer0Verdictcome from the engine'sgetSchema:tenancy.enabled: falseorsystemFields.tenant: false, and whether anorganization_idfield exists. Unknown schema means the object is treated as walled. External (federated) objects are not special-cased, soexternalOrganizationScopeUndeclaredisfalse. Platform-admin crossing is not applied to ranking (isPlatformAdmin: false). The re-read still decides access either way.recordToDocumenttakes the posture as an optional fifth argument, so existing calls behave as before.admitSources, the same bypass now also skips the organization filter. The row's prose does not mention organizations. The page is outside this card's file surface, so it is left unchanged and its owner can choose to add that.Verification
Two-minute check:
pnpm --filter @objectstack/knowledge-memory exec vitest run src/__tests__/contract.test.tsshould report 21 tests passed, including "isolated: a search from organization A never ranks or returns B's documents" and "group: …".Read first:
packages/services/service-knowledge/src/knowledge-organization-scope.ts: the posture-to-organizations mapping (risk: a wrong verdict input widens or empties the ranking scope).packages/services/service-knowledge/src/knowledge-service.ts:scopeByOrganization, pluscomputeDocHash/recordToDocument(risk: the hash change decides what a reindex rewrites).packages/plugins/knowledge-memory/src/index.ts,search(risk: filtering after scoring instead of before).Generated by Claude Code