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
|
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 45590970668 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 分类: 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
…ation of a document that has one (K8 items 2 and 9) (objectstack-ai#37263) repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Part of objectstack-ai#37097 repo:objectstack#4 · os-justin · session_01QSeKYkXwZ3ECV8yacsjMJM Clause-②: yes Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:用户无感;只在「知识检索平台边界」这份决定记录里加一条带日期的说明,写明文档指纹在文档带有所属组织时把组织也算进去,不带组织的文档指纹与以前逐字节相同。 - 为什么做:属于「知识检索平台化」专题第二阶段;实现改动 objectstack-ai#37256(让索引文档记下所属组织、检索时先按组织过滤)改了指纹的算法,按这份记录自己的规矩,这种改动要先以带日期的说明写进记录、由你批准。 - 出错会怎样:说明写错的话,后面写存储适配器的人会照着错的做,最坏是换了组织的文档在重建索引时被跳过、在按组织过滤的检索里排不上;这次只有文档,撤回这次合并即可。 - 要你做什么:审后由你本人合并(合并即批准),并且要排在实现改动 objectstack-ai#37256(上面那个让文档记下所属组织的改动)之前合并。 ## What changes One file under `docs/adr/`: `0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md`, 9 lines added and none removed against `main`. No schema, no code, no changeset. **This PR must merge before PR objectstack-ai#37256.** That PR changes the hash recipe of K8 item 2, and K8 rule 3 gives the form of such a change: "the change is a dated note on this record". Contract review `7157191417` on PR objectstack-ai#37256 (its finding M1) and the seat's L1 `7157210840` hold that PR until this note has merged. `docs/adr/**` is Tier H: the maintainer merges this PR; no seat approves, merges or enqueues it. `Part of objectstack-ai#37097`, not a closing line: the card's implementation is PR objectstack-ai#37256 and stays there. This PR carries the record's note and nothing else. Two additions, both in the form sibling records already use (ADR-0090 and ADR-0151, notes of 2026-11-24): 1. **A dated note under K8's table**, as a blockquote that opens `Note (2026-11-25, card, built by PR)`. The table is left as written. 2. **One `Amended` bullet at the end of the header list**, pointing at the note. The `Status:` line is byte-identical, so the generated `docs/adr/README.md` does not change and is not in the diff. The note, as it stands at the head: > **Note (2026-11-25, [objectstack-ai#37097](objectstack-ai#37097), built by [objectstack-ai#37256](objectstack-ai#37256)) — items 2 and 9: the hash covers the organization of a document that has one.** Item 2's hash covers the document as the service assembles it. The parenthesis "content, title, metadata" was everything assembly set on a document, its identity aside, when item 2 was accepted. Item 9 adds `organizationId` to the assembled document when the document has one, and the hash covers it then. A document without one hashes byte for byte as it did before, so the version prefix is not bumped. > > - **Why.** A document that gains an organization, loses it or moves to another one gets a new hash, so a complete reindex never leaves a stale organization on a stored document. The other answer kept the parenthesis and bumped the version. It leaves a later change of organization to the events alone, and missed events are the hole reconcile exists to close (K1). > - **A later optional member that assembly sets** enters the hash the same way, left out when it is absent, or the version is bumped. > - **What an adapter stores.** An adapter that stores `docHash` stores `organizationId` from the same version on; otherwise, once it starts reading this field, a complete reindex skips its documents and a walled search never ranks them. > > Item 9's first reader, objectstack-ai#37097, is built by PR objectstack-ai#37256, and this change to item 2 lands with it. The reasoning is contract review [`7157191417`](objectstack-ai#37256 (comment)) on that PR (its M1 and S2). The table is left as written; read items 2 and 9 with this note. The header bullet: > - **Amended** (2026-11-25, [objectstack-ai#37097](objectstack-ai#37097)): a dated note under the table of [K8](#k8--the-contract-additions-decided-item-by-item) records that the document hash of item 2 covers `organizationId` when the document has one (item 9), with no version bump. The status line above is left as it is. What each sentence of the note rests on: | Sentence | Read where | |:--|:--| | the hash covered content, title and metadata | `packages/services/service-knowledge/src/knowledge-service.ts#computeDocHash` on `origin/main` at `d62f9e9c` | | assembly also sets the document's identity, which the hash never covered | `recordToDocument` in the same file at `d62f9e9c`: `id`, `sourceId`, `sourceRecordId` beside `content`, `title`, `metadata` | | the organization enters the hashed body only when the document has one; the version stays `v1` | `computeDocHash` and `DOC_HASH_VERSION` on PR objectstack-ai#37256's branch at `e8b0688f` (and unchanged from `3df745d2`, the head the review read) | | events keep an index fresh, reconcile keeps it correct | K1 of this record, the "Sync and reconcile" row | | the adapter sentence | finding S2 of review `7157191417`; character for character the spec TSDoc on `KnowledgeDocument.organizationId` on PR objectstack-ai#37256 at `6e978db3` | ## Tests No test changes: the diff is one Markdown file. The derived gate families were run at `dd1756af`. The final head `aec56080` changes only the adapter sentence's wording, and CI at `aec56080` is 25 success, 19 skipped, 0 failed. <details><summary>Local gates at dd1756a: 21 derived, 21 run, all exit 0</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 21 commands from the branch's change set (1 path against merge base `d62f9e9c`). Each was run with its output redirected to a file and its exit code read before any pipe. | Command | Exit | |:--|:--| | `node scripts/check-adr-links.mjs` | 0 | | `node scripts/check-adr-links.mjs --self-test` | 0 | | `node scripts/check-closing-keyword-parity.mjs` | 0 | | `node scripts/check-closing-keyword-parity.mjs --self-test` | 0 | | `node scripts/check-comment-mask-corpus.mjs` | 0 | | `node scripts/ci/plan-test-core-shards.mjs --self-test` | 0 | | `pnpm --filter @objectstack/lint run check:doc-formula-expressions` | 0 | | `pnpm check:adr-anchors` | 0 | | `pnpm check:adr-index` | 0 | | `pnpm check:adr-symbol-anchors` | 0 | | `pnpm check:ci-filter-parity` | 0 | | `pnpm check:closed-ceremony-text` | 0 | | `pnpm check:cross-package-test-inputs` | 0 | | `pnpm check:doc-authoring` | 0 | | `pnpm check:driver-memory-census` | 0 | | `pnpm check:gitlink-declared` | 0 | | `pnpm check:nul-bytes` | 0 | | `pnpm check:pm-governed-merges` | 0 | | `pnpm check:pm-prior-rulings` | 0 | | `pnpm check:refd-timer-probe` | 0 | | `pnpm check:watch-hint-literal` | 0 | Reconciliation, `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran` with the exit codes recorded, at `dd1756af`: ```text Run reconciliation — 21 derived, 21 run, 0 NOT-MEASURED, 0 UNRUN. ✓ dispatch-gates --ran: 21 derived famil(ies) accounted for — 21 run, 0 NOT-MEASURED (a DERIVED zero — all 21 recorded an exit code and none of them is 3). ``` Verdict lines from that run: ```text ✅ check-adr-links: 1222 relative link destination(s) under docs/adr/ resolve adr-index --report: OK — docs/adr/README.md is current, every record parsed, self-test 60 assertions green. … ✅ check-adr-symbol-anchors: 4199 anchors across 163 records resolve … check-nul-bytes: OK (scanned 27788 text file(s) -- 27788 tracked, 0 untracked-not-ignored; skipped 101 binary; no raw ASCII control bytes). ``` One family was not measured on its first run. At the first commit `15616e2f`, `check:doc-formula-expressions` exited 3, PREREQUISITE NOT MET: it imports the compiled output of `@objectstack/formula` and `@objectstack/lint`, and neither was built in a fresh worktree. After `pnpm exec turbo run build --concurrency=2 --filter=@objectstack/formula --filter=@objectstack/lint` under the verify lock (`VERDICT command-exit 0`), it exited 0 at `15616e2f` and again at `dd1756af`. `node scripts/pm/overlap-check.mjs --branch=claude/issue-37097-adr-0161-dochash-note` before each of the three pushes: `VERDICT clean exit 0` (at `dd1756af`: 1 changed file, against `origin/main` `d62f9e9c` and 0 PR heads). </details> ## Acceptance notes - **Where the note's words differ from the dispatch order's summary**, each for precision: - The order's summary says the item 9 reader "landed" in PR objectstack-ai#37256. This note merges first, so it says the reader "is built by PR objectstack-ai#37256, and this change to item 2 lands with it", which is true before and after that merge. - "The whole assembled document" became "everything assembly set on a document, its identity aside": assembly also sets `id`, `sourceId` and `sourceRecordId`, and the hash never covered those. - The rule for a later optional member is scoped to a member "that assembly sets", so it does not read as a rule about every optional key of `KnowledgeDocument` (the chunk channel of item 5 is set by the splitter and belongs to K7's fingerprint). - The adapter sentence is the spec TSDoc's sentence on PR objectstack-ai#37256, word for word (commit `aec56080`), so the record and the contract say the same thing. - **The header bullet** was not in the order's list. It follows ADR-0151, whose header has the same shape and gains one `Amended` bullet per dated note. - **The note cites the review record** `7157191417`, so that the approver finds the reasoning from the record itself. - **No `scripts/adr-anchors` entry.** `pnpm check:adr-anchors` exits 0 without one, so the gate does not require it for the note. The review's N4 (an anchor for K8 item 9 in code) stays a follow-up outside this file surface. - **No changeset.** `docs/adr/**` publishes nothing and no derived gate asked for one; the PR carries `skip-changeset`. - **PR objectstack-ai#37256 moved while this was written**, from `3df745d2` (the head the review read) to `6e978db3`. What changed there is a test file and the spec TSDoc; the hash recipe is the same at every head. ## Verification Read first: 1. The note under K8's table in the one changed file. The sentence to weigh is the adapter rule, "An adapter that stores `docHash` stores `organizationId` from the same version on": K8 rule 2 keeps every member optional, and this sentence says two of them are taken up together. 2. The "Why" bullet of the same note: it records which answer was not taken (keep the parenthesis, bump the version) and why. 3. `computeDocHash` on PR objectstack-ai#37256's branch, `packages/services/service-knowledge/src/knowledge-service.ts`, to hold the note against the recipe it describes. Two-minute check: open this PR's Files tab. It shows one file under `docs/adr/`, +9 −0: one `Amended` bullet at the end of the header list, and one blockquote between K8's table and the paragraph that starts "What "capabilities" became." Body rewritten to head `aec56080` by seat repo:objectstack#4 (session_01QSeKYpEsWWE9Y5YtSsDgqZ) from the dev's round-2 report 7158272523. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYkXwZ3ECV8yacsjMJM)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
… Chinese-aware), the chunk channel and the split key; KnowledgeChunk.metadata and knowledge.chunk_overlap retired (objectstack-ai#37287) repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ Fixes objectstack-ai#37098 Clause-②: yes (narrowing) — widens the knowledge contract (the `split` key, `chunks`, `headingPath`, the adapter's `capabilities` and `embedding`, `IEmbedder.maxInputTokens`, the reindex `failed` / `failures`) and narrows two accept sets: `KnowledgeChunk.metadata` is refused, and `knowledge.chunk_overlap` is no longer a key of the `knowledge` settings namespace Metadata-protocol: narrowed Skills-docs: follow-up objectstack-ai#37292 — `skills/objectstack-ai/SKILL.md` does not yet teach `split` or name the two retired keys; that file is governed and outside this claim. `content/docs/protocol/knowledge.mdx` (new §3.5) and `content/docs/ai/knowledge-rag.mdx` document it here. ## 维护者速读 - 用户能看到什么变化:知识检索在建索引时由平台统一把文档切成片段,长制度按章、条切开,中文按句号问号断句,不会切在「3.2 条」「400.50 元」中间,也不切开表格。 - 为什么做:属于「知识检索平台化」专题第二阶段,让每种存储拿到的片段完全一致。 - 出错会怎样:整篇切法下超过模型上限的文档会从检索中移除并报失败,不会被截断;设置页的「片段重叠」一项被移除(它从未生效),片段上一个从未被使用的字段也被移除,写了它的代码会收到带修复说明的报错。 - 要你做什么:无。 ## What changes - **One splitter in the service** (`packages/services/service-knowledge/src/split/`): `whole`, `recursive` (blank line, line break, sentence end, semicolon, character; Chinese-aware sentence rule; tables and list items kept whole while they fit; short pieces merged up to `minChars`), and `markdown` (one section per heading, the heading path embedded at each passage's start and carried as `headingPath`). - **The chunk channel, as ADR-0161 K8 item 5 settled it.** `KnowledgeDocument.chunks?`, `KnowledgeChunk.headingPath?`, and `IKnowledgeAdapter.capabilities?.chunks`. An adapter that declares it gets every document with the service's passages; one that does not keeps receiving whole documents. `indexDocument` refuses caller-supplied `chunks`, as it refuses `docHash`. - **The limit, per ADR-0161 K8 item 6.** `IKnowledgeAdapter.embedding?.maxInputTokens` and `IEmbedder.maxInputTokens?`, read at use, never cached. `embedder-openai` reports its limit from the objectstack-ai#37093 table. A passage keeps `maxChars` (`split.maxChars`, else `knowledge.chunk_target`, else 800) and, when a limit is known, `estimateTokens` within 80% of it (the shared estimate, not forked). - **`whole` over the budget is removed and reported, never truncated.** `reindexSource` gains `failed` and `failures` (at most 20 named). The event sync logs at `error` with source, record id, estimate and limit. `indexDocument` throws. - **The `split` key**, ADR-0161 K8 item 10: `ObjectKnowledgeSource.split?: { strategy, maxChars?, minChars? }`, read by the splitter. - **`knowledge-memory` drops its own chunking.** It declares `capabilities.chunks` and indexes the service's passages as given. - **Settings.** `knowledge.chunk_target` gains its reader, through the `settings` service at use, never at boot. It is now shown for the in-memory adapter too. `knowledge.chunk_overlap` is retired the way the Localization format keys were: removed from the manifest and its 11 translations, `version` 1 to 2, a stored row kept, a write refused `400 UNKNOWN_KEY`. - `docHash` keeps its recipe: the passages are derived from `content` and do not enter it. ## BREAKING - `KnowledgeChunk.metadata`: FROM an optional record, accepted and stripped, TO a `retiredKey()` tombstone (a parse refusal with the prescription; `tsc` types it `never`). Nothing wrote or read it. Fix: delete the key; filter on the document's `metadata`. ADR-0161 K8 item 5, by seat direction 7158283273. - `knowledge.chunk_overlap`: FROM a key of the `knowledge` settings namespace TO no key (not shown or resolved; a write is refused `400 UNKNOWN_KEY`; a stored row is kept). Nothing read it. Fix: stop writing it. Retirement kit, per the `spec-property-retirement` skill, under protocol major 18 (seat ruling A): - the `retiredKey()` tombstone; - `RETIRED_KEYS_BY_MAJOR[18]` row `ai/KnowledgeChunk:metadata`; - D3 `knowledge-chunk-metadata-retired` and its `STEP18_RATIONALE` fragment; - the `[RETIRED]` line in `authorable-surface/ai.json`; - the regenerated reference; - the pin `packages/spec/src/ai/knowledge-document.test.ts`; - the changeset's `adr-0087: registered` marker. No D2 conversion: a chunk is a runtime contract shape, never stored in stack metadata, so `os migrate meta` has no source to rewrite — the `ActionDescriptor.isAsync` disposition. The settings key follows the Localization format keys' retirement: specifier and 11 translations removed, manifest `version: 2`, stored rows kept. ## Tests - `split.test.ts`: six golden files (Chinese regulation with 章/条, a Markdown table, a long unpunctuated run, mixed zh/en with quotes, 「3.2 条」 and 「400.50 元」, a Markdown heading tree), direct assertions of each rule, and a seeded property test. Over 500 random documents with random bounds, no passage's estimate exceeds the budget or the limit, no passage exceeds `maxChars`, and `recursive` loses no text. A `whole` property test runs 200 more. - `contract-stubs.test.ts`: the contract suite against two stubs. One declares no capability and is pinned to receive whole documents, never `chunks`. The other declares `chunks` and stores passages as given. - `testing.ts`: the suite gains the chunk-channel cases. With chunks, the adapter receives exactly `splitDocument`'s passages and a hit is one of them by id and text; `whole` over the budget is removed and reported; caller chunks are refused. Without chunks, whole documents arrive. `knowledge-memory` runs it with `chunks: true`. - `chunk-channel.test.ts`: the event path at `error`; `indexDocument` over the budget; the bounded `failures`; the `maxChars` precedence; the descriptor read at use; and end to end, `chunk_target` saved after boot cuts the next write through the real settings service. - `openai-embedder.test.ts`: the reported limit. `knowledge.manifest.test.ts`: `version` 2 and `chunk_overlap` absent. - `packages/spec/src/ai/knowledge-document.test.ts`: the retired `KnowledgeChunk.metadata` is refused at parse with the prescription (also inside `KnowledgeDocument.chunks`), a chunk without it parses clean, and authoring it is a `@ts-expect-error`. The local readings sit in the os-dev report comment on this PR. ## Acceptance notes - **`KnowledgeChunk.metadata` is retired here** (seat direction 7158283273, option B; registered under protocol major 18 by the seat's ruling A). The claim was re-issued as `Metadata-protocol: narrowed` (7158315677). - **No refinement for `minChars` ≤ `maxChars`.** The published JSON Schema cannot carry it, and the baseline that declares a dropped refinement is outside this claim. A `minChars` above the effective `maxChars` reads as `maxChars`, documented on the key. - **A table that does not fit** is cut between rows, each piece repeating the header. A list item that does not fit is cut as a paragraph. The budget is the hard bound. - **Re-splitting.** `docHash` does not cover passages, so a changed `split`, `chunk_target` or limit re-splits a document only when the document itself changes. The index fingerprint (ADR-0161 K7; objectstack-ai#37100) rebuilds a source on a split change. The docs say so. - **Merged with objectstack-ai#37256** (the organization filter) through `scripts/pm/os-regen-merge.sh`, keeping both sides: - `organizationId` next to `chunks`; - the organization filter before ranking, over the service's passages; - `implements: { listDocuments, chunks, organizationIds }`; - `resolveTenancyPosture` next to `resolveChunkTarget`. - **objectstack-ai#37265 still shares files**, a declared serial constraint: whichever lands second merges main. - Two test pins outside the claim's literal file list moved with the ordered retirement, both deliberate tripwires on the manifest: `settings-visibility-declaration.pin.test.ts` (90 to 87 predicates) and `knowledge.manifest.test.ts`. ## Verification Read first: `packages/services/service-knowledge/src/split/splitter.ts` (the sentence rule, the block-aware merge, the even character cut); `knowledge-service.ts` `prepareDocuments` / `writeSynced` and the walk's failure branch; `packages/spec/src/contracts/knowledge-adapter.ts`. Two-minute check: `pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/split.test.ts`. Expect 25 passed, then open `src/__tests__/fixtures/split/regulation-zh.tight.golden.json` and see each 章 title leading its own chapter. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYoHKp8EUQtketT9S29)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
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