Skip to content

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
os-zhuang merged 3 commits into
mainfrom
claude/issue-37097-adr-0161-dochash-note
Nov 25, 2026
Merged

os-zhuang merged 3 commits into
mainfrom
claude/issue-37097-adr-0161-dochash-note

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ
Part of #37097

repo:objectstack#4 · os-justin · session_01QSeKYkXwZ3ECV8yacsjMJM

Clause-②: yes
Metadata-protocol: none

维护者速读

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 #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 #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 #37097, not a closing line: the card's implementation is PR #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, #37097, built by #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, #37097, is built by PR #37256, and this change to item 2 lands with it. The reasoning is contract review 7157191417 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, #37097): a dated note under the table of K8 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 #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 #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.

Local gates at dd1756a: 21 derived, 21 run, all exit 0

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:

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:

✅ 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).

Acceptance notes

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 feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #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

…ation of a document that has one (K8 items 2 and 9)

K8 rule 3 names a dated note as the form of a change to a decided shape.
The note under K8's table records that item 2's hash covers the document
as the service assembles it, which since item 9 includes organizationId
when the document has one; a document without one hashes as before, so
the version prefix is not bumped. It also carries the rule for a later
optional member and the sentence an adapter author needs: an adapter that
stores docHash stores organizationId from the same version on.

Claude-Session: https://claude.ai/code/session_01QSeKYkXwZ3ECV8yacsjMJM
Co-authored-by: Claude <noreply@anthropic.com>
… the later-member rule to what assembly sets

Three wording changes inside the dated note under K8's table: the
parenthesis listed everything assembly set on a document, its identity
aside; the rule for a later optional member is about a member that
assembly sets; and the note says "complete reindex", the words the spec
TSDoc on organizationId uses for the same walk.

Claude-Session: https://claude.ai/code/session_01QSeKYkXwZ3ECV8yacsjMJM
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Nov 25, 2026
@github-actions github-actions Bot added size/xs documentation Improvements or additions to documentation labels Nov 25, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYkXwZ3ECV8yacsjMJM
os-dev-report

{
  "issue": null,
  "status": "done",
  "branch": "claude/issue-37097-adr-0161-dochash-note",
  "pr": "https://github.com/objectstack-ai/objectstack/pull/37263",
  "pr_number": 37263,
  "head_sha": "dd1756af23aa77d637584512556706c9a902ace4",
  "session": "session_01QSeKYkXwZ3ECV8yacsjMJM",
  "premise_still_valid": true,
  "summary": "No-card order under card #37097 (zone a4-K, seat repo:objectstack#4). One docs-only change to ADR-0161: a dated note under the table of K8 on items 2 and 9, and one `Amended` pointer bullet at the end of the header list; one file, 9 lines added, none removed, no anchor entry, no changeset. The note records that the hash of item 2 covers the document as the service assembles it, which with item 9 includes `organizationId` when the document has one, with no version bump; it gives the reason, the rule for a later optional member, and the adapter sentence of review 7157191417 (S2). Draft PR #37263 opens with `Part of #37097`, says plainly that it must merge before PR #37256, and is Tier H: it waits for the maintainer, and this session approved, merged and enqueued nothing. Premise verified: on origin/main d62f9e9c `computeDocHash` covers content, title and metadata; on the branch of PR #37256 at 3df745d2 (the head the review read) and at e8b0688f (its head now) `organizationId` enters the hashed body only when defined and `DOC_HASH_VERSION` stays `v1`.",
  "note_text": {
    "header_bullet": "- **Amended** (2026-11-25, [#37097](https://github.com/objectstack-ai/objectstack/issues/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.",
    "note_under_k8_table": "> **Note (2026-11-25, [#37097](https://github.com/objectstack-ai/objectstack/issues/37097), built by [#37256](https://github.com/objectstack-ai/objectstack/pull/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.\n>\n> - **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).\n> - **A later optional member that assembly sets** enters the hash the same way, left out when it is absent, or the version is bumped.\n> - **An adapter that stores `docHash` stores `organizationId` from the same version of the adapter on.** Otherwise, once it starts to read item 9, a complete reindex skips its documents, because the hashes match, and a search filtered by organization never ranks them.\n>\n> Item 9's first reader, #37097, is built by PR #37256, and this change to item 2 lands with it. The reasoning is contract review [`7157191417`](https://github.com/objectstack-ai/objectstack/pull/37256#issuecomment-7157191417) on that PR (its M1 and S2). The table is left as written; read items 2 and 9 with this note."
  },
  "tests": "No test: the diff is one Markdown file. No package is touched, so there is no dependency closure to build, no package test or typecheck owed, and no ablation (docs are not ablated). The gate union was run after the last commit, at dd1756af: 21 of 21 exit 0 (see gates).",
  "gates": {
    "local_head": "dd1756af",
    "derived": "node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack — 21 commands from 1 path against merge base d62f9e9c; each run with output redirected to a file and the exit code read before any pipe",
    "runs_at_dd1756af": [
      "node scripts/check-adr-links.mjs → exit 0",
      "node scripts/check-adr-links.mjs --self-test → exit 0",
      "node scripts/check-closing-keyword-parity.mjs → exit 0",
      "node scripts/check-closing-keyword-parity.mjs --self-test → exit 0",
      "node scripts/check-comment-mask-corpus.mjs → exit 0",
      "node scripts/ci/plan-test-core-shards.mjs --self-test → exit 0",
      "pnpm --filter @objectstack/lint run check:doc-formula-expressions → exit 0",
      "pnpm check:adr-anchors → exit 0",
      "pnpm check:adr-index → exit 0",
      "pnpm check:adr-symbol-anchors → exit 0",
      "pnpm check:ci-filter-parity → exit 0",
      "pnpm check:closed-ceremony-text → exit 0",
      "pnpm check:cross-package-test-inputs → exit 0",
      "pnpm check:doc-authoring → exit 0",
      "pnpm check:driver-memory-census → exit 0",
      "pnpm check:gitlink-declared → exit 0",
      "pnpm check:nul-bytes → exit 0",
      "pnpm check:pm-governed-merges → exit 0",
      "pnpm check:pm-prior-rulings → exit 0",
      "pnpm check:refd-timer-probe → exit 0",
      "pnpm check:watch-hint-literal → exit 0"
    ],
    "ran_reconciliation": "node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran (exit codes recorded) at dd1756af, exit 0: \"Run reconciliation — 21 derived, 21 run, 0 NOT-MEASURED, 0 UNRUN.\"",
    "first_run_at_15616e2f": "20 exit 0; `pnpm --filter @objectstack/lint run check:doc-formula-expressions` exit 3, PREREQUISITE NOT MET (it imports the compiled output of @objectstack/formula and @objectstack/lint, not built in a fresh worktree). Built both under the verify lock (`VERDICT command-exit 0`, held 99s, waited 0s); re-run exit 0 at 15616e2f and at dd1756af.",
    "adr_anchor_gate": "pnpm check:adr-anchors exit 0 with no new scripts/adr-anchors entry, so the gate does not require one for the note.",
    "overlap_check": "node scripts/pm/overlap-check.mjs --branch=claude/issue-37097-adr-0161-dochash-note before each of the 3 pushes: exit 0, \"VERDICT clean exit 0\" (at dd1756af: 1 changed file, against origin/main d62f9e9c and 0 PR heads).",
    "ci_check_runs_at_dd1756af": "One read right after the PR opened, not waited for: 45 check-runs — 5 success (filter; Governed Surface Queue Guard; Check PR Size; Check Changeset; Check Documentation Links), 17 in_progress (among them Lint · repo & tooling gates, Lint · docs & code guards, Lint · PM dispatch-gates, Lint · ESLint, Type Check · workspace, Type Check · source gates, Type Check · consumer gates, Type Check · debt ledger, Test UI, Dogfood Regression Gate, Plan Test Core shards, PR-body guards), 23 skipped (opt-in, UI and queue-only jobs). in_progress is the honest value; CI convergence is the seat’s to read."
  },
  "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
  "pr_state_read_back": "PR #37263: open, draft, base main, head dd1756af23aa77d637584512556706c9a902ace4, 1 file, +9 −0, labels size/xs and skip-changeset, assignee os-justin, auto-merge not armed. Body: 11264 bytes sent, 11264 stored, identical.",
  "mcp_calls": "0 — no MCP GitHub call, read or write. GitHub reads went through `gh api` GETs (comments 7157191417, 7157210840 and 7155140070; pulls 37240, 37256 and 37263; the pulls list filtered by this head; check-runs at dd1756af). The copy of this report sent to session_01QSeKYpRrYuqSLCvbSk9zrL goes by the session tool `send_message`, which is not a GitHub call.",
  "api_writes": "2 relay strokes, both as objectstack-fleet[bot]. (1) scripts/pm/fleet-write/dispatch.mjs `pr_create` (draft, assignees [os-justin], labels [skip-changeset]) → PR #37263, run 45582061807, conclusion success; endpoints on the runner: POST /repos/objectstack-ai/objectstack/pulls, POST /repos/objectstack-ai/objectstack/issues/37263/assignees, POST /repos/objectstack-ai/objectstack/issues/37263/labels. (2) scripts/pm/post-stamped.mjs --comment=37263, this report: POST /repos/objectstack-ai/objectstack/issues/37263/comments. Not REST writes: 3 git pushes to the branch (the empty-branch probe, 15616e2f, dd1756af). No write to card #37097: no claim, no assignee, no label.",
  "deviations": [
    "Order point 6 says the item 9 reader \"landed\" in PR #37256. This note merges first, so it says the reader \"is built by PR #37256, and this change to item 2 lands with it\", true before and after that merge.",
    "\"The whole assembled document\" is written as \"everything assembly set on a document, its identity aside\": on origin/main d62f9e9c `recordToDocument` also sets `id`, `sourceId` and `sourceRecordId`, which the hash never covered.",
    "The rule for a later optional member is scoped to a member \"that assembly sets\", so it is 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 the fingerprint of K7).",
    "\"From the same version on\" is written as \"from the same version of the adapter on\", because the note also speaks of the version prefix of the hash; \"a walled search\" is written as \"a search filtered by organization\", because the record uses the word \"wall\" nowhere.",
    "Added beyond the order’s six points: one `Amended` bullet at the end of the header list (the form of ADR-0151, whose header has the same shape; the Status line is byte-identical, so the generated docs/adr/README.md is unchanged), and one sentence in the note citing contract review 7157191417 (its M1 and S2).",
    "PR body: the seat signature is a plain line under the first line, the shape PR #37256 uses; no HTML comment anywhere in the body.",
    "Second commit dd1756af after the first gate run: three wording changes inside the note. The whole derived union was run again at dd1756af before the PR was opened.",
    "`test:repo` was not run locally: the diff touches no test of that project and the derivation does not name it; CI’s Test Core owns it.",
    "`pnpm install` and a build of @objectstack/formula and @objectstack/lint ran in the worktree only to measure one derived gate; nothing they produce is tracked or committed."
  ],
  "open_questions": [],
  "security_findings": "none",
  "out_of_scope_findings": [
    "carrier: seat repo:objectstack#4 (contract review 7157191417, N4) · no scripts/adr-anchors entry for K8 item 9 in code; the ADR-anchor gate asks for none for this note, and the file surface of this order excludes one unless the gate requires it · noted, not filed"
  ]
}

… TSDoc carries

The sentence on what an adapter stores now reads word for word as the
TSDoc on KnowledgeDocument.organizationId does on the branch that builds
item 9, so the record and the contract say one sentence, not two. The
bullet opens with a plain label and the sentence follows it unbroken.

Claude-Session: https://claude.ai/code/session_01QSeKYkXwZ3ECV8yacsjMJM
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYkXwZ3ECV8yacsjMJM
os-dev-report

{
  "issue": null,
  "status": "done",
  "round": "2 — a patch round on the same order, after three messages from the zone session session_01QSeKYpRrYuqSLCvbSk9zrL that were read only after the first report",
  "branch": "claude/issue-37097-adr-0161-dochash-note",
  "pr": "https://github.com/objectstack-ai/objectstack/pull/37263",
  "pr_number": 37263,
  "head_sha": "aec560807bc964835469e5062b5baa3dfe775a02",
  "previous_head_sha": "dd1756af23aa77d637584512556706c9a902ace4",
  "session": "session_01QSeKYkXwZ3ECV8yacsjMJM",
  "premise_still_valid": true,
  "summary": "One sentence of the dated note changed; nothing else did. The adapter sentence under the table of K8 now reads word for word as the TSDoc on `KnowledgeDocument.organizationId` reads on the branch of PR #37256 at its head 6e978db3, as the zone asked in its last message. The diff against main is still one file, 9 lines added, none removed. The PR stays a draft and Tier H; this session approved, merged and enqueued nothing. The PR body was written once at `pr_create` and is now stale in the places listed under seat_action; this session does not rewrite it.",
  "zone_messages": [
    "Message 1 (a line-initial `Rule-change:` line in the PR body, per the PR template under .github): NOT done. `.github/PULL_REQUEST_TEMPLATE.md` says the line is added \"Only when this pull request changes a file under `.claude/`\" and that \"Every other pull request leaves it out\"; os-dev.md says the same (a diff that touches the root `.claude/` tree). This PR changes one file under docs/adr/. Where a dispatch word and os-dev.md differ, os-dev.md holds and the difference is named here. A dev also writes a PR body only at `pr_create`.",
    "Message 2 (the adapter sentence in the words of the TSDoc at e8b0688f, the longer sentence): superseded by message 3 before it was read; not applied.",
    "Message 3 (the adapter sentence in the words of the TSDoc at 6e978db3, called final): applied in commit aec56080. Verified first: PR #37256 is at head 6e978db363c73dc9d151549ef46d6c141bc679ac, and the TSDoc sentence there, with its comment line breaks joined, is contained in the note exactly once, byte for byte. The hash recipe is unchanged at that head (`organizationId` enters the hashed body only when defined; `DOC_HASH_VERSION` stays `v1`). One difference from what the message says: its sentence is not the order’s first wording word for word (the order said \"once it starts reading item 9\" and \"(the hashes match)\"; the TSDoc says \"once it starts reading this field\" and has no parenthesis). The note follows the TSDoc, which is the stated aim."
  ],
  "note_text": {
    "header_bullet": "- **Amended** (2026-11-25, [#37097](https://github.com/objectstack-ai/objectstack/issues/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.",
    "note_under_k8_table": "> **Note (2026-11-25, [#37097](https://github.com/objectstack-ai/objectstack/issues/37097), built by [#37256](https://github.com/objectstack-ai/objectstack/pull/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.\n>\n> - **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).\n> - **A later optional member that assembly sets** enters the hash the same way, left out when it is absent, or the version is bumped.\n> - **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.\n>\n> Item 9's first reader, #37097, is built by PR #37256, and this change to item 2 lands with it. The reasoning is contract review [`7157191417`](https://github.com/objectstack-ai/objectstack/pull/37256#issuecomment-7157191417) on that PR (its M1 and S2). The table is left as written; read items 2 and 9 with this note.",
    "changed_bullet": "> - **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."
  },
  "tests": "No test: the diff is one Markdown file. The gate union was run again after the last commit, at aec56080: 21 of 21 exit 0.",
  "gates": {
    "local_head": "aec56080",
    "derived": "node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack — the same 21 commands as in round 1 (1 path against merge base d62f9e9c; origin/main has since moved to 9171bed0a6 and touches none of this file, scripts/adr-anchors or docs/adr/README.md)",
    "runs_at_aec56080": [
      "node scripts/check-adr-links.mjs → exit 0",
      "node scripts/check-adr-links.mjs --self-test → exit 0",
      "node scripts/check-closing-keyword-parity.mjs → exit 0",
      "node scripts/check-closing-keyword-parity.mjs --self-test → exit 0",
      "node scripts/check-comment-mask-corpus.mjs → exit 0",
      "node scripts/ci/plan-test-core-shards.mjs --self-test → exit 0",
      "pnpm --filter @objectstack/lint run check:doc-formula-expressions → exit 0",
      "pnpm check:adr-anchors → exit 0",
      "pnpm check:adr-index → exit 0",
      "pnpm check:adr-symbol-anchors → exit 0",
      "pnpm check:ci-filter-parity → exit 0",
      "pnpm check:closed-ceremony-text → exit 0",
      "pnpm check:cross-package-test-inputs → exit 0",
      "pnpm check:doc-authoring → exit 0",
      "pnpm check:driver-memory-census → exit 0",
      "pnpm check:gitlink-declared → exit 0",
      "pnpm check:nul-bytes → exit 0",
      "pnpm check:pm-governed-merges → exit 0",
      "pnpm check:pm-prior-rulings → exit 0",
      "pnpm check:refd-timer-probe → exit 0",
      "pnpm check:watch-hint-literal → exit 0"
    ],
    "ran_reconciliation": "node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran (exit codes recorded) at aec56080, exit 0: \"Run reconciliation — 21 derived, 21 run, 0 NOT-MEASURED, 0 UNRUN.\"",
    "prerequisite_build": "the worktree was recreated for this round; @objectstack/formula and @objectstack/lint were built under the verify lock before the run (`VERDICT command-exit 0`, 5 of 5 tasks from cache), so `check:doc-formula-expressions` was measured: exit 0.",
    "overlap_check": "node scripts/pm/overlap-check.mjs --branch=claude/issue-37097-adr-0161-dochash-note before the push of aec56080, against origin/main d62f9e9c and again against origin/main 9171bed0a6: exit 0 both times, \"VERDICT clean exit 0\", 0 PR heads.",
    "ci_check_runs_at_aec56080": "One read after the local run, not waited for: 43 check-runs — 23 success (Lint & Repo Gates; TypeScript Type Check; Test UI; Dogfood Regression Gate; Governed Surface Queue Guard; PR-body guards; Check Documentation Links; Check PR Size; Plan Test Core shards; Auto Label; filter; the Lint and Type Check lanes), 1 in_progress (Test Core 1/10), 19 skipped, 0 failed.",
    "ci_check_runs_at_dd1756af": "The previous head, read at the same time: 25 success (Test Core, Lint & Repo Gates, TypeScript Type Check, Dogfood Regression Gate, Check Changeset and PR-body guards among them), 1 cancelled (the Test Core 1/10 shard, cancelled by the new push), 23 skipped, 0 failed."
  },
  "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
  "pr_state_read_back": "PR #37263: open, draft, base main, head aec560807bc964835469e5062b5baa3dfe775a02, 1 file, +9 −0, labels documentation, size/xs and skip-changeset, assignee os-justin, auto-merge not armed. Body unchanged since `pr_create` (11264 bytes).",
  "seat_action": [
    "The PR body is the seat’s to bring to the new head (a dev writes it once, at `pr_create`). Stale at aec56080: (1) under What changes, the third bullet of the quoted note, which is now the text in note_text.changed_bullet; (2) in the table under it, the last two rows cite e8b0688f, and the branch of PR #37256 is now at 6e978db3 with the TSDoc sentence equal to the note’s; (3) under Tests, the final head is aec56080 and there were four pushes; (4) under Acceptance notes, the two wording bullets on \"from the same version of the adapter on\" and \"a search filtered by organization\" no longer hold and go; (5) under Verification, Read first item 1 quotes the old sentence.",
    "No `Rule-change:` line was added (zone message 1); if the seat still wants one on a docs/adr PR, that is a body edit of the seat’s and a reading the template does not give."
  ],
  "mcp_calls": "0 — no MCP GitHub call, read or write, in either round. GitHub reads went through `gh api` GETs. The notifications were read with the session tool, and the copies of the reports went by the session tool `send_message`; neither is a GitHub call.",
  "api_writes": "3 relay strokes in all, each as objectstack-fleet[bot]. Round 1: (1) `pr_create` → PR #37263 (POST /repos/objectstack-ai/objectstack/pulls, POST .../issues/37263/assignees, POST .../issues/37263/labels); (2) post-stamped report comment 7157915424 (POST .../issues/37263/comments). Round 2: (3) post-stamped --comment=37263, this report (POST .../issues/37263/comments). Not REST writes: 4 git pushes to the branch (the empty-branch probe, 15616e2f, dd1756af, aec56080), none forced. No PATCH of the PR body. No write to card #37097.",
  "deviations": [
    "Round 1 deviation 4 is withdrawn by this round: the note no longer says \"of the adapter\" or \"a search filtered by organization\". The other round 1 deviations stand (the reader \"is built by\" PR #37256; \"everything assembly set on a document, its identity aside\"; the later-member rule scoped to what assembly sets; the header bullet; the citation of review 7157191417).",
    "The changed bullet opens with a plain label, \"What an adapter stores.\", so that the sentence after it is unbroken by markup and matches the TSDoc as one string.",
    "Reading notes on the adopted sentence, for the approver, not a request: \"the same version\" stands one bullet below \"or the version is bumped\", so it can be read as the adapter’s version or as the hash’s; both readings give the same rule, that an adapter which stores the hash stores the organization. \"Walled\" and \"this field\" are the TSDoc’s words: the record does not use \"wall\" elsewhere, and \"field\" elsewhere in it means a field of an object.",
    "The first report was sent before the three zone messages were read: they were queued while round 1 ran and the session read its notifications only after it had reported.",
    "`test:repo` was not run locally (as in round 1); CI’s Test Core owns it and one of its shards was still running at the read."
  ],
  "open_questions": [],
  "security_findings": "none",
  "out_of_scope_findings": [
    "carrier: seat repo:objectstack#4 (contract review 7157191417, N4) · no scripts/adr-anchors entry for K8 item 9 in code; the ADR-anchor gate asks for none for this note · noted, not filed"
  ]
}

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: aec560807bc964835469e5062b5baa3dfe775a02
Local-runs: none
Scope: docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md + none
Security-touching: yes

① Derived judgments

  • 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 (draft), Part of #37097, epic 专题:知识检索平台化(应用写一份知识源配置就有可用的检索:开源、托管、企业版都能用) #37000. One file, +9 −0 against main: one Amended bullet at the end of ADR-0161's header list, and one dated note between K8's table and "What "capabilities" became". Three commits (15616e2f, dd1756af, aec56080); the third replaced the adapter sentence only.
  • Owed tier by record-recognisers --template --paths: CONTRACT_REVIEW_TIER, rules face, hits = the one file. No other file is in the diff, so + none. The code the note describes is in PR feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256 and was read there at 6e978db363c73dc9d151549ef46d6c141bc679ac, not reviewed here.
  • K = 4 (merge-base d62f9e9c05a4, origin/main 7939732f3520). None of the four commits touches docs/adr/**, scripts/adr-anchors/** or scripts/adr-index.mjs. git merge-tree against origin/main is clean (tree 228fc6e8b0ee), and so is this head against feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256's head (tree 8ffb69713e46). GitHub reads mergeable_state: clean.
  • Check-runs at this head, read 2026-11-25T09:28Z: 25 success, 19 skipped, 0 failed, 0 running. pnpm check:adr-anchors and pnpm check:adr-index are steps of "Lint · repo & tooling gates", which is green; "Lint · docs & code guards", "Check Documentation Links", "Governed Surface Queue Guard", "PR-body guards" and "Test Core" are green. The cancelled Test Core shard belonged to the previous head dd1756af and was cancelled by this push.
  • Generated files: docs/adr/README.md is byte-identical between this head and origin/main. The index reads the line that starts **Status**:; that line is not in the diff, and ADR-0161's row still reads "Proposed — 2026-11-24 …". No drift.
  • The header bullet's link #k8--the-contract-additions-decided-item-by-item is the slug of the K8 heading and is already used twice elsewhere in the file.
  • check:adr-anchors is a presence check over the entries in scripts/adr-anchors/. No entry names ADR-0161 today and the diff adds none, so the note cannot break it; CI agrees.
  • Nothing was built or run locally. The first form of the recogniser call, --paths without --template, is refused by the script ("unrecognised argument"); the tier was read from --template --paths.

② Semver level

  • Nothing publishes: one Markdown file under docs/adr/, no package, no schema, no generated reference. skip-changeset is the right label (AGENTS.md: the label is for a diff that publishes nothing from any released package).
  • Metadata-protocol: none holds. Clause-②: yes is the careful reading for a note on the contract's governing record and costs nothing here.

③ Boundary flags

Each declared deviation, at this head:

  1. The adapter sentence. Withdrawn by the dev in round 2 (report 7158272523). The sentence now reads, after the label "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." That is character for character the sentence in the TSDoc of KnowledgeDocument.organizationId in packages/spec/src/ai/knowledge-document.zod.ts at feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256's head 6e978db3 (lines 60 to 63, rejoined). The pair is verbatim; neither side has to change. The earlier wording ("of the adapter", "a search filtered by organization") had the same meaning; see N1 and N2 for what the verbatim form costs.
  2. "everything assembly set on a document, its identity aside": verified. recordToDocument at 6e978db3 sets id, sourceId, sourceRecordId, content, title, metadata, then organizationId when there is one, then docHash. computeDocHash takes content, title, metadata, and organizationId only when it is defined. On origin/main the same function sets the same six keys and hashes the same three. The three identity keys never entered the hash. Accepted; it is more exact than "the whole assembled document".
  3. The later-member rule limited to "a member that assembly sets": accepted. KnowledgeDocument has optional keys assembly does not set (permissions today, chunks from item 5, which the splitter sets and K7's fingerprint covers). Without the limit the rule would claim those.
  4. The Amended header bullet: accepted. It has the shape of ADR-0151's four bullets (date, card link, "a dated note under … records that …", "The status line above is left as it is."). No generated-file drift and the anchor gates hold, as ① shows.
  5. "is built by PR feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256, and this change to item 2 lands with it": true before and after that merge, and it does not claim behaviour on main. Between the two merges main still hashes three parts, and the note's own last paragraph says where the change arrives. The sentences in the present tense ("the hash covers it then") state the decision, as the rest of K8 does for members not yet built. Residual: if feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256 changed the recipe before it merged, this note would need a second dated note.

Further flags of round 2: the label "What an adapter stores." is fine and keeps the sentence unbroken. The dev states that the PR body was written once and is stale at this head; that is the seat's to settle and is in the seat's L1, not in this record's scope. Open questions: none. The out-of-scope item (no scripts/adr-anchors entry for K8 item 9 in code) stays the follow-up it was in review 7157191417.

SQL push-down (Prime Directive 5): no code in the diff.

④ Design judgment

Against its first consumer, #37256 at 6e978db3:

  • "Item 9 adds organizationId to the assembled document when the document has one, and the hash covers it then": holds, by the conditional spread in computeDocHash.
  • "A document without one hashes byte for byte as it did before, so the version prefix is not bumped": holds. With organizationId undefined the hashed body is the three keys main hashes, and DOC_HASH_VERSION is v1 on both sides.
  • "gains an organization, loses it or moves to another one gets a new hash": holds for all three, since the key is present with its value or absent.
  • The manual path (indexDocument) hashes with the same function and refuses a caller's organizationId, so it stays on the old bytes. The note does not contradict it.

Against the record itself:

  • Item 2's row and the note agree once read together, as the note says; the table is not edited, which is the form rule 3 names.
  • K1's "Sync and reconcile" row reads "Events keep an index fresh; a reconcile pass keeps it correct". The note's "missed events are the hole reconcile exists to close (K1)" is a fair reading of it.
  • K7's recipe hash is a second hash over what assembly reads; the note speaks of the document hash only and does not touch it.
  • Rule 2 ("Every member is optional") and the adapter bullet: no contradiction, but a new rule. An adapter that takes up neither member, or organizationId alone, is as before. One that stores docHash is now told to store organizationId with it. The rule enters by a dated note, the form rules 3 and 5 give, and the approver should know he is accepting it.
  • Item 9's own row ("set by the service at assembly … The adapter filters by it before it ranks") is unchanged in meaning.
  • ADR-0151: nothing in common except the header format. It does not mention knowledge, docHash or this record. No other record under docs/adr/ mentions docHash.

A versus B, as the "Why" bullet states it: correct, and the same as review 7157191417. A: every change of organization changes the hash, so a complete reindex rewrites the document. B: the parenthesis is kept and the version bumped; the first reindex is right, and a later change of organization reaches the index by events only. The bullet says a reindex "never" leaves a stale organization; the one exception is the adapter the next-but-one bullet covers, so the note is complete as a whole.

  • N1 — "from the same version on" stands one bullet below "or the version is bumped", where "version" is the hash's prefix. Read either way the rule is the same: an adapter that stores the hash stores the organization. No change asked.
  • N2 — "a walled search" and "this field" are the TSDoc's words. This record uses "wall" nowhere else, and "field" elsewhere in it means a field of an object. Here they mean a search that is handed organizationIds, and organizationId. A reader of the record alone can work both out from item 9. No change asked; a change would have to be made on both sides to keep the pair verbatim.
  • N3 — "everything assembly set on a document, its identity aside": assembly also sets docHash itself, which no hash can cover. Not worth a word.

Implemented-by: claude/issue-37097-adr-0161-dochash-note
Reviewed-by: session_01QSeKYpEsWWE9Y5YtSsDgqZ

VERDICT: PASS

No must-fix, no should-fix.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

席位核对 — ACCEPT · L1 · head aec560807bc964835469e5062b5baa3dfe775a02 · 2026-11-25T09:30Z

  • What it 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 (draft, Part of #37097): the dated note on ADR-0161 K8, items 2 and 9, that contract review 7157191417 on PR feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256 asked for. One file under docs/adr/, +9 −0: one Amended header bullet and one note under K8's table. Dev reports 7157915424 (round 1, head dd1756af) and 7158272523 (round 2, this head).
  • Tier. docs/adr/** is Tier H. The seat approves, merges and enqueues nothing; it hands the PR to the maintainer. It must merge before PR feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256.
  • Head. The head moved during this check, from dd1756af to aec56080: one sentence of the note changed. Everything below was read at aec56080.
  • The note against the code. Read against feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256 at 6e978db363c73dc9d151549ef46d6c141bc679ac: the organization enters the hash only when the document has one, a document without one hashes as on main, and the version stays v1. id, sourceId and sourceRecordId are set at assembly and never hashed, so "its identity aside" is right.
  • The adapter sentence. Now character for character the sentence in the spec TSDoc of KnowledgeDocument.organizationId at 6e978db3. The round 1 deviation on this point is withdrawn; neither side has to change.
  • The other deviations. Accepted: the later-member rule limited to what assembly sets; the Amended bullet in ADR-0151's form; "is built by PR feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256, and this change to item 2 lands with it", which is true before and after that merge and claims nothing about main today.
  • Generated files and gates. docs/adr/README.md is identical to main (the **Status**: line is untouched). Check-runs at this head, read 2026-11-25T09:28Z: 25 success, 19 skipped, 0 failed, 0 running; check:adr-anchors and check:adr-index ran inside "Lint · repo & tooling gates", green. The cancelled Test Core shard was on the previous head.
  • Merge state. K = 4, none of the four commits near docs/adr/**. git merge-tree is clean against origin/main 7939732f3520 and against feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256's head. mergeable_state: clean.
  • Changeset. None, with skip-changeset: right, nothing publishes.
  • Consistency. No contradiction with the rest of ADR-0161 or with ADR-0151. The reasoning for the chosen answer over the version bump is stated as the review gave it.
  • One thing for the approver to weigh. K8 rule 2 keeps every member optional. The adapter bullet adds a rule on top: an adapter that stores docHash stores organizationId too. It is a new rule, entering in the form K8 gives for one.
  • Seat action before the hand-off (no new head). The PR body is stale at this head. It quotes the old adapter sentence under "The note, as it stands at the head" and under "Verification", lists two wording deviations that no longer exist, and names dd1756af as the final head for the local gates. The dev's round 2 report says so and leaves the rewrite to the seat. The 维护者速读 block is still accurate. The seat syncs those places and marks the PR ready for review, then hands off.
  • Open, none blocking. Three reading notes in the contract review (N1 to N3), no change asked. A scripts/adr-anchors entry for K8 item 9 stays a follow-up outside this PR.
  • Contract review. PASS at this head, CONTRACT_REVIEW_TIER, Local-runs: none, Security-touching: yes.

No must-fix, no should-fix.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

维护者速读

  • 用户能看到什么变化:用户无感。只在「知识检索平台边界」这份决定记录(ADR-0161)里加一条带日期的说明:文档带有所属组织时,文档指纹把组织也算进去;不带组织的文档,指纹和以前一字不差。
  • 为什么做:「知识检索平台化」专题第二阶段的实现改动 feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256(索引文档记下所属组织、检索先按组织过滤)改了指纹的算法。按这份记录自己的规矩,这类改动要先写成带日期的说明、由你批准,所以单独开了这一张。
  • 出错会怎样:说明写错的话,以后写存储适配器的人会照着错的做,最坏是换了组织的文档在重建索引时被跳过、按组织检索时排不出来。这次只有一个文档文件、9 行,撤回这次合并即可,不涉及数据和接口。
  • 要你做什么:审核并由你本人合并(合并即批准),而且必须排在 feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256 之前合并。请留意一点:说明里新增了一条给适配器作者的规矩——存了文档指纹的适配器,要同时存所属组织;记录原先只说每个成员都可选。契约审核 PASS:记录 7158429794,Head-sha aec560807bc964835469e5062b5baa3dfe775a02;席位核对 ACCEPT:7158440806。0 个失败检查。

席位意见:通过。说明逐句对照了 #37256 的代码,都对得上;给适配器作者的那句话与接口注释里的一字不差;索引页没有变动,检查全绿;与主干、与 #37256 合并都干净。剩 3 处读法上的小提示,不需要改。

Hand-off · 2026-11-25T09:33Z · @os-zhuang — PR #37263 (Part of #37097) is ready for your review. Tier H: docs/adr/**, a dated note on ADR-0161 K8, items 2 and 9, one file, +9 −0. Seat ACCEPT 7158440806 and contract review PASS 7158429794 (CONTRACT_REVIEW_TIER), Head-sha aec560807bc964835469e5062b5baa3dfe775a02; 0 failed check-runs. It must merge before PR #37256, which stays held until it has. Your merge is the approval; the seat does not land it.

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 25, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review November 25, 2026 09:34
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 8032d95 Nov 25, 2026
54 checks passed
@os-zhuang
os-zhuang deleted the claude/issue-37097-adr-0161-dochash-note branch November 25, 2026 09:55
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…ch hands the adapter the caller's organizations (objectstack-ai#37256)

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ
Fixes objectstack-ai#37097

repo:objectstack#4 · os-justin · session_01QSeKYkS1d2QkEUgqhneuU1

Clause-②: yes
Metadata-protocol: added
Skills-docs: none — no skill under `skills/**` teaches
`KnowledgeDocument`, `AdapterSearchOptions` or the adapter contract
suite; `skills/objectstack-ai/SKILL.md` teaches `KnowledgeSource`
authoring only. `content/docs/protocol/knowledge.mdx` gains the members
and an "Organization scope" section here.

## 维护者速读
- 多组织部署里,知识检索只在提问人所属组织的文档里排名,别的组织的文档不再挤占前几名;单组织部署无感。
- 属于「知识检索平台化」专题第二阶段:索引文档记下所属组织,检索时由平台按部署的租户形态算出提问人的组织交给存储先过滤。
-
出错时最坏是某些文档在检索里排不上(尚未重建索引的旧文档在多组织形态下要等一次完整重建);能否返回仍由按提问人身份回查记录决定,可直接撤回本改动。
- 无。

## What changes

ADR-0161 K8, item 9, with `knowledge-memory` as its first reader:

1. **`KnowledgeDocument.organizationId?`**
(`packages/spec/src/ai/knowledge-document.zod.ts`). The service sets it
when it assembles a document from a record: the record's
`organization_id` under the `group` and `isolated` postures. It is
absent under `single`, for `file` / `http` sources and for a record with
no organization. `indexDocument` refuses a caller-supplied value, as it
refuses a caller-supplied `docHash`. The TSDoc also says that an adapter
storing `docHash` stores `organizationId` from the same version on.
2. **`AdapterSearchOptions.organizationIds?`**
(`packages/spec/src/contracts/knowledge-adapter.ts`). The service
computes it per `object` source in `knowledge-organization-scope.ts` and
derives nothing itself:
- the posture is the effective one, `classifyAdmissionTenancyPosture`
over the kernel's `tenancy` service. `KnowledgeServicePlugin` wires it
as the new `resolveTenancyPosture` option, next to `resolveSecurity`;
the mount logic is untouched. The wiring is pinned through real kernels
(`LiteKernel` and `ObjectKernel`): walled, no `tenancy` service, and a
`tenancy` service that cannot be read;
- the organization set is `computeTenantLayer0Verdict`
(`@objectstack/core`) for the source's object, over the context's
`tenantId` / `accessible_org_ids`. `isolated` gives the active
organization and `group` the deduplicated membership set. A `deny`
verdict becomes `[]`; `none` (an object outside tenancy, or with no
`organization_id` column) gives no filter;
- no filter under `single`, for the system identity and for `file` /
`http` sources.

The TSDoc spells out the three cases: absent means no filter, a set
means filter before ranking, `[]` means rank nothing (never "no
filter").
3. **`knowledge-memory`** stores `organizationId` and filters by
`organizationIds` before it scores, so `topK` is filled from in-scope
documents only.
4. **The permission re-read is unchanged** and remains the access
decision. Nothing new is logged or returned about how many hits a filter
removed.
5. **`docHash`** covers `organizationId` only when the document has one.
`DOC_HASH_VERSION` stays `v1`, so a document without an organization
hashes byte-for-byte as before (pinned against the old recipe).
6. **A posture that cannot be read** (a `tenancy` service is registered
but unreadable): a search leaves every `object` source unsearched for
that call and logs at `error`; a reindex stops before writing and
returns `ok: false` with the reason. An event sync logs at `warn` with
the reason and leaves the stored document as it was (no upsert, no
delete; pinned).
7. **Contract suite** (`@objectstack/service-knowledge/testing`):
`implements.organizationIds` is required, which is fine because the
suite has not been released yet. It adds adapter-only cases and cases
through a real `KnowledgeService` under `isolated`, `group` and
`single`, plus the upgrade case for documents indexed before this
change.

### PM mechanism assumptions, measured
- **Computed server-side only.** `KnowledgeSearchOptions` has no
organization member, and the service builds `organizationIds` itself. A
caller's opaque `filter: { organizationIds: [...] }` stays inside
`filter` (pinned), and `search_knowledge`'s closed input set refuses an
`organizationIds` argument (pinned). The only callers are the MCP
bridges through `knowledgeTools()`; no REST route reaches `search`.
- **`[]` and absent are different.** `[]` filters to nothing in the
TSDoc, in `knowledge-memory` and in the suite. Under `isolated` with no
active organization, and under `group` with no membership, the adapter
is handed `[]` (pinned).
- **Documents indexed before this change** carry no `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. Under `single` nothing 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").
- **`runKnowledgeAdapterContract` was extended**, not a memory-only
test.

## Tests

<details><summary>Local runs on the final head 6e978db (origin/main
d62f9e9 merged; two commits since 3df745d add tests and a TSDoc
sentence)</summary>

- `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 the
`organizationId` row and the `docHash` description in
`content/docs/references/ai/knowledge-document.mdx`.
`authorable-surface/ai.json` gained
`ai/KnowledgeDocument:organizationId` from the spec build.
</details>

<details><summary>Derived gate families (dispatch-gates --commands,
117), with --ran reconciliation</summary>

- Run at a8d8915: 113 exit 0. `pnpm check:system-context-census` exited
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 under `admitSources`' 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).
- Re-run at 44494ec, all exit 0: system-context-census,
startup-registry-verdict, type-check-coverage, type-check-debt,
test-source-alias, cross-package-test-inputs, undeclared-dep-imports,
issue-citations, optional-error-sink, logger-receiver-detach, nul-bytes,
doc-authoring, engine-double-contract, tenant-chokepoint,
tenant-audit-census, org-identifier.
- NOT MEASURED (exit 3, prerequisite): `check-plugin-teardown-shape.mjs
--self-test` needs a deeper clone (the same exit 3 on the main base
d7f299c); `check:skill-examples` needs `@objectstack/client-react`
built; `check:dual-build-cjs-loads` needs every package's dist. These
are left to CI.
- `dispatch-gates --ran`: 117 derived, 114 run, 3 NOT-MEASURED, 0 UNRUN.
- After 3df745d only a test file and a TSDoc comment changed; the full
set ran in CI at 6e978db (60 success, 10 skipped, 0 failed).
</details>

<details><summary>Ablations (scripts/ablation-replace.mjs; each mutation
proven on disk and restored to the HEAD blob)</summary>

- Memory adapter filter disabled (`organizations` forced `undefined`): 6
contract cases red (the 3 adapter-only filter cases, both service cases
under isolated and group, and the upgrade case). Restored to blob
70dc64b.
- `organizationId` dropped from the hashed body: 2 red (the contract
upgrade case, and the service hash pin). Restored to fe7502a.
- The service stops handing `organizationIds` to the adapter: 4 contract
cases and 5 service cases red. Restored to fe7502a.
- The plugin's `resolveTenancyPosture` wiring replaced by `async () =>
undefined`: 3 service cases red (both walled kernel cases and the
unreadable case); the no-tenancy case stays green. Restored.
</details>

## Acceptance notes
- **K8 item 2's wording.** It lists the hashed parts as "content, title,
metadata". Here the hash also covers `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 exact `v1` hash. The contract review (7157191417, M1) asks
for a dated note on ADR-0161 to land first; that note is PR objectstack-ai#37263,
merged first as `8032d958f2`.
- The object facts handed to `computeTenantLayer0Verdict` come from the
engine's `getSchema`: `tenancy.enabled: false` or `systemFields.tenant:
false`, and whether an `organization_id` field exists. Unknown schema
means the object is treated as walled. External (federated) objects are
not special-cased, so `externalOrganizationScopeUndeclared` is `false`.
Platform-admin crossing is not applied to ranking (`isPlatformAdmin:
false`). The re-read still decides access either way.
- `recordToDocument` takes the posture as an optional fifth argument, so
existing calls behave as before.
- The system-context page's row 46 ("Knowledge search returns hits
unfiltered, and searches every source") still describes the system
bypass accurately: through `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.ts` should report 21 tests
passed, including "isolated: a search from organization A never ranks or
returns B's documents" and "group: …".

Read first:
1.
`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).
2. `packages/services/service-knowledge/src/knowledge-service.ts`:
`scopeByOrganization`, plus `computeDocHash` / `recordToDocument` (risk:
the hash change decides what a reindex rewrites).
3. `packages/plugins/knowledge-memory/src/index.ts`, `search` (risk:
filtering after scoring instead of before).

---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1)_

---------

Co-authored-by: Claude <noreply@anthropic.com>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…nds its adapter: record ids, or a parent object through a listed lookup (objectstack-ai#37329)

<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8GWXHtfAHuZXmmZpkARr4Wi)_

Fixes objectstack-ai#37324

Clause-②: yes
Metadata-protocol: none

## 维护者速读

-
用户能看到什么变化:用户无感;只在「知识检索平台边界」这份决定记录里加一条带日期的说明,定下「限定范围检索」的接口形状:可以只在指定的几条记录里搜,也可以借知识源列出的查找字段,只在一份上级记录(比如一份制度)下的条款里搜。
-
为什么做:属于「知识检索平台化」专题第三阶段,记下您刚裁的「也能指定上级对象(制度)」;记录规定适配器契约的新成员要先以带日期的说明写进记录,随后的按范围检索代码卡才能动工。
-
出错会怎样:说明写错,后面写检索服务和存储适配器的人会照错的做,最坏是限定范围后漏掉结果(权限仍逐条按提问人重读,不会越权);有两处是记录替您定的细节请过目:一类条款若有两个字段都指向同一类制度,按制度限定时这类条款不参与检索并记日志;人员字段不算「上级」;本次只有文档,撤回合并即可。
- 要你做什么:审后由你本人合并(受治理面,合并即批准),且要排在随后的按范围检索代码改动之前。

## 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`,
17 lines added and none removed against `main` (`829a45e9`). No schema,
no code, no changeset.

K8 item 17 of ADR-0161 ("A typed scope filter") reads "Deferred" with no
final shape, and K8 rule 3 says a shape that cannot be built as written
changes by "a dated note on this record". This PR is that note. It
records the maintainer's ruling on Q3, record
[`7168192820`](objectstack-ai#37308 (comment))
on objectstack-ai#37308: 「也能指定上级对象(制度)」. objectstack-ai#37308 builds the member after this note
merges; objectstack-ai#37311 (row 12) adds the `search_knowledge` arguments.

`docs/adr/**` is Tier H: the maintainer merges this PR; no seat
approves, merges or enqueues it.

Two additions, in the form PR objectstack-ai#37263 used for the objectstack-ai#37097 note:

1. **A second dated note under K8's table**, after the objectstack-ai#37097 note and
before "What "capabilities" became.". The table is left as written.
2. **A second `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.

What the note decides. Each ◆ is a shape the note decides past the
ruling's words, for the approver to accept with the record or strike:

- ◆ **The member** is `AdapterSearchOptions.scope?`, a list of terms: `{
kind: 'record', ids }` (the document's `sourceRecordId` in `ids`) or `{
kind: 'metadata', field, ids }` (the document's `metadata[field]` in
`ids`, or a list with an element in `ids`). The adapter gets resolved
terms, never `{ object, ids }`: turning an object into a field needs the
object's registered definition, which is the platform's (K1).
- ◆ **Absent, present, empty**, read as item 9's `organizationIds`:
absent ranks every document as before; present filters BEFORE ranking so
`topK` is filled from in-scope documents; an empty list ranks nothing
and is never "no filter". `organizationIds`, `scope` and the opaque
`filter` all apply.
- **How the service builds it** from `KnowledgeSearchOptions.scope`
(entries of `object` and `ids`), per source: the source's own object
gives a `record` term; another object gives a `metadata` term for the
`metadataFields` member that points at it; no such member, and the entry
does not reach the source. A source no entry reaches is not searched; a
`file` or `http` source answers nothing under a scope.
- ◆ **Four readings the ruling leaves open**: (1) several entries
reaching one source combine as a union; (2) an own-object entry is the
`record` term only; (3) only `lookup` and `master_detail` are parent
links, target read through `referenceTargetOf`; a `user` field is not
one; a withheld field is not one; (4) a source that lists two or more
lookups to the entry's object is not reached by it, logged once per
source naming the fields.
- **What a scope does not reach**: a parent two hops away. An entry that
reaches no searched source answers the same empty answer a withheld
source gives, so the answer never tells which it was.
- ◆ **The service's guarantee**: after the adapter answers, the service
drops every hit no term holds for, judging `KnowledgeHit.sourceRecordId`
and `KnowledgeHit.metadata[field]`, fail closed. No capability flag is
added (K8 rule 5); the service logs once per adapter the first time its
check drops a hit.
- ◆ **Judged on the index copy**, never an access decision: the
permission re-read of the live row stays the access decision. Source
admission already requires every `metadataFields` member an index
carries to be queryable by the caller, so "that field in ids" is a
filter the caller could run on the object's own rows; the parent row is
never read.
- ◆ **The opaque `filter` stays as it is**, handed through and checked
by nothing in the service; whether it retires is its own card.
- **The suite cases** the member lands with in
`runKnowledgeAdapterContract`, per term kind, and one through a real
`KnowledgeService` over an adapter that ignores the member.
- **Not here**: the bounds on `KnowledgeSearchOptions.scope` (objectstack-ai#37308,
coded refusal, ADR-0112), the tool argument (objectstack-ai#37311), record-level
return (objectstack-ai#37103).

**One shape differs from objectstack-ai#37324's body words.** That body says the
member on `AdapterSearchOptions` is `scope: [{ object, ids }]`. The note
keeps `[{ object, ids }]` on the service option only and hands the
adapter resolved terms, as objectstack-ai#37308's item 1 and K8 item 17 itself say
("built by the service from"). The member name is `scope` on both
interfaces, with distinct types.

## Tests

No test changes: the diff is one Markdown file. The derived gate
families were run at `8a64f99f`, the head.

<details><summary>Local gates at 8a64f99: 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 `829a45e9`). Each was run with its output
redirected to a file and its exit code read before any pipe.
`check:doc-formula-expressions` needs `@objectstack/formula` and
`@objectstack/lint` built: built first under the verify lock, `VERDICT
command-exit 0`.

| 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:

```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).
```

`check:adr-symbol-anchors` resolves the note's four `path#symbol`
citations. Outside the derived set and not run locally: the
governed-merges audit with workflow-only variables, CI's test-core shard
planning steps, and the type-check lanes (the diff touches no
TypeScript). CI carries them.

</details>

## Acceptance notes

- **Two ◆ readings worth the approver's eye**, each written as the
note's recommendation:
- Reading (4), two lookups to the same parent: the entry does not reach
the source, logged once. The other answers were a union of the fields
(answers "inside this policy" with clauses that only cite it through the
other field), the first field listed (gives list order a meaning no
author wrote), a key on the entry naming the field (no consumer yet), or
a refusal (would differ from the withheld-source answer). No source in
this tree lists a reference field in `metadataFields` today, so no
measured consumer decides it; empty-now can open later without removing
anyone's hits.
- Reading (3), the `user` field: excluded as a parent link. The visible
cost: `Field.lookup('sys_user')` is a link while `Field.user()` is not.
Nothing scopes by user today; it returns by a dated note with its
reader.
- **The opaque `filter`** has no producer in this tree (the one non-test
caller of `IKnowledgeService.search`, `createKnowledgeTools`, passes
none) and gets no service guarantee. The note leaves it unchanged;
whether to retire it is a question for its own card. Noted, not filed:
carrier none.
- **Left to objectstack-ai#37308's code PR**, not decided here: whether the refill
after the permission filter also counts hits the scope check removed;
whether an empty `KnowledgeSearchOptions.scope` or an entry with no ids
is answered empty or refused (the note fixes only that it never reads as
"no scope"); the bound numbers; log levels.
- **No changeset.** `docs/adr/**` publishes nothing; the PR carries
`skip-changeset`.
- **No `scripts/adr-anchors` entry.** `pnpm check:adr-anchors` exits 0
without one; the code PR anchors the member it lands.

## Verification

Read first:

1. The "Four readings the ruling's words leave open" bullet of the new
note, readings (3) and (4): the two places the note goes furthest past
the ruling.
2. The "The service's guarantee, whatever the adapter does" bullet: fail
closed on a hit without the document's metadata, and no capability flag.
3. The "The opaque `filter` stays as it is" bullet.

Two-minute check: open this PR's Files tab. It shows one file under
`docs/adr/`, +17 −0: one `Amended` bullet at the end of the header list,
and one blockquote between the objectstack-ai#37097 note and the paragraph that starts
"What "capabilities" became.".

---
_Generated by [Claude
Code](https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm)_

Co-authored-by: Claude <noreply@anthropic.com>
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 pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue size/xs skip-changeset PR has no user-facing published change; bypasses the changeset gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants