Skip to content

service-knowledge: documents carry their organization, and search hands the caller's organizations to the adapter #37097

Description

@os-bob

maintainer · os-bob · session_012dn2AecKpLaYkUtNRiqtby

Filing gate: ③ maintainer-directed (topic child). Source: topic #37000 (phase 2 row 8, its organization filter); maintainer 2026-11-24 「用fable评审,并分拆第二阶段的任务」. Reviewed by an independent Fable pass before filing.
Grading: area:ai · Feature · p2 (topic) · reach: multi-organization deployments that mount service-knowledge · evidence: read.

维护者速读

  • 做什么:索引里的每份文档记下它属于哪个组织;检索时把提问人能看到的组织传给存储,存储先按组织过滤再排序。
  • 为什么:现在多组织数据只靠检索后按提问人权限回查来挡;存储层先过滤,排名前几的结果才不会被别的组织的文档占掉,也是一层纵深防护。
  • 需要你做的:无。

What

  1. KnowledgeDocument.organizationId? (knowledge-document.zod.ts), set by the service when it assembles a record document (the record's organization; absent for file / http sources and for single-organization posture).
  2. AdapterSearchOptions.organizationIds?: string[] (shape per ADR: knowledge platform boundary — the platform owns document assembly, sync and reconcile, structural split and record-level return; knowledge_source becomes a governed type #37001), computed by the service from the deployment posture: isolated → the caller's organization; group → the caller's accessible organizations; single and system identity → not passed.
  3. knowledge-memory reads both (filters before ranking) — the first reader; pgvector reads them in knowledge-pgvector: an open vector store on PostgreSQL — tables, exact search, listing, chunks #37100.
  4. The row-level permission re-read after search stays as it is (it remains the access decision).

Acceptance

  • Two organizations in one store: a search from organization A never ranks B's documents (memory adapter test and service test), under isolated and group.
  • single posture and system identity: no filter, today's results.
  • Container run per AGENTS.md.

Out of scope

Blocked-by: #37001 (contract members), #36991 (same document assembly path).
Parent: #37000. Reader: domain:server lane (spec edits per spec.md).
Dedupe: organization knowledge adapter 52 (open 7: #36991 says organization ids are out of its scope; the rest unrelated or seat posts).

Activity

  1. added theissue type on Nov 24, 2026
  2. added
    priority:p2
    area:ai
    on Nov 24, 2026
  3. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    Triage: first touch 2026-11-24T20:33Z

  4. added
    domain:server
    pm:blocked
    on Nov 24, 2026
  5. added
    pm:queue
    and removed
    pm:blocked
    on Nov 24, 2026
  6. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL
    Claim: PM loop round 1
    Session: session_01QSeKYpRrYuqSLCvbSk9zrL
    Account: os-justin
    Branch: claude/issue-37097-knowledge-org-filter
    Worktree: objectstack-issue-37097
    Domain: domain:server
    Seat: repo:objectstack#4
    Area: a4-K
    File surface: packages/spec/src/ai/knowledge-document.zod.ts, packages/spec/src/contracts/knowledge-adapter.ts and the spec artifacts they regenerate, packages/services/service-knowledge/**, packages/plugins/knowledge-memory/**, content/docs/protocol/knowledge.mdx, .changeset/* (stop on breach; explain in the report)
    Container & model: M, mode:cloud, model: default (dispatch-gates --repo objectstack-ai/objectstack --tier: "no path-derived mandate"; Clause-② review owed at CONTRACT_REVIEW_TIER by surface), effort: high
    Clause-②: yes
    Metadata-protocol: added
    Responsibility: n/a — not a defect card
    Thread-read: 7147527090
    Premise: holds — on origin/main d7f299c neither KnowledgeDocument.organizationId nor AdapterSearchOptions.organizationIds exists, and knowledge-memory ranks across every document in the store.
    Serial constraints cleared: #37096 merged (PR #37164); #37094 (claimed in the same round) touches the knowledge plugin's mount path, not search or assembly; overlap-check before every push.
    Pre-claim lane: domain:server; the two spec files are contract surface, reviewed per contract-review.md.
    Pre-claim deps: Blocked-by: #37001, #36991, both closed.
    Prior rulings read: ADR-0161 K8 row 9 (accepted: the service sets organizationId at assembly; organizationIds comes from the deployment posture; the adapter filters before it ranks; the permission re-read stays the access decision; knowledge-memory is the first reader). Tenancy posture per ADR-0105 D1 (packages/spec/src/security/tenancy-posture.ts).
    State: pm:queue → pm:dispatched in this stroke.

  7. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 25, 2026
  8. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

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

    {
      "issue": 37097,
      "status": "done",
      "branch": "claude/issue-37097-knowledge-org-filter",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/37256",
      "pr_number": 37256,
      "head_sha": "3df745d2a1328770687e0f93ecc5e7b5f29ca946",
      "session": "session_01QSeKYkS1d2QkEUgqhneuU1",
      "premise_still_valid": true,
      "summary": "Implements ADR-0161 K8 item 9. KnowledgeDocument.organizationId? is set by the service at assembly from the record's organization_id under group/isolated, and is absent under single, for file/http sources and for a record with no organization. AdapterSearchOptions.organizationIds? is computed per object source from the caller's execution context and the effective posture: classifyAdmissionTenancyPosture over the kernel tenancy service, plus computeTenantLayer0Verdict from @objectstack/core, so nothing is re-derived. It is absent for single, system identity, file/http and objects outside the wall; [] means deny. knowledge-memory filters before ranking. The permission re-read is unchanged. docHash covers organizationId only when it is set (v1 stays byte-identical for documents without one), so a complete reindex rewrites pre-change documents behind a wall. indexDocument refuses a caller-supplied organizationId, and search_knowledge refuses an organizationIds argument. runKnowledgeAdapterContract gains implements.organizationIds plus adapter-only and through-service cases (isolated, group, single, system, the upgrade case).",
      "tests": "Final head 3df745d2 (origin/main d62f9e9c merged): knowledge-memory vitest Test Files 2 passed, Tests 29 passed; service-knowledge vitest Test Files 8 passed, Tests 192 passed; typecheck for both packages exit 0 (test-typecheck 0 debt); spec build + check:generated 'All 14 generated artifacts are up to date'. Ablations via scripts/ablation-replace.mjs, source-aliased suites so no dist leg; each mutation proven on disk (anchor 1->0, blob moved) and restored to the HEAD blob with git diff HEAD empty: (1) memory filter disabled -> 6 contract cases red; (2) organizationId dropped from the hashed body -> 2 red (contract upgrade case and service hash pin); (3) the service stops passing organizationIds -> 4 contract and 5 service cases red.",
      "gates": "Local: dispatch-gates --commands derived 117 families at a8d89158, run with exit codes captured before any pipe: 113 exit 0; check:system-context-census exit 1, a real finding (two new system-identity elevation reads with no row on content/docs/permissions/system-context.mdx, a page outside the file surface), fixed at 44494ec2 by moving the organization scoping under admitSources' existing bypass (row 46), after which the census reads OK; 3 exit 3 PREREQUISITE NOT MET (check-plugin-teardown-shape --self-test needs a deeper clone, with the same exit 3 on base d7f299c0; check:skill-examples needs @objectstack/client-react built; check:dual-build-cjs-loads needs every dist). 16 gates re-run at 44494ec2, 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). dispatch-gates --ran: 117 derived, 114 run, 3 NOT-MEASURED, 0 UNRUN. CI on PR #37256: in_progress at report time (not waited on, per os-dev).",
      "line_budget": "15 files, +803 / -44 vs origin/main (three-dot), under the 3000-line threshold",
      "files_changed": [
        ".changeset/37097-knowledge-organization-filter.md",
        "content/docs/protocol/knowledge.mdx",
        "content/docs/references/ai/knowledge-document.mdx",
        "packages/plugins/knowledge-memory/src/__tests__/contract.test.ts",
        "packages/plugins/knowledge-memory/src/index.ts",
        "packages/services/service-knowledge/src/__tests__/knowledge-service.test.ts",
        "packages/services/service-knowledge/src/__tests__/knowledge-tools.test.ts",
        "packages/services/service-knowledge/src/knowledge-organization-scope.ts",
        "packages/services/service-knowledge/src/knowledge-service-plugin.ts",
        "packages/services/service-knowledge/src/knowledge-service.ts",
        "packages/services/service-knowledge/src/knowledge-source-admission.ts",
        "packages/services/service-knowledge/src/testing.ts",
        "packages/spec/authorable-surface/ai.json",
        "packages/spec/src/ai/knowledge-document.zod.ts",
        "packages/spec/src/contracts/knowledge-adapter.ts"
      ],
      "deviations": [
        "content/docs/references/ai/knowledge-document.mdx and packages/spec/authorable-surface/ai.json are spec-regenerated artifacts (check:generated --fix for the first; the spec build for the second), as the file surface allows.",
        "knowledge-service-plugin.ts: one added option (resolveTenancyPosture) next to resolveSecurity in the KnowledgeService construction, plus one import. The mount path and EMBEDDER_SERVICE logic (#37094) are untouched; overlap-check was clean before every push.",
        "docHash covers organizationId when it is set. K8 item 2's table text says 'content, title, metadata'. Without this, a complete reindex would skip pre-change documents forever. Raised in the PR's acceptance notes and in open_questions.",
        "No scripts/adr-anchors entry was added for K8 item 9 (outside the file surface); the ADR id is in the code.",
        "The local gate union ran at a8d89158; after the census fix (44494ec2) and the main merge (3df745d2), the 16 gates reading the changed files were re-run, not all 117."
      ],
      "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
      "mcp_calls": "2 — mcp__github__issue_read (get, get_comments) on #37097; reads only, no write tool",
      "api_writes": "2 — fleet-write relay dispatch pr_create (POST /repos/objectstack-ai/objectstack/dispatches, run 45572555512, created PR #37256 with assignee os-justin); post-stamped report comment on #37097. git push is not a REST write.",
      "open_questions": [
        {
          "question": "ADR-0161 K8 item 2 lists the docHash recipe as 'content, title, metadata'. This PR adds organizationId to the hashed body only when it is set, so pre-change documents get rewritten by a complete reindex. Does the contract review accept that as within item 2, or does it want a dated note on ADR-0161?",
          "options": [
            "A: accept as is and add a dated note on ADR-0161 K8 items 2/9 in a docs-only PR",
            "B: keep the hash at content/title/metadata, bump DOC_HASH_VERSION to v2 instead (every document rewritten once), and accept that a later organization move with no content change is skipped by the reindex (the event sync still writes it)"
          ],
          "recommendation": "A, because only the documents that need rewriting change hash, documents with no organization keep byte-identical v1 hashes, and the hash keeps describing the assembled document"
        }
      ],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: none · noted, not filed — content/docs/permissions/system-context.mdx row 46 prose does not mention that the system bypass also skips the new organization filter; the row's keyed symbol (admitSources) already covers it, and the census is green"
      ]
    }
  9. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL

    Delivered · PR #37256 merged as f9fda2a4f8, through the merge queue. Tier S.

    pm:dispatched removed. Zone a4-K closes out this card.

  10. removed
    pm:dispatched
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aidomain:serverpriority:p2

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions