From 59931031314e09297be135debd63239602a4be61 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 17:00:10 +0000 Subject: [PATCH 1/7] docs(adr): ADR-0155 share-grant semi-join leaf for the sharing read scope (Proposed) A new decision record, Status Proposed. The sharing scope's share-grant arm lowers to one more engine-internal branded comparand over sys_record_share, compiled in the id list's own position, so every grant counts and the 5000-row cap is gone rather than raised. Three questions are put to the maintainer and are not decided by the text: the tenant scope of the subquery, what an evaluator that cannot run the leaf answers, and the leaf's write form on a predicate update. The record declares and implements nothing. docs/adr/README.md gains the record's row and the counts it implies, from `node scripts/adr-index.mjs`; no other row moved. Claude-Session: https://claude.ai/code/session_01ADHkmSrxgDeeJWnQpVfLcX Co-authored-by: Claude --- ...er-to-an-engine-internal-semi-join-leaf.md | 673 ++++++++++++++++++ docs/adr/README.md | 7 +- 2 files changed, 677 insertions(+), 3 deletions(-) create mode 100644 docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md diff --git a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md new file mode 100644 index 00000000000..fe0a08c7bce --- /dev/null +++ b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md @@ -0,0 +1,673 @@ +# ADR-0155: The sharing scope's share-grant arm lowers to an engine-internal semi-join leaf over the record-share table, not a capped id list; every grant counts + +**Status**: Proposed — 2026-11-15; questions ①–③ are open for the maintainer and are ⛔ not decided by this text: +① the tenant scope of the subquery, ② what an evaluator that cannot run the leaf answers, ③ the leaf on a predicate +update. Each is put under [Questions for the maintainer](#questions-for-the-maintainer) with its options, what each +option costs and a recommendation, and every sentence of the Decision that depends on one says so. `docs/adr/` is +Tier H (Prime Directive #14): the record lands on a `GOVERNED_APPROVERS` approval, and the execution cards under +[Execution plan](#execution-plan-after-acceptance) are cut after acceptance and ⛔ never before it. **This record +declares; it implements nothing.** +- **Date**: 2026-11-15 +- **Card**: [#33899](https://github.com/objectstack-ai/objectstack/issues/33899). It is the precondition of + [#33787](https://github.com/objectstack-ai/objectstack/issues/33787) (the defect), which is `Blocked-by` this card + and closes when the plugin-sharing switch lands. +- **Ruling it serves**: the maintainer's 「只做根治」 on #33787 (ruling record + [`6895275749`](https://github.com/objectstack-ai/objectstack/issues/33787#issuecomment-6895275749), 2026-11-15T13:47Z): + the root fix only, with no interim. The root fix is the semi-join shape. It has no compile path today, so its first + deliverable is this record. +- **Builds on**: [ADR-0139](./0139-engine-internal-semi-join-leaf-readable-parent-ids.md) (the engine-internal + semi-join leaf: its brand device, its position rules, its executor seam and its refusal envelope); + [ADR-0147](./0147-membership-scoped-rls-lowers-to-an-engine-internal-org-member-semi-join-leaf.md) (Proposed: the + first record to add a leaf under its own brand, with a fixed inner read under system authority and no tenant wall — + the pattern this record follows and the seam it shares, [D4](#d4--the-engine-seam-and-what-is-built-once-with-adr-0147)); + [ADR-0111](./0111-record-share-management-authority-and-verb-boundary.md) D3 (a share widens edit, never delete) + and D7 (no inert grants; only `user` recipients are enforced); + [ADR-0142](./0142-ownership-queue-membership-claim-and-assignment-rules.md) D3 (the queue arm); + [ADR-0131](./0131-total-organization-ownership-no-null-organization-id.md) D1 and D8 (NULL is not a state; the + driver's tenant scope is the wall's verdict); [ADR-0090](./0090-permission-model-v2-concept-convergence.md) D10 + (delegation); [ADR-0052](./0052-audit-is-not-the-activity-feed.md) §5 (the pointer pair); + [ADR-0112](./0112-error-code-vocabulary-and-ledger.md) (the refusal envelope); + [ADR-0049](./0049-no-unenforced-security-properties.md) (enforce-or-remove). +- **Revisits**: ADR-0139 D1's "⛔ No second leaf", for one more leaf and nothing else. This is the second record to do + so (ADR-0147 is the first), and the prohibition stays the default: a new leaf needs a Tier H record of its own. It + answers ADR-0139's open item O4, which names this read. Two further places move only if the maintainer rules that + way: ADR-0139 D1's read-verbs sentence (③) and, under one answer to ②, ADR-0139 D3's "⛔ No `DriverCapabilities` bit + returns" and ADR-0111 D7's list of inert grants. The dated pointer notes those records are owed are ⛔ not in this + record's diff ([O7](#open-items-not-blocking-acceptance-each-becomes-a-reading-on-its-card)). +- **Leaves unchanged**: every authorable surface (no operator, no CEL function, no object, permission-set or + sharing-rule key, and no stored predicate to migrate); `sys_record_share`'s columns; its write path (grant, revoke, + rule materialisation, the organization stamp), the by-id gates and share-management authority, which move only + under one answer to ② and only on the objects that answer names; the owner match and its depth, the queue arm, the + source of the approval arm, the external floor, the guest denial, the phantom-anchor narrowing and the delegation + intersection; the outer read's tenant wall; `ReadableIds` and its consumers; ADR-0147's leaf and its floor. +- **Consumers**: `@objectstack/spec` (the leaf's declaration, the comparand door's option, the conformance case-set, + the `ISharingService` prose), `@objectstack/objectql` (the door and the executor seam), `@objectstack/driver-sql` + and the drivers that inherit it, `@objectstack/driver-turso` (its remote transport), `@objectstack/driver-memory`, + `@objectstack/driver-mongodb`, `@objectstack/driver-odata`, `@objectstack/service-analytics` (its read-scope + compilers), `@objectstack/plugin-security` (the read filter that carries the leaf; the explainer's record pass) and + `@objectstack/plugin-sharing` (the one producer, and the switch). + +--- + +## TL;DR + +A member's read of a private, owner-scoped object carries a share arm: the records that `sys_record_share` grants to +that user. Today `packages/plugins/plugin-sharing/src/sharing-service.ts#buildReadFilter` builds the arm by reading the +user's grant rows into memory and binding their ids as a list, and that read stops at `limit: 5000`. The card states +the consequence, and this record repeats its words and adds none: past 5,000 share grants a member silently loses +access, failing closed. The predicate-update scope (`packages/plugins/plugin-sharing/src/sharing-service.ts#buildWriteFilter`) +reads the same way. + +This record proposes that the arm lower to one more engine-internal branded comparand, provisionally +`SharedRecordIds`, which a SQL driver compiles in the list's own position: + +```sql +id IN (SELECT record_id FROM sys_record_share + WHERE object_name = :object AND recipient_type = 'user' AND recipient_id = :user + AND record_id IS NOT NULL AND record_id <> '') +``` + +Every grant then counts, whatever the count. No grant is read into memory, and the share arm binds a fixed handful +of parameters where it bound one per grant. Below today's cap the visible set is the same set; above it the answer +is the corrected one. The owner match, the queue arm and the approval arm stay in the same filter as sibling +disjuncts. No request can spell the leaf, and no author gains a spelling. + +Three things are the maintainer's and are put, not decided: + +- **①** Whether the subquery carries a tenant scope. Today's grant read carries none. Recommended: none, which is + parity. +- **②** What an evaluator that cannot run a subquery answers: MongoDB, OData, an object on another datasource, the + analytics native-SQL compiler, the explainer. A materialised list, or a refusal. Recommended: no list anywhere. The + analytics compiler compiles the leaf and the explainer resolves it per record. On storage that cannot run a + subquery, share grants become unsupported: refused at the grant door and no longer counted, with a visible trail. + That takes away something that works there today, and [Q2](#q2--an-evaluator-that-cannot-run-the-leaf) says + exactly what. +- **③** `buildWriteFilter` feeds a predicate `update`, and ADR-0139 D1 admits a leaf on read verbs only. Recommended: + admit this leaf's write form on `update`, and nowhere else. + +## Provenance + +- **The defect.** [#33787](https://github.com/objectstack-ai/objectstack/issues/33787), filed from the bench report + [`6893177082`](https://github.com/objectstack-ai/objectstack/issues/33701#issuecomment-6893177082) on #33701. +- **The R9 item.** Epic #33631's addendum + [`6893156419`](https://github.com/objectstack-ai/objectstack/issues/33631#issuecomment-6893156419) names the + semi-join as the target shape. The `domain:server` seat's three constraints on whoever builds it are + [`6893239331`](https://github.com/objectstack-ai/objectstack/issues/33787#issuecomment-6893239331): keep every arm, + pin parity, quote the speed figure narrowly. Its item 1 is read as corrected by `6895112167` below. +- **The reading that found no compile path.** os-dev-report + [`6895027257`](https://github.com/objectstack-ai/objectstack/issues/33787#issuecomment-6895027257) on #33787 + (`needs_decision`): the arm cannot reuse `ReadableIds`, and its option A is a second leaf decided by a new record. +- **The routing and the independent review.** + [`6895112167`](https://github.com/objectstack-ai/objectstack/issues/33787#issuecomment-6895112167): an independent + review confirmed the report's four claims and found option A under-scoped on write verbs, the analytics native-SQL + scope, the in-process explainer and verdicts, and cross-datasource objects. [D5](#d5--the-evaluator-census), + [Q2](#q2--an-evaluator-that-cannot-run-the-leaf) and [Q3](#q3--the-leaf-on-a-predicate-update) are that scoping. The + same comment corrects constraint 1: "every arm stays in the same filter", not "inside the subquery". +- **The ruling.** [`6895275749`](https://github.com/objectstack-ai/objectstack/issues/33787#issuecomment-6895275749): + 「只做根治」, and the root fix starts with this record. +- **This card and its triage.** [#33899](https://github.com/objectstack-ai/objectstack/issues/33899); triage audit + [`6896032788`](https://github.com/objectstack-ai/objectstack/issues/33899#issuecomment-6896032788) (lane, grade, and + the standing principle quoted under Q2). +- **This record's own reading** is of `origin/main` `b8ac0e24`. The card's was of `45dee177`. The premise holds on + both, and [What this reading adds](#what-this-reading-adds-to-the-cards) lists where the newer reading is more exact. + +## Context + +### The mechanism today (read on `origin/main` `b8ac0e24`) + +- **The read scope.** `packages/plugins/plugin-sharing/src/sharing-service.ts#buildReadFilter` answers `null` (no + restriction) for a bypass or system context, an object whose org-wide default is not private for this principal, + an object with no owner field, and an `org` read depth. It answers the deny sentinel for the guest and for a context + with no user id. Otherwise it composes `{ $or: [ownerMatch, queueMatch, { id: { $in: grantedIds } }] }`: the queue + disjunct is there when the object has a queue column and the caller sits in a queue, the `$in` disjunct only when + the list is not empty, and the owner match stands alone when neither is. A federated object whose owner column is + the platform's injected anchor takes neither the owner arm nor the share arm + (`packages/plugins/plugin-sharing/src/federated-phantom-anchors.ts#hasPhantomOwnerAnchor`). +- **The grant read.** One `find` of `sys_record_share` with `{ object_name, recipient_type: 'user', recipient_id }`, of + which it uses `record_id`, at `limit: 5000`, with no ordering, under + `packages/plugins/plugin-sharing/src/sharing-service.ts#SYSTEM_CTX`. That context is system authority and names no + organization. The security middleware passes a system context through, and + `packages/objectql/src/engine-driver-options.ts#driverReadScope` projects no driver tenant scope for such a + context. So the read runs outside the tenant wall, and it returns the user's rows for the object whatever + organization each row carries. `packages/plugins/plugin-sharing/src/sharing-service.ts#grantedRecordIds` drops a + nullish `record_id`, stringifies the rest and drops the empty string. +- **The approval arm.** `packages/plugins/plugin-sharing/src/sharing-service.ts#pendingApproverReadGrants` asks the + approvals service for the records a pending step waits on the caller for. They grant read only, none to a delegated + principal, and they fail closed. Their ids are unioned into the same list as the grants' ids. +- **The queue arm.** `packages/plugins/plugin-sharing/src/sharing-service.ts#queueSittingMatch` is + `owner_id IS NULL AND queue IN (the caller's queues)` (ADR-0142 D3): a sibling disjunct over the object's own + columns, and no part of the id list. +- **The write scope.** `packages/plugins/plugin-sharing/src/sharing-service.ts#buildWriteFilter` scopes a predicate + (multi-row) write wherever the object is not write-open to the caller: a `private` model and a `public_read` one + alike. For `delete` it answers the owner match alone (ADR-0111 D3). For `update` it reads the grants the same way, + narrowed to `packages/plugins/plugin-sharing/src/access-level.ts#WRITE_ACCESS_LEVELS` (`edit`, and the retired + `full`, still honoured), at the same `limit: 5000`, and ORs the queue arm in. It has no approval arm, and on a + phantom-anchor object it answers the deny sentinel. A by-id write never reads the list: + `packages/plugins/plugin-sharing/src/sharing-service.ts#checkEdit` asks one record's rows (`record_id = :id`, + `limit: 1`), and the delete gate has no share branch. +- **Where the scope goes.** `packages/plugins/plugin-sharing/src/sharing-plugin.ts#buildSharingMiddleware` ANDs the + read scope into the `where` of every `find`, `findOne`, `count` and `aggregate` (the delegator's beside it, + ADR-0090 D10) and the write scope into the `where` of a predicate `update` or `delete`. + `packages/plugins/plugin-security/src/security-plugin-sharing-verdicts.ts#resolveSharingReadFilter` hands the same + read scope to two more readers. One is `packages/plugins/plugin-security/src/security-plugin-read-filter.ts#getReadFilter`, + so the scope also rides into every composed `ReadableIds` scope whose parent is such an object and into the + analytics read-scope compilers. The other is the explainer's record pass. +- **The table.** `packages/plugins/plugin-sharing/src/objects/sys-record-share.object.ts#SysRecordShare`: `record_id` + is the id half of a pointer pair with `object_name` (ADR-0052 §5), text on both halves, and not a relation. Only + `recipient_type: 'user'` rows are written and enforced (ADR-0111 D7). The index + `(object_name, recipient_type, recipient_id)` serves the grant read. A direct grant stamps the row's organization + from the shared record, or from the acting session for a record that carries none + (`packages/plugins/plugin-sharing/src/sharing-service.ts#resolveDirectGrantOrganization`); a rule-materialised grant + carries its rule's. No access gate reads the stamp. +- **The term used below.** An operation is *sharing-scoped* when one of the two builders composes such a filter for + it: the object has an owner field, the caller is below `org` depth, and the object is not open to the caller on + that side (a `private` model for a read; a `private` or `public_read` model for a predicate update; for an external + principal, whatever the external floor leaves closed). + +### Why no existing form serves + +- **`ReadableIds` means one thing**: the ids of P this caller may read. Its SQL always projects the parent's `id` + (`packages/drivers/driver-sql/src/sql-driver.ts#readableIdsSubquery`), under a scope the engine composes from the + security service and under the outer read's tenant scope. It has no slot for another projected column or for a fixed + system predicate, and ADR-0147's alternatives rejected giving it one: one brand carries one meaning. +- **The filter vocabulary is closed** (`packages/spec/src/data/filter.zod.ts#VALID_AST_OPERATORS`) and has no + subquery operator. An authorable one is the form ADR-0139 refused, because authorable means request-spellable. +- **The nested-relation lowering materialises** an id list and refuses past + `packages/objectql/src/relation-filter-lowering.ts#RELATION_FILTER_ID_CAP` (1,000), and `record_id` is not a relation. +- **A longer list is not an answer.** The ruling behind ADR-0139 + ([`6097072172`](https://github.com/objectstack-ai/objectstack/issues/22590#issuecomment-6097072172)) took neither an + unbounded `$in` nor a raised cap for that record's class: one moves the cliff to the dialect's bound-parameter + ceiling, the other moves it by a constant. +- **ADR-0139 D1 ends "⛔ No second leaf, no `EXISTS`, no correlated form"**, and its O4 records this very read as "A + separate finding, not this record's". ADR-0147 is the precedent for one more leaf under its own brand. + +### What it costs + +- **The defect**, in the card's words: past 5,000 share grants a member silently loses access, failing closed. It is + triaged p2, and the maintainer ruled no interim knowing it stays until the switch lands. +- **Every sharing-scoped operation reads the grants again.** A list page is a `find` and a `count`, so two grant + reads, and each statement then binds one parameter per grant. Inside a `controlled_by_parent` read the list binds + once more, within the parent's subquery. +- **The measured figure, quoted as narrowly as the seat constrained it** (`6893239331` item 3). It covers the scope + statements alone: the account page, its total and the two grant reads, at 1M rows and 5,000 grants. There the + id-list scope against the semi-join scope read PG 21.6 → 7.0 ms. SQLite read 18.3 → 12.1 ms for the same pair, and + the line-item chain stayed flat. It is not a whole-request figure, and no card under this record may claim more. + +### What this reading adds to the card's + +- **The write scope's share arm exists on `update` only**, and only on the predicate door. `delete` never had one and + the by-id gates read one record, so ③ is about one verb. +- **Every addressed predicate write is already narrowed to the rows the read door returns**, at most 10,000 of them, + with a loud refusal above (`packages/plugins/plugin-security/src/security-plugin-addressed-writes.ts#readableRowsScopeForPredicateWrite`, + `packages/plugins/plugin-security/src/security-plugin.ts#PREDICATE_WRITE_READABLE_ID_CAP`). That bounds the rows a + predicate update touches. It does not evaluate the share arm. +- **"Share rows can carry a NULL organization" is narrower than it reads.** ADR-0131 D1 makes NULL not a state, and + it names a record share among the rows that carry their organization, NOT NULL. What remains is ADR-0131's own + exceptions: a lean embedding that registers no organization object, and rows an uncertified database still holds. + The parity argument under ① does not rest on those rows: today's grant read consults no organization at all. +- **The share disjunct becomes universal.** Today it is present only for a caller who holds a grant or a pending + approval. As a leaf it is present on every sharing-scoped operation, so an evaluator's answer to ② is met by + nearly every member read of such an object, not by grantees alone. +- **The analytics native compiler has a third answer.** It need not choose between a list and a refusal: the leaf + needs no composition, so that compiler can compile it. +- **The explainer judges one record at a time**, and for one record the leaf is one indexed point read, the read + `checkEdit` already makes. That is exact at every grant count, and it is neither a list nor a refusal. + +## Decision + +### D-0 — The same-set invariant + +Name the set once, so every later sentence can point at it: + +- **G(object, user, levels)** is the set of `record_id` values over the `sys_record_share` rows with + `object_name = object`, `recipient_type = 'user'`, `recipient_id = user`, a `record_id` that is neither NULL nor + empty, and, where `levels` is given, an `access_level` in `levels`. It is read with system authority, with no + organization predicate (that half is ①), with no cap and no ordering. +- **The leaf denotes G, the whole of it.** Today's list is at most 5,000 members of G. +- **Below the cap nothing changes.** Where a caller's rows number 5,000 or fewer, today's list is G, and every read + and every predicate update answers the same rows before and after the switch, on every evaluator that evaluates + the leaf. +- **Above it the answer is the corrected one**: every member of G counts. +- **Nothing else moves.** No row enters or leaves a scope through the owner match or its depth, the queue arm, the + approval arm, the org-wide default, the external floor, the guest denial, the phantom-anchor narrowing, the + delegation intersection or the outer read's tenant wall. +- **Anything beyond that is a visibility change, and it is the maintainer's first.** That is why ①, ② and ③ are + questions: each has an answer that keeps this invariant and an answer that narrows it on purpose. + +### D1 — The leaf: its own brand, engine-internal, never authorable + +- **One more branded comparand, declared in spec.** `@objectstack/spec` declares it in `packages/spec/src/data/` + beside `packages/spec/src/data/readable-ids.ts#ReadableIds`, with ADR-0139 D1's device unchanged: the brand is a + `Symbol.for` key, non-enumerable, and the value is frozen. A copy that crosses JSON, structured clone or a + serializing wire arrives unbranded and is refused as a non-list comparand (`INVALID_FILTER` / 400). ⛔ It is never + dropped and never read as an empty list. +- **Its own brand.** It is not a mode of `ReadableIds` and not a mode of ADR-0147's leaf. ADR-0147 D-a reads ADR-0139 + D1's reason for one leaf as this: one brand carries one meaning, so no composer has to ask which meaning it holds. + This record keeps that reason the same way, by giving each further meaning a brand of its own. +- **What it carries: the inputs of G and nothing else.** The object's name, the recipient's user id, and the admitted + access levels: none on the read form, which admits every level, and `WRITE_ACCESS_LEVELS` on the write form (③), + supplied by the producer so the level vocabulary keeps its one home. `recipient_type = 'user'` is fixed, not + carried. It carries no organization, no caller scope and no reading context. The inputs are ordinary enumerable + properties, as `ReadableIds`' object name is, so two users' leaves never compare or serialise as equal; only the + brand is non-enumerable. The rest of its representation is the spec card's. +- **The recipient is the producer's.** It is captured from the context the scope is built for, where today's + `recipient_id` comes from. ⛔ No seam and no driver re-derives it from the reading context. +- **It arrives composed.** It asks no security service and composes no scope, so the engine's executor seam passes + it through ([D4](#d4--the-engine-seam-and-what-is-built-once-with-adr-0147)). +- **Position.** It is legal only as the `$in` comparand of `id` on the object it names: directly in that object's + `where`, or inside the composed scope of a `ReadableIds` leaf whose parent is that object. There it composes under + `$and`, `$or` and `$not` like any `$in`. +- **Verbs.** `find`, `findOne`, `count` and `aggregate`, `where` only. Its write form on a predicate `update` is ③. On + `delete`, in a `having`, or at any other position, the engine refuses it loudly, as ADR-0139 D1 refuses a misplaced + `ReadableIds`. +- **No request can spell it, and no author gains a spelling.** No operator joins + `packages/spec/src/data/filter.zod.ts#VALID_AST_OPERATORS`, and there is no CEL function and no lint vocabulary. + One producer writes it: plugin-sharing's read-scope builder, and its write-scope builder under ③. +- **⛔ No `EXISTS`, no correlated form, no join.** It sits in the list's own position, so `find`, `count` and + `aggregate` agree by construction, and a record matched by several grant rows is still one row. +- **The name.** `SharedRecordIds` is provisional ([O1](#open-items-not-blocking-acceptance-each-becomes-a-reading-on-its-card)): + a new public name is the seat's call. It names what the ids are, record ids, because a name read as "the ids of the + grants" points at the wrong column. + +### D2 — The inner read: today's grant read, with no cap + +The subquery is `buildReadFilter`'s own read restated as SQL, with the `limit` gone and nothing added: + +```sql +-- the read form +id IN (SELECT record_id FROM sys_record_share + WHERE object_name = :object AND recipient_type = 'user' AND recipient_id = :user + AND record_id IS NOT NULL AND record_id <> '') + +-- the write form (③) adds one predicate inside the subquery + AND access_level IN (:levels) +``` + +- **System authority.** No row-level security, org-wide default, sharing or field-level security applies to + `sys_record_share` here. Today's read runs under `SYSTEM_CTX`, and the sharing service bypasses its own table. +- **Tenant scope: ①.** Today's read carries none. Under the recommended answer the subquery carries none either: the + driver ⛔ does not apply `packages/drivers/driver-sql/src/sql-driver.ts#applyTenantScope` to it. The driver card + records that absence against the driver's read-side chokepoint guard (`scripts/check-tenant-chokepoint.mjs`): an + exemption citing this record if the guard reads the builder, a pin if it does not. So it reads as a decision and + not as an oversight. The outer statement's wall is untouched either way. +- **No validity, status or source filter.** Today's read has none, and adding one narrows G. +- **The blank-id guard** restates `grantedRecordIds`' filter. It also keeps a negation NULL-safe: `id NOT IN (…)` over + a subquery that holds one NULL is never true, so it would answer no row at all. +- **Set semantics.** Several grant rows on one record (one per source, ADR-0111 D7, and one per rule) are one member. + Nothing de-duplicates, and nothing needs to. +- **No cap, no ordering.** The `limit` is not raised and not made loud. It is gone, because nothing is materialised. +- **Same datasource.** The subquery reads `sys_record_share` on the datasource the outer object is bound to. An object + bound to another one is in ②'s census: no driver evaluates a subquery across two. +- **Index-backed** by `(object_name, recipient_type, recipient_id)`. Whether that index should also carry `record_id` + is a measurement on the driver card (O3). +- **Key comparison.** Both keys are strings on every table the platform manages (`id` a `varchar`, `record_id` a + `text`), and today's list is normalised through `String()`. Where an outer key is of another type, the compiled + form owes the same rows or a loud refusal, ⛔ never a silent miss (O2). +- **Statement time.** The subquery reads the grants when the statement runs. Today's list is read once per operation, + before its statement. A grant or a revoke is therefore seen no later than it is today. + +### D3 — Every arm stays in the same filter + +After the switch the read scope is: + +```text +{ $or: [ ownerMatch, + queueMatch, when the object has a queue column and the caller sits in a queue + { id: { $in: SharedRecordIds(object, user) } }, + { id: { $in: approvalIds } } ] } when the approvals service names any +``` + +- **The seat's rule, as corrected** (`6895112167`): every arm stays in the same filter. ⛔ None moves to the + application, and none is dropped. +- **The approval ids become a disjunct of their own.** Today they are unioned into the grant list. A union of two id + sets and an OR of two memberships select the same rows. They stay a list: they are not share rows, the approvals + service vouches for them, and no subquery over `sys_record_share` can express them. +- **The queue arm stays a sibling disjunct** over the object's own columns. ⛔ It is never moved into the share + subquery, which cannot express it. +- **The owner match is unchanged**, at every depth. +- **The share disjunct is always present** on a sharing-scoped read, on every object ② leaves it on. Today it is + absent for a caller with no grant. An empty subquery admits nothing, so the rows are the same. +- **The write scope** takes the same shape with the write form (③) and, as today, no approval arm. `delete` keeps + answering the owner match alone, and no leaf is ever written on it. +- **A phantom-anchor object** keeps today's answers: on a read the approval ids or the deny sentinel, on a predicate + write the deny sentinel, and no share arm on either. +- **A delegated operation** carries one leaf per identity, each on its own side of the ADR-0090 D10 intersection, + where it carries two lists today. +- **The outer read's tenant wall** is composed where it is composed today. + +### D4 — The engine seam, and what is built once with ADR-0147 + +**The seam.** + +- **Admission.** Two callers admit `ReadableIds` today, through + `packages/spec/src/data/filter-comparand-shape.ts#ListComparandShapeOptions`: the engine's comparand door + (`packages/objectql/src/filter-comparand-shape.ts#assertListComparandShapes`), and the analytics merges that hand a + read scope on to the engine (`packages/services/service-analytics/src/read-scope-sql.ts#assertReadScopeComparandsRunnable`). + The engine's door admits this brand the same way. The analytics merges are a row of ②. ⛔ No other caller admits it. +- **Pass-through.** At the executor boundary (`packages/objectql/src/engine.ts#composeReadableIdsAtBoundary`) there is + nothing to compose. The seam checks position and verb (D1) and hands the leaf to the driver as it stands. +- **Every occurrence, nested ones included.** The scope the engine composes for a `ReadableIds` leaf is the security + service's read filter for the parent (`packages/objectql/src/engine-readable-ids-permission-formula.ts#composeReadableIdsChain`), + and for a sharing-scoped parent that filter carries this leaf. The seam's checks descend into composed scopes. + `driver-sql` compiles a composed scope with the same compiler, so the leaf compiles there too. +- **Two classes the seam recognises before the driver call.** The first is an object bound to another datasource than + `sys_record_share` (`packages/objectql/src/engine.ts#resolveDatasourceBinding`); what it answers is ②. The second is + ADR-0139 D5.2's class: an object-scoped middleware registered for `sys_record_share` + (`packages/objectql/src/engine.ts#hasObjectMiddleware`), which today's grant read passes through and the subquery + would read around. No package in this repository registers one. Where a host does, the seam refuses the leaf rather + than read around the middleware, and every sharing-scoped operation on that host fails until the registration is + removed. Hosts outside this repository were not read (O8). +- **The refusal** is ADR-0139 D3's envelope wherever it occurs: status 500, `INTERNAL_ERROR`, a message naming the + evaluator, the leaf and the remedy, logged at `error` once per evaluator + (`packages/core/src/utils/readable-ids-driver-refusal.ts#refuseReadableIdsOnce` is the device). ⛔ It is not + `INVALID_FILTER`: the fault is a composition's, not an author's. + +**Built once.** The card records ADR-0147 as approved and unbuilt, and its Status line still reads `Proposed`. Both +records add a leaf that is a branded `$in` comparand, arrives composed, and compiles to a fixed inner read of one +platform table under system authority, behind a blank-id guard, with no tenant scope (ADR-0147 D-b; here, ①'s +recommended answer). That is one mechanism: + +| Piece | Built | +|:--|:--| +| The brand, its factory and guard, its meaning, its producer | per leaf, never shared: one brand, one meaning | +| The comparand door's admission of engine-internal comparands | once, as one option that names the brands it admits, not one flag per brand | +| The executor seam's pass-through, its position and verb checks, its descent into composed scopes | once | +| The fixed inner read: one table, one projected column, a closed set of bound equality and membership predicates, the blank-id guard, system authority, and the tenant scope each record rules for its leaf (none in ADR-0147 D-b; ① here) | once per evaluator (`driver-sql`, the Turso remote transport, `driver-memory`, and the analytics native compiler if ② rules that it compiles). Each leaf supplies its description, and no evaluator restates either leaf's predicate by hand | +| The refusal envelope and its once-per-evaluator log | once | +| The conformance case-set | once, with a case per leaf | +| A driver's declaration that it evaluates such leaves | once, if either record consults one. ADR-0147 D-d does. This record does under every answer to ② but R1 | +| What an evaluator that cannot run a leaf answers | per leaf. ADR-0147 D-d states its own; this record's is ② | + +- **Sequencing.** Whichever record's cards are cut first build the shared pieces in the two-leaf shape, and the other + record's cards add their leaf on top. ⛔ Neither builds a private copy. +- **This record does not revisit ADR-0147.** Its floor was chosen for a leaf whose refusal would fail every `sys_user` + read. Whether the SQL-first rule changes that answer is that record's question (O6). + +### D5 — The evaluator census + +One rule holds for every evaluator, whatever ② rules: **an evaluator evaluates the leaf exactly, or refuses it +loudly. ⛔ It never reads it as an ordinary comparand.** The in-process matcher shows why. +`packages/formula/src/matches-filter.ts#matchesFilterCondition` answers `false` for an `$in` whose comparand is not an +array, so an unrecognised leaf reads as "matches no record", and under `$not` as "matches every record". + +Three rows are not in question: + +| Evaluator | Answer | +|:--|:--| +| `driver-sql`; `driver-sqlite-wasm` and the local Turso transport, which inherit it | compiles, in `packages/drivers/driver-sql/src/sql-driver.ts#applyFilterCondition`, beside the `ReadableIds` arm | +| the Turso remote transport (`packages/drivers/driver-turso/src/remote-transport.ts#RemoteTransport`, an independent compiler) | compiles the same SQL | +| `driver-memory` | evaluates in process, as it evaluates `ReadableIds` (`packages/drivers/driver-memory/src/memory-driver.ts#readableParentIds`): it reads the store's `sys_record_share` rows under the fixed predicate and member-tests them, unbounded and hashed once. It refuses a tenant-scoped call and a multi-tenant boot, so ① does not arise there | + +`driver-memory`'s row is not the slower path Prime Directive 5 forbids. In-process evaluation is that driver's only +way to answer anything, the engine's own suites run on it, and the card's plan builds it (item 7). The standing +principle quoted under ② names memory beside MongoDB, so the maintainer may move this row under ② as well. Its cost +there is that every suite which exercises record sharing on `driver-memory` moves to SQLite. + +The rest of the census is ②: `driver-mongodb`, `driver-odata`, a driver this repository does not ship, an object on +another datasource, the analytics read-scope compilers, and the explainer's record pass. + +### D6 — What the switch must show + +The plugin-sharing switch is where #33787 ends. Its card carries the pins the defect card and the seat set (#33787's +body; `6893239331` item 2): + +- **Parity below the cap.** At 5,000 grants the leaf and today's id list answer the same, on SQLite and on + PostgreSQL, for the list total and for GET by id, with each arm exercised: owner, queue, approval and share. +- **The corrected answer at the edge and above it.** At 5,001 and at 6,000 grants. 6,000 grants plus 1,000 owned + records is 7,000 visible, and the 6,000th granted record answers 200. +- **Both scopes**: the read scope, and the predicate-update scope as ③ is ruled. +- **Ablated**, as the seat's constraint asks. +- **The speed figure** is quoted as [What it costs](#what-it-costs) quotes it, and no wider. + +## Questions for the maintainer + +Each question states today's fact, the options, what each option costs, and a recommendation. Until the maintainer +rules, a recommendation is not a decision, and no execution card is cut. + +### Q1 — The tenant scope of the subquery + +**Today.** The grant read carries no tenant scope ([Context](#the-mechanism-today-read-on-originmain-b8ac0e24)). Every +access gate that consults share rows reads them the same way: the list scope, the by-id edit gate and the explainer. +None of them reads the organization a grant row is stamped with. + +**Option A — no tenant scope (parity). Recommended.** The subquery is G as D-0 defines it: system authority and no +wall. The visible set is today's below the cap and the corrected one above it, under every posture. The records stay +behind the outer statement's wall, composed exactly as today: a record outside the reader's organizations is not +selected, whatever the subquery holds. + +**Option B — the subquery takes the outer read's tenant scope**, as ADR-0139's `ReadableIds` subquery does. That +narrows G by the grant row's stamp: + +- Under the `single` posture nothing changes: that posture has no wall between organizations for the driver to apply. +- Under `isolated` and `group`, a grant stamped outside the reader's scope stops counting. Where the stamp is the + record's own organization (a direct grant on an object with a tenant column), nothing visible changes: the outer + wall already decides that record. Where the two can differ (a grant on an object with no tenant column, stamped + with the granting session's organization; a rule-materialised grant, stamped with its rule's organization and not + the record's), a reader whose scope excludes the stamp loses a record they read today. +- A grant row with no organization stops counting wherever a tenant scope applies. ADR-0131 D1 leaves such rows to + an uncertified database. +- The by-id gates and the explainer would have to take the same wall in the same change, or the list and the by-id + answer disagree about one record. + +**What B buys** is a second wall on rows whose records the outer wall already governs. Beyond that redundancy its +only effect is the narrowing above, which is a visibility change with its own migration reading. + +**Recommendation: A.** It is the invariant (D-0), and it is what ADR-0147 D-b states for its own leaf, for the same +reason: the wall's only lawful effect on the inner read is redundancy, and anything more changes the set. B stays +available as a decision of its own. If grants are to be walled by their stamp, that is ruled for every gate that reads +them, with a migration reading, and not as a side effect of removing a cap. + +### Q2 — An evaluator that cannot run the leaf + +**Today.** These evaluators receive an ordinary `id IN (list)` arm and answer it like any list, up to the cap. Nothing +in the scope builders looks at where the object is stored, the phantom-anchor rule apart. + +**The standing principle.** The maintainer, on the triage thread on 2026-11-15, as quoted in triage comment +[`6896032788`](https://github.com/objectstack-ai/objectstack/issues/33899#issuecomment-6896032788): +「有的功能如果Mongo内存不支持,那就不需要支持,首先保sql,应该用最高性能的方案,而不能为了兼容而兼容」. AGENTS.md Prime +Directive 5 states the rule in force (ruling record `6888468549`): "build a query capability at its fastest SQL shape +(JOIN or semi-join, aggregates in the database); memory and mongo refuse what they cannot run with a stable code; ⛔ +never a slower path built only for parity". ADR-0147 D-d chose the other way for its leaf, an exact-array floor. + +**The three answers an evaluator can give.** + +- **L — keep a list.** The engine substitutes a materialised id list for the leaf before the call, chosen up front + from a declaration the driver makes (ADR-0147 D-d's device), ⛔ never by catching a refusal. To keep "never drop + silently" the list is complete up to a bind-safe bound, with a loud refusal past it. This is the fallback the + independent review described, with a refusal where it had an error-level log. +- **R1 — refuse the read.** The producer writes the leaf for every object, and an evaluator that cannot run it + refuses with D4's envelope. This is ADR-0139 D3 as written, and it needs no declaration. +- **R2 — refuse the feature.** Share grants are not supported on an object whose evaluator cannot run the leaf. The + producer writes no share arm there, every gate stops consulting grants on that object, and the grant door and the + sharing-rule save door refuse them as inert: ADR-0111 D7's rule with one more arm, `SHARING_NOT_ENABLED` / 422. A + leaf that still reaches such an evaluator is refused as in R1. It needs the declaration, to know up front. + +**The census.** The by-id sharing verdicts are not in it: they read one record's grant rows and never receive the +leaf (`packages/plugins/plugin-security/src/security-plugin-sharing-verdicts.ts#resolveSharingCanEdit`). In the table, +"such an object" is one a caller's operations are sharing-scoped on. + +| Evaluator | If it keeps a list (L) | If it refuses | Recommended | +|:--|:--|:--|:--| +| `driver-mongodb` (`packages/drivers/driver-mongodb/src/mongodb-filter.ts#translateFilter`, which refuses `ReadableIds`) | Everything that works today keeps working, up to the bound. The engine keeps a second evaluation path and a completion read per operation | **R1**: every sharing-scoped read and predicate update fails with 500, rows the caller owns included, because the leaf is on every such operation. **R2**: owner, queue and approval access is unchanged; share grants on those objects stop counting and can no longer be created | **R2**, with R1 behind it | +| `driver-odata` (`packages/drivers/driver-odata/src/odata-driver.ts#refuseReadableIds`) | As above; the backend's own ceiling is its request length | As above | **R2**, with R1 behind it | +| A driver this repository does not ship | As above, unless it declares that it evaluates the leaf | As above | **R2**, with R1 behind it | +| An object bound to another datasource than `sys_record_share`. That includes a federated object that declares a real remote owner column, which keeps its shares today (`packages/plugins/plugin-sharing/src/sharing-service.ts#inertGrantReason`) | As above | As above | **R2**, with R1 behind it | +| The analytics native-SQL compiler (`packages/services/service-analytics/src/read-scope-sql.ts#compileScopedFilterToSql`). Today it binds one parameter per `$in` member and refuses `ReadableIds` at entry | The cap, or an unbounded list, returns on this path | It declines the query to the engine strategy, as it does for `ReadableIds` (`packages/services/service-analytics/src/strategies/native-sql-strategy.ts#readScopeCarriesReadableIds`). With the leaf on every sharing-scoped read, that is nearly every member query on such an object, and the shapes only native SQL serves, such as a multi-hop join (`packages/services/service-analytics/src/strategies/cross-object-where.ts#UnservedCrossObjectReason`), are then refused | **Neither: it compiles the leaf.** It is SQL, and the leaf needs no composition | +| The analytics engine strategy's merge and the dry-run SQL echo | not applicable | Unless its merge admits the brand (`packages/services/service-analytics/src/read-scope-sql.ts#assertReadScopeComparandsRunnable`), every query it serves on such an object is refused | **It admits the brand** and hands the scope to the engine, as it does `ReadableIds`. The echo prints the subquery the statement runs | +| The explainer's record pass (`packages/plugins/plugin-security/src/explain-engine.ts#matchUnderDeclaredColumns`). Today it matches the list in process and publishes it as the sharing layer's `rowFilter` (`packages/spec/src/security/explain.zod.ts#ExplainRecordAttributionSchema`) | It materialises the caller's whole grant list for each explanation, and the published filter grows with it | The record pass matches the sharing read filter for every record-grained explanation, whatever the verb. So each one on such an object fails, on every driver, and with it the attachment and comment gates that ask the explainer for a parent record's by-id judgement | **Neither: it resolves the leaf at the record.** One indexed read under the fixed predicate, keyed by the record ids it judges, the read `checkEdit` makes for one | + +**What the recommended column costs, stated plainly.** + +- **On the four storage rows, share grants stop working at the switch.** Grants that count today, up to the cap, stop + counting, and new ones are refused. It fails closed, and it must not be silent. The switch card owes a report at + boot of the objects that hold such rows, the refusal at both doors, the explainer's sentence and a changelog entry: + ADR-0111 D10's "tighten directly, fail closed, with a visible trail". This reading has no census of deployments + that hold such grants; that report is the instrument. +- **It consults a driver declaration**, so ADR-0139 D3's "⛔ No `DriverCapabilities` bit returns" is revisited for + this leaf as ADR-0147 D-d revisits it for its own, and ADR-0111 D7 gains an arm. +- **A later compile lifts R2 for that evaluator** with no amendment here: a `$lookup` form on MongoDB (O9), or a + remote that can reach the grants. +- **The explainer's published `rowFilter` changes content.** Today it lists every granted id, up to the cap. Resolved + at the record, the share arm is the judged record's id when a grant admits it and is left out otherwise, the two + shapes today's filter has for a caller with one grant and with none. ⛔ It never publishes the leaf, which would + cross the wire unbranded. The card that lands it declares that under its own Clause-②. + +**Why not R1 alone.** The leaf is on every sharing-scoped operation, so R1 takes ownership scoping down together with +sharing on those evaluators. It is the simplest reading of the rule and needs no declaration, and that outage is its +price. Writing the leaf only for a caller who holds a grant would confine the outage to grantees, at the price of the +per-operation read this record removes, and a grantee would still lose every read of the object. Under the +recommendation R1 stays as the backstop: a leaf that reaches an evaluator that cannot run it is refused, never +dropped. + +**Why not L.** It is the slower path built only for parity. It keeps a second evaluation path in the engine (the +declaration, the substitution, its descent into composed scopes, a completion read per operation) for backends the +principle says not to be compatible with for compatibility's sake, and its bound is a cap again. Its merit is real and +is stated: L is the one answer under which nothing that works today stops working. + +**Recommendation.** No list anywhere. The storage rows take **R2** with R1 behind it, the analytics compilers compile +or admit, and the explainer resolves at the record. The maintainer may rule row by row. + +### Q3 — The leaf on a predicate update + +**Today.** `buildWriteFilter` feeds the `where` of a predicate `update` with the same capped list, narrowed to the +write levels. ADR-0139 D1 admits a leaf on `find`, `findOne`, `count` and `aggregate` only, and the engine enforces it: +`packages/objectql/src/filter-comparand-shape.ts#collectComposableReadableIds` refuses a leaf in a write's predicate at +the executor's entry. `delete` has no share arm, and a by-id write reads one record, so the question is one verb on +one door. + +**Option A — admit the write form on `update`. Recommended.** The engine's verb rule admits this brand's write form +in the `where` of a predicate `update`, and nothing else. ⛔ Not `ReadableIds`, not ADR-0147's leaf, and not `delete`, +where no producer writes a leaf and one that appears is refused as today. `driver-sql` compiles an update's `where` +with the compiler it reads with (`packages/drivers/driver-sql/src/sql-driver.ts#updateMany`), so the write is one +statement whose predicate holds the subquery, and the engine's prior-row read (`packages/objectql/src/engine-update.ts`) +carries the same predicate. ADR-0139 D1 states its read-verbs rule without a reason. This record reads it from what +`ReadableIds` denotes, the ids a caller may read: a read scope, which a write's predicate has no use for. This leaf's +write form denotes a write scope: the records shared with the caller at a write level. The cost is one more governed +sentence revisited: ADR-0139 D1's read-verbs sentence, for this leaf alone. + +**Option B — keep the leaf read-only, and a list on the write side.** It has three forms, and each meets a ruling +already made: + +- today's capped read, unchanged: the predicate-update half of #33787 stays, against the seat's constraint that + "`buildWriteFilter` takes the same shape"; +- a complete list: the unbounded `$in` that ruling `6097072172` did not take, with the dialect's bind ceiling as the + new cliff; +- a bounded list that refuses loudly past its bound: the cap kept and made loud, the interim shape 「只做根治」 ruled + out, made permanent on the write side. + +**Option C — derive the write scope from the candidate rows.** plugin-security already narrows an addressed predicate +write to the rows the read door returns, at most 10,000, so the write scope could read only the grants on those ids. +It is exact, and it is not recommended: it ties plugin-sharing's scope to another plugin's middleware order, a +composition without that plugin has no candidate list, and it binds up to 10,000 ids in a second read. + +**Recommendation: A.** The code leaves a fork, and the standing rulings close all of it but one branch: every form +of B contradicts one of them. What remains is that A changes a governed sentence of ADR-0139, and that is the +maintainer's to change. The 10,000-row bound on an addressed predicate write stays where it is: this leaf adds no +bound and removes none. + +## Consequences + +- **Positive.** Every grant counts on the SQL family, at any count. The cap and its silent cut are gone, not raised. + A sharing-scoped operation issues no grant read of its own, its statement's parameters no longer grow with the + grants, and a `controlled_by_parent` read no longer binds the list again inside the parent's subquery. The arm is + part of one statement, so `find`, `count` and `aggregate` agree by construction. +- **Cost, named.** Spec gains one more branded comparand. The engine's door and seam and three evaluators gain its + handling. Every sharing-scoped read carries an index-backed subquery, for a caller with no grant too, where today + it carried one extra read and no arm. +- **Failure surface.** Unchanged in direction. Today a failing grant read fails the operation before its statement; + after the switch the same failure is the statement's. +- **Freshness.** The arm is read at statement time (D2). On a predicate update the prior-row read and the write are + two statements, and each evaluates the share arm for itself, as each already evaluates the owner match for itself. + Today's list is read once, before both. +- **A public contract's answer changes kind.** `buildReadFilter` is a member of + `packages/spec/src/contracts/sharing-service.ts#ISharingService`. Its answer now carries an engine-internal leaf, so + it is handed to the engine in process, ⛔ never serialised and never matched by a generic matcher. The spec card + says so in the contract's prose. Readers outside this repository were not read from this tree (O8). +- **The evaluators under ②** change as the maintainer rules. The recommended answers' costs are stated there. +- **Each execution card declares its own Clause-②.** + +## Alternatives considered + +- **Generalise `ReadableIds`** with a projected column and a fixed system scope: rejected, as ADR-0147's alternatives + rejected it. One brand carries one meaning, and every composer and driver would otherwise branch on a mode. +- **A subquery operator or a CEL function in the authorable vocabulary**: rejected. Authorable means + request-spellable, and "the rows shared with user U" is a visibility primitive no request may spell. +- **`EXISTS`, a correlated subquery or a join**: rejected (D1). A join multiplies a record by its grant rows and + changes the shape of every statement. +- **Read every grant and bind the full list** (the report's option B): not taken. It is the unbounded `$in` of ruling + `6097072172`, its cliff is the dialect's bind ceiling, and it is the slower shape. +- **Keep the cap and refuse loudly past it** (the report's option C): ruled out with every interim by 「只做根治」. +- **A completion read up to a bind-safe bound, with an error-level log past it** (the independent review's interim, + which the routing comment notes is also the fallback a leaf would need): ruled out as an interim by the same + ruling. As a fallback it is answer L of ②. +- **Write the leaf only for a caller who holds a grant** (an existence probe per operation): rejected. It keeps the + per-operation read the semi-join removes, and the filter's shape would again depend on the data. +- **The nested-relation lowering**: rejected. It materialises, it caps at 1,000, and `record_id` is not a relation. +- **The list as one array parameter, a temporary table or `json_each`**: rejected. Each still reads the grants into + the application on every operation and is dialect-specific. The semi-join is the fastest shape. +- **A materialised "shared with" column on the record**: rejected, as ADR-0139's alternatives rejected a materialised + accessible-ids column: it is stale the moment access changes. Every grant would also rewrite a business row. +- **The approval ids or the queue arm inside the subquery**: rejected (D3). Neither is a share row. +- **Group, position or unit recipients evaluated in the subquery**: out of scope. Only `user` rows are enforced + (ADR-0111 D7), and rule materialisation already expands the others into per-user rows. +- **A tenant scope on the subquery**: that is ①'s option B. + +## Open items (not blocking acceptance; each becomes a reading on its card) + +- **O1** — Names. `SharedRecordIds`, and the driver declaration's name if ② consults one. The seat's call, fixed on + the spec card, and shared with ADR-0147's O1 where the declaration is shared. +- **O2** — Key comparison. The subquery compares two columns where today a column meets bound strings. On the tables + the platform manages both are strings. The driver card pins the comparison, type and collation, on every dialect + `driver-sql` ships, and answers an outer key of another type with the same rows or a loud refusal. +- **O3** — The index. `(object_name, recipient_type, recipient_id)` serves the predicate and does not carry + `record_id`. Whether it should is measured on the driver card, with the R9 bench as the instrument. +- **O4** — The approval arm stays a list. Its size is the approvals service's, and its ceiling is not measured here. +- **O5** — `packages/plugins/plugin-sharing/src/sharing-service.ts#listShares` reads one record's grant rows at + `limit: 500` with no notice. It serves the management listing and the explainer's share attribution, and no gate's + verdict rests on it alone. It was noted on #33787 and is not filed, and it is not this record's. +- **O6** — ADR-0147's floor and the SQL-first rule point different ways. This record does not revisit that one. If ② + is ruled a refusal, the two leaves differ on evaluators that cannot compile, and D4's table already builds for it. +- **O7** — Pointer notes owed on acceptance, each dated and append-only, in a governed edit of their own: ADR-0139 D1 + (one more leaf, and the read-verbs sentence if ③ is ruled A); ADR-0139 O4 (answered); ADR-0139 D3 and ADR-0111 D7 + (only under ②'s R2); and a cross-reference from ADR-0147 D-a for the shared seam. They are not in this record's + diff, which adds this record and its index row and edits no other record: ADR-0139 was under amendment by another + change while this record was written (PR #33992, its D6 and its Status line). +- **O8** — Readers of `buildReadFilter` and of the security service's read filter outside this repository (the cloud + repository's packages) were not read from this tree, and neither was any host that registers an object-scoped + middleware for `sys_record_share` (D4). The switch card owes that census before it lands. +- **O9** — `driver-mongodb`: a `$lookup` form is unprototyped (shared with ADR-0139 O3 and ADR-0147 O2). +- **O10** — A guard the leaf makes possible. A list carries no identity, and the leaf names its recipient. Whether the + seam verifies that recipient against the reading context (the caller, or the delegator of an on-behalf-of + operation) is the engine card's reading. It would catch a scope reused across requests. ⛔ It never replaces the + recipient (D1), and it must not refuse the explainer's judgement of another principal, which reaches no driver. + +## Acceptance criteria + +- The maintainer approves this record (`GOVERNED_APPROVERS`, Tier H) and rules ①, ② and ③. The rulings are recorded + in this record, in its Status line and in the three question sections, each citing its ruling record, before any + execution card is cut. +- O7's pointer notes land in their own governed edit. +- The switch meets [D6](#d6--what-the-switch-must-show). +- At every step D-0 holds on every evaluator that evaluates the leaf, and every other evaluator answers as ② ruled. + +## Execution plan (after acceptance) + +The seats cut the cards after acceptance, in this order. Each card declares its own Clause-② and runs its own gates. +The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ②'s rows add cards as they are ruled. + +1. **Spec: the leaf.** The brand, its factory and guard beside `ReadableIds`; the comparand door's option; the fixed + inner read's description; the conformance case-set; the `ISharingService` prose. The shared pieces take the + two-leaf shape (D4). +2. **Engine: the seam.** Door admission, pass-through, the position rule and the verb rule (③ as ruled), the two + recognised classes, the descent into composed scopes, the refusal, and the declaration's consult if ② rules one. +3. **`driver-sql` and the Turso remote transport: the compile.** The subquery and its tenant scope (① as ruled), the + update path (③ as ruled), the pins per dialect, O2 and O3. +4. **`driver-memory`: the in-process evaluation.** +5. **The rest of the census, as ② is ruled**: the storage rows' refusal for this brand, the analytics compilers, the + explainer's record pass. +6. **plugin-sharing: the switch.** `buildReadFilter` and `buildWriteFilter` write the leaf, the approval ids become a + disjunct of their own, and under R2 the inert arm and its report land here, at the moment those grants stop + counting. The middleware also mirrors its scope under the AST's `filter` key, which the executor seam does not walk + and no driver in this repository reads; the card stops mirroring the leaf there or pins that the key stays unread. + The card carries D6's pins and the narrow figure, and #33787 ends with it. ⛔ It lands last: landed earlier, it + hands the leaf to an evaluator that has no answer for it yet. diff --git a/docs/adr/README.md b/docs/adr/README.md index 887684343eb..1c1a3a78bce 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -13,12 +13,12 @@ ## Summary -155 records under `docs/adr/` (150 numbers), 11 under `ui/docs/adr/` (listed separately below). +156 records under `docs/adr/` (151 numbers), 11 under `ui/docs/adr/` (listed separately below). | Status | Records | |---|---| | Accepted | 133 | -| Proposed | 8 | +| Proposed | 9 | | Superseded | 4 | | Draft | 3 | | Deferred | 2 | @@ -26,7 +26,7 @@ | Amended | 1 | | Partially implemented | 1 | | Revised | 1 | -| **Total** | **155** | +| **Total** | **156** | ## Shared numbers @@ -222,6 +222,7 @@ A bare `ADR-0006` names the decision; its current text is [0006-project-environm | [ADR-0152](./0152-scim-group-grants-only-an-ordinary-permission-set-through-a-per-connection-mapping.md) | A SCIM group grants only an ordinary permission set, through a per-connection mapping row a platform administ… | Accepted — implemented, 2026-11-08, recording the maintainer's ruling of 2… | 2026-11-08 | — | — | | [ADR-0153](./0153-one-way-sync-in-beside-federation.md) | One-way sync-in beside federation — a connector or a federated object, a warehouse table included, fills an o… | Proposed — 2026-11-10. `docs/adr/` is Tier H (Prime Directive #14): this r… | 2026-11-10 | — | — | | [ADR-0154](./0154-audit-ledger-tamper-evidence-sealer-signed-checkpoints-amendments-verify.md) | The audit ledger is tamper-evident — an asynchronous sealer signs per-organization checkpoints, redaction and… | Proposed — 2026-11-10 — draft. This record declares; it implements nothing… | 2026-11-10 | — | — | +| [ADR-0155](./0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md) | The sharing scope's share-grant arm lowers to an engine-internal semi-join leaf over the record-share table,… | Proposed — 2026-11-15; questions ①–③ are open for the maintainer and are ⛔… | 2026-11-15 | — | — | ## ObjectUI registry — `ui/docs/adr/` (`ui-` prefix) From 066925797b26fdeeb283c30405722894d2d5fe29 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 19:09:39 +0000 Subject: [PATCH 2/7] =?UTF-8?q?docs(adr):=20ADR-0155=20fix=20round=201=20?= =?UTF-8?q?=E2=80=94=20seam=20recipient=20rule,=20no-grant=20plan=20pin,?= =?UTF-8?q?=20middleware=20row?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A text-only round on the record after its at-tier contract review. The record stays Proposed, and its three maintainer questions stay open. D4 decides the seam's recipient rule. The seam admits a composed share-grant leaf only when its recipient is the user of the context the operation runs under, or that context's delegator. A system context is the stated exemption. Any other recipient is a composition fault, answered with D4's refusal envelope. The reason is the one ADR-0139 already acts on: a composed scope is trusted only for the principal it was composed for. ADR-0147's anchor takes the same rule, because the seam is built once for both leaves. The open item that asked this question is removed. D6 gains two pins: the nested and the delegated positions, and the plan and timing of the list page and its total for a caller with no grant, on SQLite and on PostgreSQL, against today's statement. The middleware class D4 recognises becomes a row of Q2's census, with what each of the three answers does to it and a recommendation of its own. D4 no longer decides it in place. D5 keeps only the in-process matcher's answer for an `$in` whose comparand is not an array. The Revisits line and O7 say the ADR-0139 D3 pointer is owed under L as well as R2, name the card that carries the ADR-0139 notes, and drop a reason that no longer holds. Q2 points at D5's driver-memory row, which the maintainer may move under the same question. One-line corrections from the same review: the read scope's null answers, the organization stamp of a rule-materialised grant, the ADR-0131 citation, what a leaf compiles to outside its subquery, find hooks on the grant table, the update path on the driver-memory card, the seat constraint Q3's first form meets, and the statements that hold only under one answer to the third question. No other record is edited, and the index row is unchanged. Claude-Session: https://claude.ai/code/session_01ADHkmSrxgDeeJWnQpVfLcX Co-authored-by: Claude --- ...er-to-an-engine-internal-semi-join-leaf.md | 195 +++++++++++------- 1 file changed, 125 insertions(+), 70 deletions(-) diff --git a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md index fe0a08c7bce..d6b12dbe0c1 100644 --- a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md +++ b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md @@ -30,16 +30,20 @@ declares; it implements nothing.** [ADR-0049](./0049-no-unenforced-security-properties.md) (enforce-or-remove). - **Revisits**: ADR-0139 D1's "⛔ No second leaf", for one more leaf and nothing else. This is the second record to do so (ADR-0147 is the first), and the prohibition stays the default: a new leaf needs a Tier H record of its own. It - answers ADR-0139's open item O4, which names this read. Two further places move only if the maintainer rules that - way: ADR-0139 D1's read-verbs sentence (③) and, under one answer to ②, ADR-0139 D3's "⛔ No `DriverCapabilities` bit - returns" and ADR-0111 D7's list of inert grants. The dated pointer notes those records are owed are ⛔ not in this - record's diff ([O7](#open-items-not-blocking-acceptance-each-becomes-a-reading-on-its-card)). + answers ADR-0139's open item O4, which names this read. Three further places move only if the maintainer rules that + way: ADR-0139 D1's read-verbs sentence (under ③'s A); ADR-0139 D3's "⛔ No `DriverCapabilities` bit returns" (under + ②'s L or R2, each of which consults a driver declaration); and ADR-0111 D7's list of inert grants (under R2 alone). + The dated pointer notes those records are owed are ⛔ not in this record's diff: + [#34102](https://github.com/objectstack-ai/objectstack/issues/34102) carries ADR-0139's after acceptance + ([O7](#open-items-not-blocking-acceptance-each-becomes-a-reading-on-its-card)). - **Leaves unchanged**: every authorable surface (no operator, no CEL function, no object, permission-set or sharing-rule key, and no stored predicate to migrate); `sys_record_share`'s columns; its write path (grant, revoke, rule materialisation, the organization stamp), the by-id gates and share-management authority, which move only under one answer to ② and only on the objects that answer names; the owner match and its depth, the queue arm, the source of the approval arm, the external floor, the guest denial, the phantom-anchor narrowing and the delegation - intersection; the outer read's tenant wall; `ReadableIds` and its consumers; ADR-0147's leaf and its floor. + intersection; the outer read's tenant wall; `ReadableIds` and its consumers; ADR-0147's leaf and its floor. The + shared seam's recipient rule reads that leaf's anchor and changes nothing it carries + ([D4](#d4--the-engine-seam-and-what-is-built-once-with-adr-0147)). - **Consumers**: `@objectstack/spec` (the leaf's declaration, the comparand door's option, the conformance case-set, the `ISharingService` prose), `@objectstack/objectql` (the door and the executor seam), `@objectstack/driver-sql` and the drivers that inherit it, `@objectstack/driver-turso` (its remote transport), `@objectstack/driver-memory`, @@ -77,11 +81,12 @@ Three things are the maintainer's and are put, not decided: - **①** Whether the subquery carries a tenant scope. Today's grant read carries none. Recommended: none, which is parity. - **②** What an evaluator that cannot run a subquery answers: MongoDB, OData, an object on another datasource, the - analytics native-SQL compiler, the explainer. A materialised list, or a refusal. Recommended: no list anywhere. The - analytics compiler compiles the leaf and the explainer resolves it per record. On storage that cannot run a - subquery, share grants become unsupported: refused at the grant door and no longer counted, with a visible trail. - That takes away something that works there today, and [Q2](#q2--an-evaluator-that-cannot-run-the-leaf) says - exactly what. + analytics native-SQL compiler, the explainer, and with them one host class: a middleware on the grant table, which + the subquery would read around. A materialised list, or a refusal. Recommended: no list anywhere. The analytics + compiler compiles the leaf and the explainer resolves it per record. On storage that cannot run a subquery, share + grants become unsupported: refused at the grant door and no longer counted, with a visible trail. That takes away + something that works there today, and [Q2](#q2--an-evaluator-that-cannot-run-the-leaf) says exactly what. For the + host class the recommendation is a refusal at boot, until the registration is removed. - **③** `buildWriteFilter` feeds a predicate `update`, and ADR-0139 D1 admits a leaf on read verbs only. Recommended: admit this leaf's write form on `update`, and nowhere else. @@ -110,18 +115,22 @@ Three things are the maintainer's and are put, not decided: the standing principle quoted under Q2). - **This record's own reading** is of `origin/main` `b8ac0e24`. The card's was of `45dee177`. The premise holds on both, and [What this reading adds](#what-this-reading-adds-to-the-cards) lists where the newer reading is more exact. + The sentences added after the at-tier review of this record + ([`6899302526`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6899302526)) were read on + `origin/main` `27c2f1ea`. ## Context ### The mechanism today (read on `origin/main` `b8ac0e24`) - **The read scope.** `packages/plugins/plugin-sharing/src/sharing-service.ts#buildReadFilter` answers `null` (no - restriction) for a bypass or system context, an object whose org-wide default is not private for this principal, - an object with no owner field, and an `org` read depth. It answers the deny sentinel for the guest and for a context - with no user id. Otherwise it composes `{ $or: [ownerMatch, queueMatch, { id: { $in: grantedIds } }] }`: the queue - disjunct is there when the object has a queue column and the caller sits in a queue, the `$in` disjunct only when - the list is not empty, and the owner match stands alone when neither is. A federated object whose owner column is - the platform's injected anchor takes neither the owner arm nor the share arm + restriction) for a bypass or system context, an object with no registered schema, an object whose org-wide default + is not private for this principal, an object with no owner field, and an `org` read depth. It answers the deny + sentinel for the guest and for a context with no user id. Otherwise it composes + `{ $or: [ownerMatch, queueMatch, { id: { $in: grantedIds } }] }`: the queue disjunct is there when the object has a + queue column and the caller sits in a queue, the `$in` disjunct only when the list is not empty, and the owner match + stands alone when neither is. A federated object whose owner column is the platform's injected anchor takes neither + the owner arm nor the share arm (`packages/plugins/plugin-sharing/src/federated-phantom-anchors.ts#hasPhantomOwnerAnchor`). - **The grant read.** One `find` of `sys_record_share` with `{ object_name, recipient_type: 'user', recipient_id }`, of which it uses `record_id`, at `limit: 5000`, with no ordering, under @@ -157,8 +166,10 @@ Three things are the maintainer's and are put, not decided: `recipient_type: 'user'` rows are written and enforced (ADR-0111 D7). The index `(object_name, recipient_type, recipient_id)` serves the grant read. A direct grant stamps the row's organization from the shared record, or from the acting session for a record that carries none - (`packages/plugins/plugin-sharing/src/sharing-service.ts#resolveDirectGrantOrganization`); a rule-materialised grant - carries its rule's. No access gate reads the stamp. + (`packages/plugins/plugin-sharing/src/sharing-service.ts#resolveDirectGrantOrganization`). A rule-materialised grant + carries its rule's, or the record's where the rule is platform-global and has none + (`packages/plugins/plugin-sharing/src/sharing-service.ts#resolveSystemGrantOrganization`). No access gate reads the + stamp. - **The term used below.** An operation is *sharing-scoped* when one of the two builders composes such a filter for it: the object has an owner field, the caller is below `org` depth, and the object is not open to the caller on that side (a `private` model for a read; a `private` or `public_read` model for a predicate update; for an external @@ -200,11 +211,13 @@ Three things are the maintainer's and are put, not decided: - **Every addressed predicate write is already narrowed to the rows the read door returns**, at most 10,000 of them, with a loud refusal above (`packages/plugins/plugin-security/src/security-plugin-addressed-writes.ts#readableRowsScopeForPredicateWrite`, `packages/plugins/plugin-security/src/security-plugin.ts#PREDICATE_WRITE_READABLE_ID_CAP`). That bounds the rows a - predicate update touches. It does not evaluate the share arm. + predicate update touches. The narrowing is a read through the read door, so it carries the read scope's share arm. + What it leaves out is the write scope's. - **"Share rows can carry a NULL organization" is narrower than it reads.** ADR-0131 D1 makes NULL not a state, and - it names a record share among the rows that carry their organization, NOT NULL. What remains is ADR-0131's own - exceptions: a lean embedding that registers no organization object, and rows an uncertified database still holds. - The parity argument under ① does not rest on those rows: today's grant read consults no organization at all. + that record's TL;DR (item 2) and D3 name a record share among the rows that carry their organization, NOT NULL. + What remains is ADR-0131's own exceptions: a lean embedding that registers no organization object, and rows an + uncertified database still holds. The parity argument under ① does not rest on those rows: today's grant read + consults no organization at all. - **The share disjunct becomes universal.** Today it is present only for a caller who holds a grant or a pending approval. As a leaf it is present on every sharing-scoped operation, so an evaluator's answer to ② is met by nearly every member read of such an object, not by grantees alone. @@ -251,7 +264,8 @@ Name the set once, so every later sentence can point at it: properties, as `ReadableIds`' object name is, so two users' leaves never compare or serialise as equal; only the brand is non-enumerable. The rest of its representation is the spec card's. - **The recipient is the producer's.** It is captured from the context the scope is built for, where today's - `recipient_id` comes from. ⛔ No seam and no driver re-derives it from the reading context. + `recipient_id` comes from. ⛔ No seam and no driver re-derives it from the reading context. The seam checks it + against that context and never replaces it ([D4](#d4--the-engine-seam-and-what-is-built-once-with-adr-0147)). - **It arrives composed.** It asks no security service and composes no scope, so the engine's executor seam passes it through ([D4](#d4--the-engine-seam-and-what-is-built-once-with-adr-0147)). - **Position.** It is legal only as the `$in` comparand of `id` on the object it names: directly in that object's @@ -345,18 +359,33 @@ After the switch the read scope is: read scope on to the engine (`packages/services/service-analytics/src/read-scope-sql.ts#assertReadScopeComparandsRunnable`). The engine's door admits this brand the same way. The analytics merges are a row of ②. ⛔ No other caller admits it. - **Pass-through.** At the executor boundary (`packages/objectql/src/engine.ts#composeReadableIdsAtBoundary`) there is - nothing to compose. The seam checks position and verb (D1) and hands the leaf to the driver as it stands. + nothing to compose. The seam checks position and verb (D1) and the recipient (next), and hands the leaf to the + driver as it stands. +- **The recipient rule.** The seam admits the leaf only when its recipient is the user of the context the operation + runs under (the reading context; under ③, the predicate update's), or that context's delegator (ADR-0090 D10). Those + are the two identities D3 writes a leaf for. A system context is the one exemption, and it is stated here: it is the + platform's own code, it already holds every authority, and it may carry a scope composed for any principal. Any + other recipient is a composition fault, answered with the refusal below. The reason is one ADR-0139 already acts + on: a composed scope is trusted only for the principal it was composed for. `ReadableIds` keeps that by + construction. The engine composes it for the reading caller on every request (its D2), and no door admits a leaf + that arrives composed (`packages/spec/src/data/readable-ids.ts#ComposedReadableIds`). This leaf arrives composed + (D1), so the seam keeps the same rule by a check. The check compares, and ⛔ it never replaces the recipient (D1). It + holds at every occurrence the seam descends to, on the write form as on the read form. It is the seam's rule alone: + an in-process judge that is handed another principal's scope, as the explainer is, reaches no seam. ADR-0147's + anchor takes the same rule for its caller, because the seam is built once for both leaves (below). - **Every occurrence, nested ones included.** The scope the engine composes for a `ReadableIds` leaf is the security service's read filter for the parent (`packages/objectql/src/engine-readable-ids-permission-formula.ts#composeReadableIdsChain`), and for a sharing-scoped parent that filter carries this leaf. The seam's checks descend into composed scopes. `driver-sql` compiles a composed scope with the same compiler, so the leaf compiles there too. - **Two classes the seam recognises before the driver call.** The first is an object bound to another datasource than - `sys_record_share` (`packages/objectql/src/engine.ts#resolveDatasourceBinding`); what it answers is ②. The second is - ADR-0139 D5.2's class: an object-scoped middleware registered for `sys_record_share` + `sys_record_share` (`packages/objectql/src/engine.ts#resolveDatasourceBinding`). The second is ADR-0139 D5.2's + class: an object-scoped middleware registered for `sys_record_share` (`packages/objectql/src/engine.ts#hasObjectMiddleware`), which today's grant read passes through and the subquery - would read around. No package in this repository registers one. Where a host does, the seam refuses the leaf rather - than read around the middleware, and every sharing-scoped operation on that host fails until the registration is - removed. Hosts outside this repository were not read (O8). + would read around. ⛔ The seam never reads around it. What each class answers is ②, and each is a row of Q2's + census. No package in this repository registers such a middleware, and hosts outside it were not read (O8). Today's + grant read also runs the `beforeFind` and `afterFind` hooks registered for the table, and the subquery runs none. + The class is drawn at middleware, where ADR-0139 D5.2 draws it. No package here registers such a hook for the + table by name, and O8's census looks for both. - **The refusal** is ADR-0139 D3's envelope wherever it occurs: status 500, `INTERNAL_ERROR`, a message naming the evaluator, the leaf and the remedy, logged at `error` once per evaluator (`packages/core/src/utils/readable-ids-driver-refusal.ts#refuseReadableIdsOnce` is the device). ⛔ It is not @@ -371,8 +400,9 @@ recommended answer). That is one mechanism: |:--|:--| | The brand, its factory and guard, its meaning, its producer | per leaf, never shared: one brand, one meaning | | The comparand door's admission of engine-internal comparands | once, as one option that names the brands it admits, not one flag per brand | -| The executor seam's pass-through, its position and verb checks, its descent into composed scopes | once | +| The executor seam's pass-through, its position and verb checks, its recipient rule, its descent into composed scopes | once. The recipient rule reads this leaf's recipient and the caller of ADR-0147's anchor | | The fixed inner read: one table, one projected column, a closed set of bound equality and membership predicates, the blank-id guard, system authority, and the tenant scope each record rules for its leaf (none in ADR-0147 D-b; ① here) | once per evaluator (`driver-sql`, the Turso remote transport, `driver-memory`, and the analytics native compiler if ② rules that it compiles). Each leaf supplies its description, and no evaluator restates either leaf's predicate by hand | +| What a leaf compiles to outside its subquery | per leaf. ADR-0147 ORs its caller arm in, and issues no subquery when no organization is active (its D-a and D-c). This leaf is the subquery alone | | The refusal envelope and its once-per-evaluator log | once | | The conformance case-set | once, with a case per leaf | | A driver's declaration that it evaluates such leaves | once, if either record consults one. ADR-0147 D-d does. This record does under every answer to ② but R1 | @@ -380,15 +410,17 @@ recommended answer). That is one mechanism: - **Sequencing.** Whichever record's cards are cut first build the shared pieces in the two-leaf shape, and the other record's cards add their leaf on top. ⛔ Neither builds a private copy. -- **This record does not revisit ADR-0147.** Its floor was chosen for a leaf whose refusal would fail every `sys_user` - read. Whether the SQL-first rule changes that answer is that record's question (O6). +- **This record does not revisit ADR-0147's decisions.** The recipient rule is the shared seam's: it checks that + record's anchor, and it changes neither what the anchor carries nor where it is captured (its D-a and D-c). + ADR-0147's floor was chosen for a leaf whose refusal would fail every `sys_user` read, and whether the SQL-first + rule changes that answer is that record's question (O6). ### D5 — The evaluator census One rule holds for every evaluator, whatever ② rules: **an evaluator evaluates the leaf exactly, or refuses it -loudly. ⛔ It never reads it as an ordinary comparand.** The in-process matcher shows why. +loudly. ⛔ It never reads it as an ordinary comparand.** The in-process matcher shows why: `packages/formula/src/matches-filter.ts#matchesFilterCondition` answers `false` for an `$in` whose comparand is not an -array, so an unrecognised leaf reads as "matches no record", and under `$not` as "matches every record". +array, where this rule asks for a refusal. Three rows are not in question: @@ -404,7 +436,8 @@ principle quoted under ② names memory beside MongoDB, so the maintainer may mo there is that every suite which exercises record sharing on `driver-memory` moves to SQLite. The rest of the census is ②: `driver-mongodb`, `driver-odata`, a driver this repository does not ship, an object on -another datasource, the analytics read-scope compilers, and the explainer's record pass. +another datasource, the analytics read-scope compilers, the explainer's record pass, and the host class D4 +recognises. ### D6 — What the switch must show @@ -419,6 +452,16 @@ body; `6893239331` item 2): - **Ablated**, as the seat's constraint asks. - **The speed figure** is quoted as [What it costs](#what-it-costs) quotes it, and no wider. +This record adds two more: + +- **The nested and the delegated positions.** The leaf inside a composed `ReadableIds` scope (D4), and the pair of + leaves a delegated operation carries (D3), answer the rows today's lists answer below the cap. +- **The caller with no grant.** This statement changes shape most. For a caller who holds no grant and no pending + approval, and sits in no queue, today's scope is the bare owner match. After the switch it is an `$or` with the + subquery arm, on every list page and its total. The driver card reads the plan and the timing of that page and its + total on SQLite and on PostgreSQL, against today's statement, and says whether the planner still serves it from the + owner index. The switch quotes that reading. It is not measured here. + ## Questions for the maintainer Each question states today's fact, the options, what each option costs, and a recommendation. Until the maintainer @@ -442,8 +485,8 @@ narrows G by the grant row's stamp: - Under `isolated` and `group`, a grant stamped outside the reader's scope stops counting. Where the stamp is the record's own organization (a direct grant on an object with a tenant column), nothing visible changes: the outer wall already decides that record. Where the two can differ (a grant on an object with no tenant column, stamped - with the granting session's organization; a rule-materialised grant, stamped with its rule's organization and not - the record's), a reader whose scope excludes the stamp loses a record they read today. + with the granting session's organization; a grant materialised by a rule that has an organization, stamped with the + rule's and not the record's), a reader whose scope excludes the stamp loses a record they read today. - A grant row with no organization stops counting wherever a tenant scope applies. ADR-0131 D1 leaves such rows to an uncertified database. - The by-id gates and the explainer would have to take the same wall in the same change, or the list and the by-id @@ -468,6 +511,8 @@ in the scope builders looks at where the object is stored, the phantom-anchor ru Directive 5 states the rule in force (ruling record `6888468549`): "build a query capability at its fastest SQL shape (JOIN or semi-join, aggregates in the database); memory and mongo refuse what they cannot run with a stable code; ⛔ never a slower path built only for parity". ADR-0147 D-d chose the other way for its leaf, an exact-array floor. +The principle names memory, and `driver-memory`'s row is decided in [D5](#d5--the-evaluator-census), outside the +census below: the maintainer may move this row under ② as well, at the cost D5 states. **The three answers an evaluator can give.** @@ -484,7 +529,8 @@ never a slower path built only for parity". ADR-0147 D-d chose the other way for **The census.** The by-id sharing verdicts are not in it: they read one record's grant rows and never receive the leaf (`packages/plugins/plugin-security/src/security-plugin-sharing-verdicts.ts#resolveSharingCanEdit`). In the table, -"such an object" is one a caller's operations are sharing-scoped on. +"such an object" is one a caller's operations are sharing-scoped on. One row is not an evaluator: the host class D4 +recognises second. It is here because the same three answers apply to it. | Evaluator | If it keeps a list (L) | If it refuses | Recommended | |:--|:--|:--|:--| @@ -492,6 +538,7 @@ leaf (`packages/plugins/plugin-security/src/security-plugin-sharing-verdicts.ts# | `driver-odata` (`packages/drivers/driver-odata/src/odata-driver.ts#refuseReadableIds`) | As above; the backend's own ceiling is its request length | As above | **R2**, with R1 behind it | | A driver this repository does not ship | As above, unless it declares that it evaluates the leaf | As above | **R2**, with R1 behind it | | An object bound to another datasource than `sys_record_share`. That includes a federated object that declares a real remote owner column, which keeps its shares today (`packages/plugins/plugin-sharing/src/sharing-service.ts#inertGrantReason`) | As above | As above | **R2**, with R1 behind it | +| A host that registers an object-scoped middleware for `sys_record_share` (D4's second class). Today's grant read passes through the middleware, and the subquery would not. No package in this repository registers one | The list is read through the engine, so the middleware still runs and what works today keeps working, up to the bound. The SQL family keeps a list path for this class | **R1**: every sharing-scoped read and predicate update on that host fails with 500 until the registration is removed. A boot check can name the registration and refuse the boot before any request is served, as ADR-0139 D5's seventh-consumer note has the boot refuse the same class. A registration made after boot still meets the seam's refusal at read. **R2**: record sharing is unsupported on that host. No object takes a share arm, grants stop counting and are refused at both doors, and owner, queue and approval access is unchanged | **R1, at boot**, with the seam's refusal behind it | | The analytics native-SQL compiler (`packages/services/service-analytics/src/read-scope-sql.ts#compileScopedFilterToSql`). Today it binds one parameter per `$in` member and refuses `ReadableIds` at entry | The cap, or an unbounded list, returns on this path | It declines the query to the engine strategy, as it does for `ReadableIds` (`packages/services/service-analytics/src/strategies/native-sql-strategy.ts#readScopeCarriesReadableIds`). With the leaf on every sharing-scoped read, that is nearly every member query on such an object, and the shapes only native SQL serves, such as a multi-hop join (`packages/services/service-analytics/src/strategies/cross-object-where.ts#UnservedCrossObjectReason`), are then refused | **Neither: it compiles the leaf.** It is SQL, and the leaf needs no composition | | The analytics engine strategy's merge and the dry-run SQL echo | not applicable | Unless its merge admits the brand (`packages/services/service-analytics/src/read-scope-sql.ts#assertReadScopeComparandsRunnable`), every query it serves on such an object is refused | **It admits the brand** and hands the scope to the engine, as it does `ReadableIds`. The echo prints the subquery the statement runs | | The explainer's record pass (`packages/plugins/plugin-security/src/explain-engine.ts#matchUnderDeclaredColumns`). Today it matches the list in process and publishes it as the sharing layer's `rowFilter` (`packages/spec/src/security/explain.zod.ts#ExplainRecordAttributionSchema`) | It materialises the caller's whole grant list for each explanation, and the published filter grows with it | The record pass matches the sharing read filter for every record-grained explanation, whatever the verb. So each one on such an object fails, on every driver, and with it the attachment and comment gates that ask the explainer for a parent record's by-id judgement | **Neither: it resolves the leaf at the record.** One indexed read under the fixed predicate, keyed by the record ids it judges, the read `checkEdit` makes for one | @@ -503,6 +550,11 @@ leaf (`packages/plugins/plugin-security/src/security-plugin-sharing-verdicts.ts# boot of the objects that hold such rows, the refusal at both doors, the explainer's sentence and a changelog entry: ADR-0111 D10's "tighten directly, fail closed, with a visible trail". This reading has no census of deployments that hold such grants; that report is the instrument. +- **A host in the middleware row does not start until it removes the registration.** That row is recommended as R1 + on purpose, and it is an outage by choice. The condition is one registration the host can remove, where a storage + row leaves the host no remedy. The boot names it before any request is served. R2 there would switch record + sharing off on every object while the host kept serving. The class is empty in this repository, and O8's census + says whether a host outside it is in the class. - **It consults a driver declaration**, so ADR-0139 D3's "⛔ No `DriverCapabilities` bit returns" is revisited for this leaf as ADR-0147 D-d revisits it for its own, and ADR-0111 D7 gains an arm. - **A later compile lifts R2 for that evaluator** with no amendment here: a `$lookup` form on MongoDB (O9), or a @@ -517,15 +569,16 @@ sharing on those evaluators. It is the simplest reading of the rule and needs no price. Writing the leaf only for a caller who holds a grant would confine the outage to grantees, at the price of the per-operation read this record removes, and a grantee would still lose every read of the object. Under the recommendation R1 stays as the backstop: a leaf that reaches an evaluator that cannot run it is refused, never -dropped. +dropped. The middleware row is the one row recommended as R1 itself, and its cost above says why. **Why not L.** It is the slower path built only for parity. It keeps a second evaluation path in the engine (the declaration, the substitution, its descent into composed scopes, a completion read per operation) for backends the principle says not to be compatible with for compatibility's sake, and its bound is a cap again. Its merit is real and is stated: L is the one answer under which nothing that works today stops working. -**Recommendation.** No list anywhere. The storage rows take **R2** with R1 behind it, the analytics compilers compile -or admit, and the explainer resolves at the record. The maintainer may rule row by row. +**Recommendation.** No list anywhere. The storage rows take **R2** with R1 behind it, the middleware row takes **R1** +at boot, the analytics compilers compile or admit, and the explainer resolves at the record. The maintainer may rule +row by row. ### Q3 — The leaf on a predicate update @@ -545,11 +598,11 @@ carries the same predicate. ADR-0139 D1 states its read-verbs rule without a rea write form denotes a write scope: the records shared with the caller at a write level. The cost is one more governed sentence revisited: ADR-0139 D1's read-verbs sentence, for this leaf alone. -**Option B — keep the leaf read-only, and a list on the write side.** It has three forms, and each meets a ruling -already made: +**Option B — keep the leaf read-only, and a list on the write side.** It has three forms. The first meets a seat +constraint, and the other two each meet a ruling already made: - today's capped read, unchanged: the predicate-update half of #33787 stays, against the seat's constraint that - "`buildWriteFilter` takes the same shape"; + "`buildWriteFilter` takes the same shape" (`6893239331` item 1); - a complete list: the unbounded `$in` that ruling `6097072172` did not take, with the dialect's bind ceiling as the new cliff; - a bounded list that refuses loudly past its bound: the cap kept and made loud, the interim shape 「只做根治」 ruled @@ -560,25 +613,27 @@ write to the rows the read door returns, at most 10,000, so the write scope coul It is exact, and it is not recommended: it ties plugin-sharing's scope to another plugin's middleware order, a composition without that plugin has no candidate list, and it binds up to 10,000 ids in a second read. -**Recommendation: A.** The code leaves a fork, and the standing rulings close all of it but one branch: every form -of B contradicts one of them. What remains is that A changes a governed sentence of ADR-0139, and that is the -maintainer's to change. The 10,000-row bound on an addressed predicate write stays where it is: this leaf adds no -bound and removes none. +**Recommendation: A.** The code leaves a fork, and the seat's constraint and the standing rulings close all of it but +one branch: every form of B contradicts one of them. What remains is that A changes a governed sentence of ADR-0139, +and that is the maintainer's to change. The 10,000-row bound on an addressed predicate write stays where it is: this +leaf adds no bound and removes none. ## Consequences - **Positive.** Every grant counts on the SQL family, at any count. The cap and its silent cut are gone, not raised. A sharing-scoped operation issues no grant read of its own, its statement's parameters no longer grow with the grants, and a `controlled_by_parent` read no longer binds the list again inside the parent's subquery. The arm is - part of one statement, so `find`, `count` and `aggregate` agree by construction. + part of one statement, so `find`, `count` and `aggregate` agree by construction. For a predicate update each of + these holds under ③'s A; under B the write side keeps a list. - **Cost, named.** Spec gains one more branded comparand. The engine's door and seam and three evaluators gain its handling. Every sharing-scoped read carries an index-backed subquery, for a caller with no grant too, where today - it carried one extra read and no arm. + it carried one extra read and no arm. D6 pins that statement's plan and timing. - **Failure surface.** Unchanged in direction. Today a failing grant read fails the operation before its statement; - after the switch the same failure is the statement's. -- **Freshness.** The arm is read at statement time (D2). On a predicate update the prior-row read and the write are - two statements, and each evaluates the share arm for itself, as each already evaluates the owner match for itself. - Today's list is read once, before both. + after the switch the same failure is the statement's. One refusal is new: the seam's recipient rule (D4). It + answers a composition fault, and no flow read in this repository meets it. +- **Freshness.** The arm is read at statement time (D2). Under ③'s A, a predicate update's prior-row read and its + write are two statements, and each evaluates the share arm for itself, as each already evaluates the owner match + for itself. Today's list is read once, before both. - **A public contract's answer changes kind.** `buildReadFilter` is a member of `packages/spec/src/contracts/sharing-service.ts#ISharingService`. Its answer now carries an engine-internal leaf, so it is handed to the engine in process, ⛔ never serialised and never matched by a generic matcher. The spec card @@ -628,25 +683,23 @@ bound and removes none. - **O6** — ADR-0147's floor and the SQL-first rule point different ways. This record does not revisit that one. If ② is ruled a refusal, the two leaves differ on evaluators that cannot compile, and D4's table already builds for it. - **O7** — Pointer notes owed on acceptance, each dated and append-only, in a governed edit of their own: ADR-0139 D1 - (one more leaf, and the read-verbs sentence if ③ is ruled A); ADR-0139 O4 (answered); ADR-0139 D3 and ADR-0111 D7 - (only under ②'s R2); and a cross-reference from ADR-0147 D-a for the shared seam. They are not in this record's - diff, which adds this record and its index row and edits no other record: ADR-0139 was under amendment by another - change while this record was written (PR #33992, its D6 and its Status line). + (one more leaf, and the read-verbs sentence if ③ is ruled A); ADR-0139 O4 (answered); ADR-0139 D3 (under ②'s L or + R2, each of which consults a driver declaration); ADR-0111 D7 (only under R2); and a cross-reference from ADR-0147 + D-a for the shared seam and its recipient rule. [#34102](https://github.com/objectstack-ai/objectstack/issues/34102) + carries the ADR-0139 notes once this record lands and ①, ② and ③ are ruled, because some of them depend on a + ruling. The ADR-0111 and ADR-0147 notes ride with it or take a governed edit of their own. None is in this + record's diff, which adds this record and its index row and edits no other record. - **O8** — Readers of `buildReadFilter` and of the security service's read filter outside this repository (the cloud repository's packages) were not read from this tree, and neither was any host that registers an object-scoped - middleware for `sys_record_share` (D4). The switch card owes that census before it lands. + middleware or a find hook for `sys_record_share` (D4). The switch card owes that census before it lands. - **O9** — `driver-mongodb`: a `$lookup` form is unprototyped (shared with ADR-0139 O3 and ADR-0147 O2). -- **O10** — A guard the leaf makes possible. A list carries no identity, and the leaf names its recipient. Whether the - seam verifies that recipient against the reading context (the caller, or the delegator of an on-behalf-of - operation) is the engine card's reading. It would catch a scope reused across requests. ⛔ It never replaces the - recipient (D1), and it must not refuse the explainer's judgement of another principal, which reaches no driver. ## Acceptance criteria - The maintainer approves this record (`GOVERNED_APPROVERS`, Tier H) and rules ①, ② and ③. The rulings are recorded in this record, in its Status line and in the three question sections, each citing its ruling record, before any execution card is cut. -- O7's pointer notes land in their own governed edit. +- O7's pointer notes land in their own governed edit; #34102 carries ADR-0139's. - The switch meets [D6](#d6--what-the-switch-must-show). - At every step D-0 holds on every evaluator that evaluates the leaf, and every other evaluator answers as ② ruled. @@ -658,13 +711,15 @@ The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ② 1. **Spec: the leaf.** The brand, its factory and guard beside `ReadableIds`; the comparand door's option; the fixed inner read's description; the conformance case-set; the `ISharingService` prose. The shared pieces take the two-leaf shape (D4). -2. **Engine: the seam.** Door admission, pass-through, the position rule and the verb rule (③ as ruled), the two - recognised classes, the descent into composed scopes, the refusal, and the declaration's consult if ② rules one. +2. **Engine: the seam.** Door admission, pass-through, the position rule, the verb rule (③ as ruled) and the + recipient rule, the two recognised classes (② as ruled), the descent into composed scopes, the refusal, and the + declaration's consult if ② rules one. The recipient rule is pinned on its four cases: the context's user, its + delegator, a system context, and any other recipient, which is refused. 3. **`driver-sql` and the Turso remote transport: the compile.** The subquery and its tenant scope (① as ruled), the - update path (③ as ruled), the pins per dialect, O2 and O3. -4. **`driver-memory`: the in-process evaluation.** -5. **The rest of the census, as ② is ruled**: the storage rows' refusal for this brand, the analytics compilers, the - explainer's record pass. + update path (③ as ruled), the pins per dialect, O2, O3, and D6's reading for a caller with no grant. +4. **`driver-memory`: the in-process evaluation**, on reads and on the update path (③ as ruled). +5. **The rest of the census, as ② is ruled**: the storage rows' refusal for this brand, the middleware row's answer + (the boot check, under the recommended one), the analytics compilers, the explainer's record pass. 6. **plugin-sharing: the switch.** `buildReadFilter` and `buildWriteFilter` write the leaf, the approval ids become a disjunct of their own, and under R2 the inert arm and its report land here, at the moment those grants stop counting. The middleware also mirrors its scope under the AST's `filter` key, which the executor seam does not walk From 1f6f9718d9177cad93d000114711e7a6b4de21bb Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 20:22:16 +0000 Subject: [PATCH 3/7] =?UTF-8?q?docs(adr):=20ADR-0155=20fix=20round=202=20?= =?UTF-8?q?=E2=80=94=20boot=20check=20on=20the=20switch=20card,=20full=20i?= =?UTF-8?q?dentity=20check=20at=20the=20shared=20seam?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A text-only round on the record after its delta contract review. The record stays Proposed, and its three maintainer questions stay open. The host row's boot check moves to the switch card. Until a producer writes the leaf, today's grant read still runs a registration on the grant table and nothing reads around it, so no card before the switch refuses a boot. The census of hosts and outside readers is read before the switch card is cut. The TL;DR, Q2's row, its cost list, its recommendation, the open item and the execution plan say the same. D4 states in full what the shared seam checks on ADR-0147's anchor. One rule holds for both leaves: every identity named by a leaf that arrives composed is compared with the reading context. This record's leaf names its recipient. ADR-0147's anchor names its caller and its organization, and the organization must be the reading context's active organization. A system context is the one exemption, and any mismatch is the composition fault D4 already answers. ADR-0147 takes this through its cross-reference note, which lands with this record's other pointer notes. The class D4 recognises second covers a find hook registered for the grant table by name as well as an object-scoped middleware. The census looks for both kinds, and the boot check names either. The pointer notes land with the governed edit that records the maintainer's rulings in this record's Status line, which the first acceptance criterion already requires. The record names no other carrier. D4 also says why the seam's position, verb and recipient checks hold by construction on the analytics native-SQL path, which has no seam in front of it. Consequences names option C beside B for the write side, and the precondition the recipient rule gives the documented use of the security service's read filter. The spec card's prose list and the Consumers field name that contract. No other record is edited, and the index row is unchanged. Claude-Session: https://claude.ai/code/session_01ADHkmSrxgDeeJWnQpVfLcX Co-authored-by: Claude --- ...er-to-an-engine-internal-semi-join-leaf.md | 140 ++++++++++-------- 1 file changed, 82 insertions(+), 58 deletions(-) diff --git a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md index d6b12dbe0c1..117e08bb194 100644 --- a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md +++ b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md @@ -33,8 +33,8 @@ declares; it implements nothing.** answers ADR-0139's open item O4, which names this read. Three further places move only if the maintainer rules that way: ADR-0139 D1's read-verbs sentence (under ③'s A); ADR-0139 D3's "⛔ No `DriverCapabilities` bit returns" (under ②'s L or R2, each of which consults a driver declaration); and ADR-0111 D7's list of inert grants (under R2 alone). - The dated pointer notes those records are owed are ⛔ not in this record's diff: - [#34102](https://github.com/objectstack-ai/objectstack/issues/34102) carries ADR-0139's after acceptance + The dated pointer notes those records are owed are ⛔ not in this record's diff: they land with the governed edit + that records the maintainer's rulings in this record's Status line ([O7](#open-items-not-blocking-acceptance-each-becomes-a-reading-on-its-card)). - **Leaves unchanged**: every authorable surface (no operator, no CEL function, no object, permission-set or sharing-rule key, and no stored predicate to migrate); `sys_record_share`'s columns; its write path (grant, revoke, @@ -45,11 +45,12 @@ declares; it implements nothing.** shared seam's recipient rule reads that leaf's anchor and changes nothing it carries ([D4](#d4--the-engine-seam-and-what-is-built-once-with-adr-0147)). - **Consumers**: `@objectstack/spec` (the leaf's declaration, the comparand door's option, the conformance case-set, - the `ISharingService` prose), `@objectstack/objectql` (the door and the executor seam), `@objectstack/driver-sql` - and the drivers that inherit it, `@objectstack/driver-turso` (its remote transport), `@objectstack/driver-memory`, - `@objectstack/driver-mongodb`, `@objectstack/driver-odata`, `@objectstack/service-analytics` (its read-scope - compilers), `@objectstack/plugin-security` (the read filter that carries the leaf; the explainer's record pass) and - `@objectstack/plugin-sharing` (the one producer, and the switch). + the `ISharingService` and `ISecurityService` prose), `@objectstack/objectql` (the door and the executor seam), + `@objectstack/driver-sql` and the drivers that inherit it, `@objectstack/driver-turso` (its remote transport), + `@objectstack/driver-memory`, `@objectstack/driver-mongodb`, `@objectstack/driver-odata`, + `@objectstack/service-analytics` (its read-scope compilers), `@objectstack/plugin-security` (the read filter that + carries the leaf; the explainer's record pass) and `@objectstack/plugin-sharing` (the one producer, and the + switch). --- @@ -81,12 +82,13 @@ Three things are the maintainer's and are put, not decided: - **①** Whether the subquery carries a tenant scope. Today's grant read carries none. Recommended: none, which is parity. - **②** What an evaluator that cannot run a subquery answers: MongoDB, OData, an object on another datasource, the - analytics native-SQL compiler, the explainer, and with them one host class: a middleware on the grant table, which - the subquery would read around. A materialised list, or a refusal. Recommended: no list anywhere. The analytics - compiler compiles the leaf and the explainer resolves it per record. On storage that cannot run a subquery, share - grants become unsupported: refused at the grant door and no longer counted, with a visible trail. That takes away - something that works there today, and [Q2](#q2--an-evaluator-that-cannot-run-the-leaf) says exactly what. For the - host class the recommendation is a refusal at boot, until the registration is removed. + analytics native-SQL compiler, the explainer, and with them one host class: a middleware or a find hook registered + for the grant table by name, which the subquery would read around. A materialised list, or a refusal. Recommended: + no list anywhere. The analytics compiler compiles the leaf and the explainer resolves it per record. On storage + that cannot run a subquery, share grants become unsupported: refused at the grant door and no longer counted, with + a visible trail. That takes away something that works there today, and + [Q2](#q2--an-evaluator-that-cannot-run-the-leaf) says exactly what. For the host class the recommendation is a + refusal at boot from the switch on, until the registration is removed. - **③** `buildWriteFilter` feeds a predicate `update`, and ADR-0139 D1 admits a leaf on read verbs only. Recommended: admit this leaf's write form on `update`, and nowhere else. @@ -117,7 +119,8 @@ Three things are the maintainer's and are put, not decided: both, and [What this reading adds](#what-this-reading-adds-to-the-cards) lists where the newer reading is more exact. The sentences added after the at-tier review of this record ([`6899302526`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6899302526)) were read on - `origin/main` `27c2f1ea`. + `origin/main` `27c2f1ea`, and those added after its delta review + ([`6900428326`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6900428326)) on `385ea1cc`. ## Context @@ -371,21 +374,32 @@ After the switch the read scope is: that arrives composed (`packages/spec/src/data/readable-ids.ts#ComposedReadableIds`). This leaf arrives composed (D1), so the seam keeps the same rule by a check. The check compares, and ⛔ it never replaces the recipient (D1). It holds at every occurrence the seam descends to, on the write form as on the read form. It is the seam's rule alone: - an in-process judge that is handed another principal's scope, as the explainer is, reaches no seam. ADR-0147's - anchor takes the same rule for its caller, because the seam is built once for both leaves (below). + an in-process judge that is handed another principal's scope, as the explainer is, reaches no seam. Under ②'s + recommended answer the analytics native-SQL compiler compiles the leaf with no seam in front of it, and the seam's + position, verb and recipient checks hold there by construction: one strategy context, built per request + (`packages/services/service-analytics/src/analytics-service.ts#callCtx`), asks for the scope under the request's + context and issues the statement that carries it. +- **The same rule on ADR-0147's anchor, in full.** The seam is built once for both leaves (below), and it holds one + rule for both: every identity named by a leaf that arrives composed is compared with the reading context. This + leaf names one, its recipient. ADR-0147's anchor names two, and the seam checks both: its caller, which like a + recipient must be the reading context's user or that context's delegator, and its organization, which must be the + reading context's active organization. A system context is the same one exemption, and any mismatch is the same + composition fault, answered with the refusal below. ADR-0147 takes this through its cross-reference note (O7), + which lands with this record's other pointer notes. - **Every occurrence, nested ones included.** The scope the engine composes for a `ReadableIds` leaf is the security service's read filter for the parent (`packages/objectql/src/engine-readable-ids-permission-formula.ts#composeReadableIdsChain`), and for a sharing-scoped parent that filter carries this leaf. The seam's checks descend into composed scopes. `driver-sql` compiles a composed scope with the same compiler, so the leaf compiles there too. - **Two classes the seam recognises before the driver call.** The first is an object bound to another datasource than - `sys_record_share` (`packages/objectql/src/engine.ts#resolveDatasourceBinding`). The second is ADR-0139 D5.2's - class: an object-scoped middleware registered for `sys_record_share` - (`packages/objectql/src/engine.ts#hasObjectMiddleware`), which today's grant read passes through and the subquery - would read around. ⛔ The seam never reads around it. What each class answers is ②, and each is a row of Q2's - census. No package in this repository registers such a middleware, and hosts outside it were not read (O8). Today's - grant read also runs the `beforeFind` and `afterFind` hooks registered for the table, and the subquery runs none. - The class is drawn at middleware, where ADR-0139 D5.2 draws it. No package here registers such a hook for the - table by name, and O8's census looks for both. + `sys_record_share` (`packages/objectql/src/engine.ts#resolveDatasourceBinding`). The second is a registration made + for `sys_record_share` by name, which today's grant read runs and the subquery would read around. It has two + kinds, treated alike: an object-scoped middleware (`packages/objectql/src/engine.ts#hasObjectMiddleware`), which is + ADR-0139 D5.2's class, and a find hook, `beforeFind` or `afterFind` + (`packages/objectql/src/engine.ts#registerHook`), which this record adds for this table. ⛔ The seam never reads + around either. What each class answers is ②, and each is a row of Q2's census. No package in this repository names + the table in either kind of registration. plugin-audit registers its record-view hook for the objects a host opts + in (`packages/plugins/plugin-audit/src/read-audit.ts#installReadAuditWriter`), so a host that opts this table in is + in the class. Hosts outside this repository were not read, and O8's census looks for both kinds. - **The refusal** is ADR-0139 D3's envelope wherever it occurs: status 500, `INTERNAL_ERROR`, a message naming the evaluator, the leaf and the remedy, logged at `error` once per evaluator (`packages/core/src/utils/readable-ids-driver-refusal.ts#refuseReadableIdsOnce` is the device). ⛔ It is not @@ -400,7 +414,7 @@ recommended answer). That is one mechanism: |:--|:--| | The brand, its factory and guard, its meaning, its producer | per leaf, never shared: one brand, one meaning | | The comparand door's admission of engine-internal comparands | once, as one option that names the brands it admits, not one flag per brand | -| The executor seam's pass-through, its position and verb checks, its recipient rule, its descent into composed scopes | once. The recipient rule reads this leaf's recipient and the caller of ADR-0147's anchor | +| The executor seam's pass-through, its position and verb checks, its recipient rule, its descent into composed scopes | once. The recipient rule reads this leaf's recipient, and the caller and the organization of ADR-0147's anchor | | The fixed inner read: one table, one projected column, a closed set of bound equality and membership predicates, the blank-id guard, system authority, and the tenant scope each record rules for its leaf (none in ADR-0147 D-b; ① here) | once per evaluator (`driver-sql`, the Turso remote transport, `driver-memory`, and the analytics native compiler if ② rules that it compiles). Each leaf supplies its description, and no evaluator restates either leaf's predicate by hand | | What a leaf compiles to outside its subquery | per leaf. ADR-0147 ORs its caller arm in, and issues no subquery when no organization is active (its D-a and D-c). This leaf is the subquery alone | | The refusal envelope and its once-per-evaluator log | once | @@ -538,7 +552,7 @@ recognises second. It is here because the same three answers apply to it. | `driver-odata` (`packages/drivers/driver-odata/src/odata-driver.ts#refuseReadableIds`) | As above; the backend's own ceiling is its request length | As above | **R2**, with R1 behind it | | A driver this repository does not ship | As above, unless it declares that it evaluates the leaf | As above | **R2**, with R1 behind it | | An object bound to another datasource than `sys_record_share`. That includes a federated object that declares a real remote owner column, which keeps its shares today (`packages/plugins/plugin-sharing/src/sharing-service.ts#inertGrantReason`) | As above | As above | **R2**, with R1 behind it | -| A host that registers an object-scoped middleware for `sys_record_share` (D4's second class). Today's grant read passes through the middleware, and the subquery would not. No package in this repository registers one | The list is read through the engine, so the middleware still runs and what works today keeps working, up to the bound. The SQL family keeps a list path for this class | **R1**: every sharing-scoped read and predicate update on that host fails with 500 until the registration is removed. A boot check can name the registration and refuse the boot before any request is served, as ADR-0139 D5's seventh-consumer note has the boot refuse the same class. A registration made after boot still meets the seam's refusal at read. **R2**: record sharing is unsupported on that host. No object takes a share arm, grants stop counting and are refused at both doors, and owner, queue and approval access is unchanged | **R1, at boot**, with the seam's refusal behind it | +| A host that registers an object-scoped middleware or a find hook for `sys_record_share` by name (D4's second class). Today's grant read runs the registration, and the subquery would not. No package in this repository names the table in one | The list is read through the engine, so the registration still runs and what works today keeps working, up to the bound. The SQL family keeps a list path for this class | **R1**: every sharing-scoped read and predicate update on that host fails with 500 until the registration is removed. A boot check can name the registration, middleware or hook, and refuse the boot before any request is served. ADR-0139 D5's seventh-consumer note is the precedent, and it is keyed on what writes the leaf: the boot there refuses a `controlled_by_parent` detail whose master is in the middleware class, not the middleware alone. So the check lands with the switch (plan step 6) and refuses only where a producer writes the leaf: until then today's grant read still runs the registration, and nothing reads around it. A registration made after boot still meets the seam's refusal at read. **R2**: record sharing is unsupported on that host. No object takes a share arm, grants stop counting and are refused at both doors, and owner, queue and approval access is unchanged | **R1, at boot**, with the seam's refusal behind it | | The analytics native-SQL compiler (`packages/services/service-analytics/src/read-scope-sql.ts#compileScopedFilterToSql`). Today it binds one parameter per `$in` member and refuses `ReadableIds` at entry | The cap, or an unbounded list, returns on this path | It declines the query to the engine strategy, as it does for `ReadableIds` (`packages/services/service-analytics/src/strategies/native-sql-strategy.ts#readScopeCarriesReadableIds`). With the leaf on every sharing-scoped read, that is nearly every member query on such an object, and the shapes only native SQL serves, such as a multi-hop join (`packages/services/service-analytics/src/strategies/cross-object-where.ts#UnservedCrossObjectReason`), are then refused | **Neither: it compiles the leaf.** It is SQL, and the leaf needs no composition | | The analytics engine strategy's merge and the dry-run SQL echo | not applicable | Unless its merge admits the brand (`packages/services/service-analytics/src/read-scope-sql.ts#assertReadScopeComparandsRunnable`), every query it serves on such an object is refused | **It admits the brand** and hands the scope to the engine, as it does `ReadableIds`. The echo prints the subquery the statement runs | | The explainer's record pass (`packages/plugins/plugin-security/src/explain-engine.ts#matchUnderDeclaredColumns`). Today it matches the list in process and publishes it as the sharing layer's `rowFilter` (`packages/spec/src/security/explain.zod.ts#ExplainRecordAttributionSchema`) | It materialises the caller's whole grant list for each explanation, and the published filter grows with it | The record pass matches the sharing read filter for every record-grained explanation, whatever the verb. So each one on such an object fails, on every driver, and with it the attachment and comment gates that ask the explainer for a parent record's by-id judgement | **Neither: it resolves the leaf at the record.** One indexed read under the fixed predicate, keyed by the record ids it judges, the read `checkEdit` makes for one | @@ -550,11 +564,12 @@ recognises second. It is here because the same three answers apply to it. boot of the objects that hold such rows, the refusal at both doors, the explainer's sentence and a changelog entry: ADR-0111 D10's "tighten directly, fail closed, with a visible trail". This reading has no census of deployments that hold such grants; that report is the instrument. -- **A host in the middleware row does not start until it removes the registration.** That row is recommended as R1 - on purpose, and it is an outage by choice. The condition is one registration the host can remove, where a storage - row leaves the host no remedy. The boot names it before any request is served. R2 there would switch record - sharing off on every object while the host kept serving. The class is empty in this repository, and O8's census - says whether a host outside it is in the class. +- **From the switch on, a host in the host class does not start until it removes the registration.** Its row is + recommended as R1 on purpose, and it is an outage by choice. The condition is one registration the host can + remove, where a storage row leaves the host no remedy. The boot names it before any request is served, and no card + before the switch refuses a boot. R2 there would switch record sharing off on every object while the host kept + serving. The class is empty in this repository, and O8's census, read before the switch card is cut, says whether + a host outside it is in the class. - **It consults a driver declaration**, so ADR-0139 D3's "⛔ No `DriverCapabilities` bit returns" is revisited for this leaf as ADR-0147 D-d revisits it for its own, and ADR-0111 D7 gains an arm. - **A later compile lifts R2 for that evaluator** with no amendment here: a `$lookup` form on MongoDB (O9), or a @@ -569,16 +584,16 @@ sharing on those evaluators. It is the simplest reading of the rule and needs no price. Writing the leaf only for a caller who holds a grant would confine the outage to grantees, at the price of the per-operation read this record removes, and a grantee would still lose every read of the object. Under the recommendation R1 stays as the backstop: a leaf that reaches an evaluator that cannot run it is refused, never -dropped. The middleware row is the one row recommended as R1 itself, and its cost above says why. +dropped. The host row is the one row recommended as R1 itself, and its cost above says why. **Why not L.** It is the slower path built only for parity. It keeps a second evaluation path in the engine (the declaration, the substitution, its descent into composed scopes, a completion read per operation) for backends the principle says not to be compatible with for compatibility's sake, and its bound is a cap again. Its merit is real and is stated: L is the one answer under which nothing that works today stops working. -**Recommendation.** No list anywhere. The storage rows take **R2** with R1 behind it, the middleware row takes **R1** -at boot, the analytics compilers compile or admit, and the explainer resolves at the record. The maintainer may rule -row by row. +**Recommendation.** No list anywhere. The storage rows take **R2** with R1 behind it, the host row takes **R1** at +boot from the switch on, the analytics compilers compile or admit, and the explainer resolves at the record. The +maintainer may rule row by row. ### Q3 — The leaf on a predicate update @@ -624,7 +639,7 @@ leaf adds no bound and removes none. A sharing-scoped operation issues no grant read of its own, its statement's parameters no longer grow with the grants, and a `controlled_by_parent` read no longer binds the list again inside the parent's subquery. The arm is part of one statement, so `find`, `count` and `aggregate` agree by construction. For a predicate update each of - these holds under ③'s A; under B the write side keeps a list. + these holds under ③'s A; under B the write side keeps a list, and under C it still reads grants per operation. - **Cost, named.** Spec gains one more branded comparand. The engine's door and seam and three evaluators gain its handling. Every sharing-scoped read carries an index-backed subquery, for a caller with no grant too, where today it carried one extra read and no arm. D6 pins that statement's plan and timing. @@ -636,8 +651,11 @@ leaf adds no bound and removes none. for itself. Today's list is read once, before both. - **A public contract's answer changes kind.** `buildReadFilter` is a member of `packages/spec/src/contracts/sharing-service.ts#ISharingService`. Its answer now carries an engine-internal leaf, so - it is handed to the engine in process, ⛔ never serialised and never matched by a generic matcher. The spec card - says so in the contract's prose. Readers outside this repository were not read from this tree (O8). + it is handed to the engine in process, ⛔ never serialised and never matched by a generic matcher. The recipient + rule also gives the security service's read filter a precondition. Its documented use hands the scope to an engine + read (`packages/spec/src/contracts/security-service.ts#getReadFilter`), and that read must run under the context + the scope was asked for, under one acting on behalf of that context's user, or under a system context. The spec + card says both in the contracts' prose. Readers outside this repository were not read from this tree (O8). - **The evaluators under ②** change as the maintainer rules. The recommended answers' costs are stated there. - **Each execution card declares its own Clause-②.** @@ -682,16 +700,19 @@ leaf adds no bound and removes none. verdict rests on it alone. It was noted on #33787 and is not filed, and it is not this record's. - **O6** — ADR-0147's floor and the SQL-first rule point different ways. This record does not revisit that one. If ② is ruled a refusal, the two leaves differ on evaluators that cannot compile, and D4's table already builds for it. -- **O7** — Pointer notes owed on acceptance, each dated and append-only, in a governed edit of their own: ADR-0139 D1 - (one more leaf, and the read-verbs sentence if ③ is ruled A); ADR-0139 O4 (answered); ADR-0139 D3 (under ②'s L or - R2, each of which consults a driver declaration); ADR-0111 D7 (only under R2); and a cross-reference from ADR-0147 - D-a for the shared seam and its recipient rule. [#34102](https://github.com/objectstack-ai/objectstack/issues/34102) - carries the ADR-0139 notes once this record lands and ①, ② and ③ are ruled, because some of them depend on a - ruling. The ADR-0111 and ADR-0147 notes ride with it or take a governed edit of their own. None is in this - record's diff, which adds this record and its index row and edits no other record. +- **O7** — Pointer notes owed on acceptance, each dated and append-only: ADR-0139 D1 (one more leaf, and the + read-verbs sentence if ③ is ruled A); ADR-0139 O4 (answered); ADR-0139 D3 (under ②'s L or R2, each of which + consults a driver declaration); ADR-0111 D7 (only under R2); and a cross-reference from ADR-0147 D-a for the shared + seam and what its recipient rule checks on that record's anchor (D4). They land with the governed edit that records + the maintainer's rulings in this record's Status line. The first acceptance criterion already requires that edit, + and the same rulings decide which notes are owed. None is in this record's diff, which adds this record and its + index row and edits no other record. - **O8** — Readers of `buildReadFilter` and of the security service's read filter outside this repository (the cloud repository's packages) were not read from this tree, and neither was any host that registers an object-scoped - middleware or a find hook for `sys_record_share` (D4). The switch card owes that census before it lands. + middleware or a find hook for `sys_record_share` by name (D4). The census reads both, and for each outside reader + the context it runs its read under (Consequences). It is owed before the switch card is cut: under the host row's + recommended answer that card carries the boot check, so it is the first card that can refuse a boot, and the + census precedes it. - **O9** — `driver-mongodb`: a `$lookup` form is unprototyped (shared with ADR-0139 O3 and ADR-0147 O2). ## Acceptance criteria @@ -699,7 +720,7 @@ leaf adds no bound and removes none. - The maintainer approves this record (`GOVERNED_APPROVERS`, Tier H) and rules ①, ② and ③. The rulings are recorded in this record, in its Status line and in the three question sections, each citing its ruling record, before any execution card is cut. -- O7's pointer notes land in their own governed edit; #34102 carries ADR-0139's. +- O7's pointer notes land with that edit: the governed edit that records the rulings in this record's Status line. - The switch meets [D6](#d6--what-the-switch-must-show). - At every step D-0 holds on every evaluator that evaluates the leaf, and every other evaluator answers as ② ruled. @@ -709,20 +730,23 @@ The seats cut the cards after acceptance, in this order. Each card declares its The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ②'s rows add cards as they are ruled. 1. **Spec: the leaf.** The brand, its factory and guard beside `ReadableIds`; the comparand door's option; the fixed - inner read's description; the conformance case-set; the `ISharingService` prose. The shared pieces take the - two-leaf shape (D4). + inner read's description; the conformance case-set; the `ISharingService` and `ISecurityService` prose. The shared + pieces take the two-leaf shape (D4). 2. **Engine: the seam.** Door admission, pass-through, the position rule, the verb rule (③ as ruled) and the recipient rule, the two recognised classes (② as ruled), the descent into composed scopes, the refusal, and the declaration's consult if ② rules one. The recipient rule is pinned on its four cases: the context's user, its - delegator, a system context, and any other recipient, which is refused. + delegator, a system context, and any other recipient, which is refused. The cases of ADR-0147's anchor, its + organization among them, are pinned on the card that adds that leaf to the seam. 3. **`driver-sql` and the Turso remote transport: the compile.** The subquery and its tenant scope (① as ruled), the update path (③ as ruled), the pins per dialect, O2, O3, and D6's reading for a caller with no grant. 4. **`driver-memory`: the in-process evaluation**, on reads and on the update path (③ as ruled). -5. **The rest of the census, as ② is ruled**: the storage rows' refusal for this brand, the middleware row's answer - (the boot check, under the recommended one), the analytics compilers, the explainer's record pass. -6. **plugin-sharing: the switch.** `buildReadFilter` and `buildWriteFilter` write the leaf, the approval ids become a - disjunct of their own, and under R2 the inert arm and its report land here, at the moment those grants stop - counting. The middleware also mirrors its scope under the AST's `filter` key, which the executor seam does not walk - and no driver in this repository reads; the card stops mirroring the leaf there or pins that the key stays unread. - The card carries D6's pins and the narrow figure, and #33787 ends with it. ⛔ It lands last: landed earlier, it - hands the leaf to an evaluator that has no answer for it yet. +5. **The rest of the census, as ② is ruled**: the storage rows' refusal for this brand, the analytics compilers, the + explainer's record pass. ⛔ No card up to here refuses a boot. +6. **plugin-sharing: the switch.** O8's census is read before this card is cut. `buildReadFilter` and + `buildWriteFilter` write the leaf, and the approval ids become a disjunct of their own. Each tightening lands + here, at the moment it takes effect: under R2 the inert arm and its report, when those grants stop counting, and + under the host row's recommended answer the boot check, when a producer first writes the leaf. The middleware also + mirrors its scope under the AST's `filter` key, which the executor seam does not walk and no driver in this + repository reads; the card stops mirroring the leaf there or pins that the key stays unread. The card carries + D6's pins and the narrow figure, and #33787 ends with it. ⛔ It lands last: landed earlier, it hands the leaf to an + evaluator that has no answer for it yet. From 11d7d354ca108dd153708fb60cbf122cd68b2760 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 21:54:06 +0000 Subject: [PATCH 4/7] =?UTF-8?q?docs(adr):=20ADR-0155=20fix=20round=203=20?= =?UTF-8?q?=E2=80=94=20anchor=20check=20against=20the=20context's=20own=20?= =?UTF-8?q?anchor,=20native=20compiler=20returns=20classed=20objects=20to?= =?UTF-8?q?=20the=20engine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A text-only round on the record after its second delta contract review. The record stays Proposed, and its three maintainer questions stay open. D4 states the shared seam's rule for ADR-0147's anchor against what the reading context itself carries. The seam compares the leaf's anchor with the anchor the context carries, caller and organization together, and admits the leaf only when both are equal. Nothing is re-derived from the context's userId or tenantId, as ADR-0147 D-a rules. ADR-0147 D-c's context, the delegator's rebuilt one, reads under the anchor it carries and is admitted. The built-once table says the same, plan step 2 lists the cases the later card pins, and Consequences keeps its "no flow" sentence to this record's own leaf. The recipient rule of this record's leaf is unchanged. The analytics native-SQL compiler compiles the leaf only where the seam would hand it to a driver. Where either class D4 recognises applies, it declines the query to the engine strategy before anything compiles, so the class gets the answer question 2 rules. Q2's row states the price, and plan step 5 names the card that carries the recognition. A registration on the grant table that skips system reads stays in the host class: the engine reads registrations and not handlers. For a host whose registration is its opt-in to record-view auditing, removing it gives up that auditing of share rows. D4, Q2's host row and its cost list say so, price the other answer, an exemption on a declaration the engine enforces, and put the choice to the maintainer under question 2. The seat that cuts the switch card produces the census of hosts and outside readers as a condition of cutting it, and records it in that card's body. O8, plan step 6 and the acceptance criteria say the same. No other record is edited, and the index row is unchanged. Claude-Session: https://claude.ai/code/session_01ADHkmSrxgDeeJWnQpVfLcX Co-authored-by: Claude --- ...er-to-an-engine-internal-semi-join-leaf.md | 92 +++++++++++++------ 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md index 117e08bb194..754f2da9051 100644 --- a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md +++ b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md @@ -119,8 +119,10 @@ Three things are the maintainer's and are put, not decided: both, and [What this reading adds](#what-this-reading-adds-to-the-cards) lists where the newer reading is more exact. The sentences added after the at-tier review of this record ([`6899302526`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6899302526)) were read on - `origin/main` `27c2f1ea`, and those added after its delta review - ([`6900428326`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6900428326)) on `385ea1cc`. + `origin/main` `27c2f1ea`, those added after its delta review + ([`6900428326`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6900428326)) on `385ea1cc`, + and those added after its second delta review + ([`6901557418`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6901557418)) on `b29f2dd1`. ## Context @@ -378,14 +380,27 @@ After the switch the read scope is: recommended answer the analytics native-SQL compiler compiles the leaf with no seam in front of it, and the seam's position, verb and recipient checks hold there by construction: one strategy context, built per request (`packages/services/service-analytics/src/analytics-service.ts#callCtx`), asks for the scope under the request's - context and issues the statement that carries it. + context and issues the statement that carries it. That compiler compiles the leaf only where the seam would hand + it to a driver. Where either of the two classes below applies, it declines the query to the engine strategy before + anything compiles, so the class gets the answer ② rules, at boot or from the seam after it. Each class has one + answer, and the seam's answer is this record's. - **The same rule on ADR-0147's anchor, in full.** The seam is built once for both leaves (below), and it holds one - rule for both: every identity named by a leaf that arrives composed is compared with the reading context. This - leaf names one, its recipient. ADR-0147's anchor names two, and the seam checks both: its caller, which like a - recipient must be the reading context's user or that context's delegator, and its organization, which must be the - reading context's active organization. A system context is the same one exemption, and any mismatch is the same - composition fault, answered with the refusal below. ADR-0147 takes this through its cross-reference note (O7), - which lands with this record's other pointer notes. + rule for both: every identity named by a leaf that arrives composed is compared with what the reading context + itself carries. This leaf names one, its recipient, and the context carries its user and its delegator (above). + ADR-0147's leaf names two, the caller and the organization of its anchor, and the context carries an anchor of its + own, which ADR-0147 D-e has the builders and carriers of the list carry. The seam compares the two anchors, caller + and organization together, and admits the leaf only when both are equal. Nothing is re-derived from the reading + context's `userId` or `tenantId` (ADR-0147 D-a). ADR-0147 D-c names the context that needs it so: the delegator's + rebuilt context (`packages/plugins/plugin-security/src/explain-engine.ts#resolveDelegatorContext`) carries the + live principal's list, and after that record the live principal's anchor, under the delegator's user and with no + delegation link. It is a reading context: on a delegated write to a `controlled_by_parent` detail the master's + write gate runs once per principal, and its delegator pass reads the master under that context + (`packages/plugins/plugin-security/src/security-plugin-cbp-write-gate.ts#assertControlledByParentChainEditable`). + A leaf compiled under that context carries the same anchor, and the seam admits it. A reading context that carries + no anchor matches none. A system context is the same one exemption, and any mismatch is the same composition + fault, answered with the refusal below. This record states the rule in full, for both fields, and does not leave + the caller to ADR-0147's cross-reference note. That note (O7) carries the rule into ADR-0147, and it lands with + this record's other pointer notes. - **Every occurrence, nested ones included.** The scope the engine composes for a `ReadableIds` leaf is the security service's read filter for the parent (`packages/objectql/src/engine-readable-ids-permission-formula.ts#composeReadableIdsChain`), and for a sharing-scoped parent that filter carries this leaf. The seam's checks descend into composed scopes. @@ -397,9 +412,14 @@ After the switch the read scope is: ADR-0139 D5.2's class, and a find hook, `beforeFind` or `afterFind` (`packages/objectql/src/engine.ts#registerHook`), which this record adds for this table. ⛔ The seam never reads around either. What each class answers is ②, and each is a row of Q2's census. No package in this repository names - the table in either kind of registration. plugin-audit registers its record-view hook for the objects a host opts - in (`packages/plugins/plugin-audit/src/read-audit.ts#installReadAuditWriter`), so a host that opts this table in is - in the class. Hosts outside this repository were not read, and O8's census looks for both kinds. + the table in either kind of registration on its own. plugin-audit registers its record-view hook for the objects a + host opts in, so a host that opts this table in is in the class. That hook returns at once on a system read + (`packages/plugins/plugin-audit/src/read-audit.ts#installReadAuditWriter`, `#recordView`), which the grant read is. + "Treated alike" holds for such a registration all the same: the seam and the boot check read a registration by the + object it names, and nothing the engine holds says what a handler does on a system read. So this record keeps it + in the class. The other answer exempts a registration that declares it skips system reads, on a declaration the + engine enforces. Q2 prices both, in its host row and its cost list, and the maintainer rules which under ②. Hosts + outside this repository were not read, and O8's census looks for both kinds. - **The refusal** is ADR-0139 D3's envelope wherever it occurs: status 500, `INTERNAL_ERROR`, a message naming the evaluator, the leaf and the remedy, logged at `error` once per evaluator (`packages/core/src/utils/readable-ids-driver-refusal.ts#refuseReadableIdsOnce` is the device). ⛔ It is not @@ -414,7 +434,7 @@ recommended answer). That is one mechanism: |:--|:--| | The brand, its factory and guard, its meaning, its producer | per leaf, never shared: one brand, one meaning | | The comparand door's admission of engine-internal comparands | once, as one option that names the brands it admits, not one flag per brand | -| The executor seam's pass-through, its position and verb checks, its recipient rule, its descent into composed scopes | once. The recipient rule reads this leaf's recipient, and the caller and the organization of ADR-0147's anchor | +| The executor seam's pass-through, its position and verb checks, its recipient rule, its descent into composed scopes | once. The recipient rule compares this leaf's recipient with the reading context's user and delegator, and ADR-0147's anchor, caller and organization together, with the anchor that context carries | | The fixed inner read: one table, one projected column, a closed set of bound equality and membership predicates, the blank-id guard, system authority, and the tenant scope each record rules for its leaf (none in ADR-0147 D-b; ① here) | once per evaluator (`driver-sql`, the Turso remote transport, `driver-memory`, and the analytics native compiler if ② rules that it compiles). Each leaf supplies its description, and no evaluator restates either leaf's predicate by hand | | What a leaf compiles to outside its subquery | per leaf. ADR-0147 ORs its caller arm in, and issues no subquery when no organization is active (its D-a and D-c). This leaf is the subquery alone | | The refusal envelope and its once-per-evaluator log | once | @@ -552,8 +572,8 @@ recognises second. It is here because the same three answers apply to it. | `driver-odata` (`packages/drivers/driver-odata/src/odata-driver.ts#refuseReadableIds`) | As above; the backend's own ceiling is its request length | As above | **R2**, with R1 behind it | | A driver this repository does not ship | As above, unless it declares that it evaluates the leaf | As above | **R2**, with R1 behind it | | An object bound to another datasource than `sys_record_share`. That includes a federated object that declares a real remote owner column, which keeps its shares today (`packages/plugins/plugin-sharing/src/sharing-service.ts#inertGrantReason`) | As above | As above | **R2**, with R1 behind it | -| A host that registers an object-scoped middleware or a find hook for `sys_record_share` by name (D4's second class). Today's grant read runs the registration, and the subquery would not. No package in this repository names the table in one | The list is read through the engine, so the registration still runs and what works today keeps working, up to the bound. The SQL family keeps a list path for this class | **R1**: every sharing-scoped read and predicate update on that host fails with 500 until the registration is removed. A boot check can name the registration, middleware or hook, and refuse the boot before any request is served. ADR-0139 D5's seventh-consumer note is the precedent, and it is keyed on what writes the leaf: the boot there refuses a `controlled_by_parent` detail whose master is in the middleware class, not the middleware alone. So the check lands with the switch (plan step 6) and refuses only where a producer writes the leaf: until then today's grant read still runs the registration, and nothing reads around it. A registration made after boot still meets the seam's refusal at read. **R2**: record sharing is unsupported on that host. No object takes a share arm, grants stop counting and are refused at both doors, and owner, queue and approval access is unchanged | **R1, at boot**, with the seam's refusal behind it | -| The analytics native-SQL compiler (`packages/services/service-analytics/src/read-scope-sql.ts#compileScopedFilterToSql`). Today it binds one parameter per `$in` member and refuses `ReadableIds` at entry | The cap, or an unbounded list, returns on this path | It declines the query to the engine strategy, as it does for `ReadableIds` (`packages/services/service-analytics/src/strategies/native-sql-strategy.ts#readScopeCarriesReadableIds`). With the leaf on every sharing-scoped read, that is nearly every member query on such an object, and the shapes only native SQL serves, such as a multi-hop join (`packages/services/service-analytics/src/strategies/cross-object-where.ts#UnservedCrossObjectReason`), are then refused | **Neither: it compiles the leaf.** It is SQL, and the leaf needs no composition | +| A host that registers an object-scoped middleware or a find hook for `sys_record_share` by name (D4's second class). Today's grant read runs the registration, and the subquery would not. No package in this repository names the table in one on its own, but a host that opts the table into plugin-audit's record-view auditing is in the class (D4), although that hook returns at once on a system read, which the grant read is | The list is read through the engine, so the registration still runs and what works today keeps working, up to the bound. The SQL family keeps a list path for this class | **R1**: every sharing-scoped read and predicate update on that host fails with 500 until the registration is removed. For a host whose registration is that opt-in, removing it gives up record-view auditing of share rows. A boot check can name the registration, middleware or hook, and refuse the boot before any request is served. ADR-0139 D5's seventh-consumer note is the precedent, and it is keyed on what writes the leaf: the boot there refuses a `controlled_by_parent` detail whose master is in the middleware class, not the middleware alone. So the check lands with the switch (plan step 6) and refuses only where a producer writes the leaf: until then today's grant read still runs the registration, and nothing reads around it. A registration made after boot still meets the seam's refusal at read. **R2**: record sharing is unsupported on that host. No object takes a share arm, grants stop counting and are refused at both doors, and owner, queue and approval access is unchanged | **R1, at boot**, with the seam's refusal behind it, and the class kept whole (D4). The other answer exempts a registration that declares it skips system reads; its price is that declaration on hook registration, enforced by the engine. The maintainer rules which | +| The analytics native-SQL compiler (`packages/services/service-analytics/src/read-scope-sql.ts#compileScopedFilterToSql`). Today it binds one parameter per `$in` member and refuses `ReadableIds` at entry | The cap, or an unbounded list, returns on this path | It declines the query to the engine strategy, as it does for `ReadableIds` (`packages/services/service-analytics/src/strategies/native-sql-strategy.ts#readScopeCarriesReadableIds`). With the leaf on every sharing-scoped read, that is nearly every member query on such an object, and the shapes only native SQL serves, such as a multi-hop join (`packages/services/service-analytics/src/strategies/cross-object-where.ts#UnservedCrossObjectReason`), are then refused | **Neither: it compiles the leaf**, where the seam would hand the leaf to a driver. It is SQL, and the leaf needs no composition. Where either of D4's two classes applies, it declines the query to the engine strategy before anything compiles, so the class gets the answer this table rules for it, at boot or from the seam after it. The price: for those objects and hosts the shapes only native SQL serves are refused | | The analytics engine strategy's merge and the dry-run SQL echo | not applicable | Unless its merge admits the brand (`packages/services/service-analytics/src/read-scope-sql.ts#assertReadScopeComparandsRunnable`), every query it serves on such an object is refused | **It admits the brand** and hands the scope to the engine, as it does `ReadableIds`. The echo prints the subquery the statement runs | | The explainer's record pass (`packages/plugins/plugin-security/src/explain-engine.ts#matchUnderDeclaredColumns`). Today it matches the list in process and publishes it as the sharing layer's `rowFilter` (`packages/spec/src/security/explain.zod.ts#ExplainRecordAttributionSchema`) | It materialises the caller's whole grant list for each explanation, and the published filter grows with it | The record pass matches the sharing read filter for every record-grained explanation, whatever the verb. So each one on such an object fails, on every driver, and with it the attachment and comment gates that ask the explainer for a parent record's by-id judgement | **Neither: it resolves the leaf at the record.** One indexed read under the fixed predicate, keyed by the record ids it judges, the read `checkEdit` makes for one | @@ -565,11 +585,19 @@ recognises second. It is here because the same three answers apply to it. ADR-0111 D10's "tighten directly, fail closed, with a visible trail". This reading has no census of deployments that hold such grants; that report is the instrument. - **From the switch on, a host in the host class does not start until it removes the registration.** Its row is - recommended as R1 on purpose, and it is an outage by choice. The condition is one registration the host can - remove, where a storage row leaves the host no remedy. The boot names it before any request is served, and no card - before the switch refuses a boot. R2 there would switch record sharing off on every object while the host kept - serving. The class is empty in this repository, and O8's census, read before the switch card is cut, says whether - a host outside it is in the class. + recommended as R1 on purpose, and it is an outage by choice. The condition is a registration the host can remove, + where a storage row leaves the host no remedy. The boot names it before any request is served, and no card before + the switch refuses a boot. R2 there would switch record sharing off on every object while the host kept serving. + No package in this repository names the table on its own, and O8's census, recorded when the switch card is cut, + says whether a host is in the class, by a registration of its own or by opting the table into record-view + auditing. +- **For a host that opted the table into record-view auditing, removing the registration gives up that auditing of + share rows.** The registration is the opt-in itself. That hook returns at once on a system read, and the grant read + is one: the host pays this price although the hook records nothing on that read today. D4 keeps the registration + in the class all the same, because the engine reads registrations and not handlers. The other answer exempts a + registration that declares it skips system reads. Such a host then starts and keeps its auditing, and the price is + one more contract: a declaration on hook registration, which the engine enforces by not dispatching that hook on a + system read, and which the seam and the boot check read. The maintainer rules which, with the host row. - **It consults a driver declaration**, so ADR-0139 D3's "⛔ No `DriverCapabilities` bit returns" is revisited for this leaf as ADR-0147 D-d revisits it for its own, and ADR-0111 D7 gains an arm. - **A later compile lifts R2 for that evaluator** with no amendment here: a `$lookup` form on MongoDB (O9), or a @@ -645,7 +673,9 @@ leaf adds no bound and removes none. it carried one extra read and no arm. D6 pins that statement's plan and timing. - **Failure surface.** Unchanged in direction. Today a failing grant read fails the operation before its statement; after the switch the same failure is the statement's. One refusal is new: the seam's recipient rule (D4). It - answers a composition fault, and no flow read in this repository meets it. + answers a composition fault, and for this record's leaf, whose recipient is the reading context's user or its + delegator, no flow read in this repository meets it. The flows that carry ADR-0147's anchor are read on the card + that adds that leaf to the seam (plan step 2). - **Freshness.** The arm is read at statement time (D2). Under ③'s A, a predicate update's prior-row read and its write are two statements, and each evaluates the share arm for itself, as each already evaluates the owner match for itself. Today's list is read once, before both. @@ -709,8 +739,10 @@ leaf adds no bound and removes none. index row and edits no other record. - **O8** — Readers of `buildReadFilter` and of the security service's read filter outside this repository (the cloud repository's packages) were not read from this tree, and neither was any host that registers an object-scoped - middleware or a find hook for `sys_record_share` by name (D4). The census reads both, and for each outside reader - the context it runs its read under (Consequences). It is owed before the switch card is cut: under the host row's + middleware or a find hook for `sys_record_share` by name (D4), an opt-in of that table into record-view auditing + among them. The census reads both, and for each outside reader the context it runs its read under (Consequences). + The seat that cuts the switch card produces the census, as a condition of cutting that card, and records it in + the card's body: each tree it read, named by repository and commit, and what it found there. Under the host row's recommended answer that card carries the boot check, so it is the first card that can refuse a boot, and the census precedes it. - **O9** — `driver-mongodb`: a `$lookup` form is unprototyped (shared with ADR-0139 O3 and ADR-0147 O2). @@ -721,6 +753,8 @@ leaf adds no bound and removes none. in this record, in its Status line and in the three question sections, each citing its ruling record, before any execution card is cut. - O7's pointer notes land with that edit: the governed edit that records the rulings in this record's Status line. +- O8's census is produced by the seat that cuts the switch card and recorded in that card's body. The card is not + cut without it. - The switch meets [D6](#d6--what-the-switch-must-show). - At every step D-0 holds on every evaluator that evaluates the leaf, and every other evaluator answers as ② ruled. @@ -735,14 +769,18 @@ The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ② 2. **Engine: the seam.** Door admission, pass-through, the position rule, the verb rule (③ as ruled) and the recipient rule, the two recognised classes (② as ruled), the descent into composed scopes, the refusal, and the declaration's consult if ② rules one. The recipient rule is pinned on its four cases: the context's user, its - delegator, a system context, and any other recipient, which is refused. The cases of ADR-0147's anchor, its - organization among them, are pinned on the card that adds that leaf to the seam. + delegator, a system context, and any other recipient, which is refused. The cases of ADR-0147's anchor are pinned + on the card that adds that leaf to the seam: the reading context's own anchor; ADR-0147 D-c's context, the + delegator's rebuilt one, reading under the anchor it carries; a system context; and an anchor that differs in its + caller or in its organization, or a context that carries none, each refused. 3. **`driver-sql` and the Turso remote transport: the compile.** The subquery and its tenant scope (① as ruled), the update path (③ as ruled), the pins per dialect, O2, O3, and D6's reading for a caller with no grant. 4. **`driver-memory`: the in-process evaluation**, on reads and on the update path (③ as ruled). 5. **The rest of the census, as ② is ruled**: the storage rows' refusal for this brand, the analytics compilers, the - explainer's record pass. ⛔ No card up to here refuses a boot. -6. **plugin-sharing: the switch.** O8's census is read before this card is cut. `buildReadFilter` and + explainer's record pass. The native compiler's card carries the recognition of D4's two classes and the decline to + the engine strategy. ⛔ No card up to here refuses a boot. +6. **plugin-sharing: the switch.** The seat that cuts this card first produces O8's census and records it in the + card's body; without the census the card is not cut. `buildReadFilter` and `buildWriteFilter` write the leaf, and the approval ids become a disjunct of their own. Each tightening lands here, at the moment it takes effect: under R2 the inert arm and its report, when those grants stop counting, and under the host row's recommended answer the boot check, when a producer first writes the leaf. The middleware also From b0b45bcc3222ab0a8179bb986d49d009109c4435 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 22:34:13 +0000 Subject: [PATCH 5/7] =?UTF-8?q?docs(adr):=20ADR-0155=20fix=20round=204=20?= =?UTF-8?q?=E2=80=94=20the=20host=20class's=20boundary=20for=20a=20registr?= =?UTF-8?q?ation=20that=20names=20no=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01ADHkmSrxgDeeJWnQpVfLcX Co-authored-by: Claude --- ...er-to-an-engine-internal-semi-join-leaf.md | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md index 754f2da9051..a18d3d860fc 100644 --- a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md +++ b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md @@ -122,7 +122,9 @@ Three things are the maintainer's and are put, not decided: `origin/main` `27c2f1ea`, those added after its delta review ([`6900428326`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6900428326)) on `385ea1cc`, and those added after its second delta review - ([`6901557418`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6901557418)) on `b29f2dd1`. + ([`6901557418`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6901557418)) on `b29f2dd1`, + and those added after its third delta review + ([`6902450506`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6902450506)) on `e9fb0987`. ## Context @@ -249,6 +251,9 @@ Name the set once, so every later sentence can point at it: - **Nothing else moves.** No row enters or leaves a scope through the owner match or its depth, the queue arm, the approval arm, the org-wide default, the external floor, the guest denial, the phantom-anchor narrowing, the delegation intersection or the outer read's tenant wall. +- **An outer key of another type answers the same rows.** Where an object's `id` column is not a string, the subquery + answers the rows today's list answers (O2). A refusal there would narrow this invariant on that object, so it is no + driver card's to choose: a card that cannot keep the same rows stops, and the case goes to the maintainer under ②. - **Anything beyond that is a visibility change, and it is the maintainer's first.** That is why ①, ② and ③ are questions: each has an answer that keeps this invariant and an answer that narrows it on purpose. @@ -414,12 +419,27 @@ After the switch the read scope is: around either. What each class answers is ②, and each is a row of Q2's census. No package in this repository names the table in either kind of registration on its own. plugin-audit registers its record-view hook for the objects a host opts in, so a host that opts this table in is in the class. That hook returns at once on a system read - (`packages/plugins/plugin-audit/src/read-audit.ts#installReadAuditWriter`, `#recordView`), which the grant read is. + (`packages/plugins/plugin-audit/src/read-audit.ts#installReadAuditWriter`, through its record-view handler), which + the grant read is. "Treated alike" holds for such a registration all the same: the seam and the boot check read a registration by the object it names, and nothing the engine holds says what a handler does on a system read. So this record keeps it in the class. The other answer exempts a registration that declares it skips system reads, on a declaration the engine enforces. Q2 prices both, in its host row and its cost list, and the maintainer rules which under ②. Hosts outside this repository were not read, and O8's census looks for both kinds. +- **The class's boundary: a registration that names no object.** A middleware registered with no `object` (or with + `'*'`), and a find hook registered for no object, run on every read, today's grant read among them; from the switch + on, the subquery does not run them. They are outside the second class, on the line ADR-0139 D5.2 draws for its + leaf: the engine recognises a registration by the object it names, and counts no global one + (`packages/objectql/src/engine.ts#hasObjectMiddleware`). A registration keyed to no object says nothing the engine + can read about one table, and platform plugins in this repository register middleware that names no object + (`packages/plugins/organizations/src/organizations-plugin.ts` is one), so a class that took them in would refuse + every host that runs such a plugin. The rule this record keeps for them: a sharing-scoped read answers the same rows before and after the + switch on every host, or the host is told. The host is told twice: the contract prose of plan step 1 says that a + narrowing of reads of `sys_record_share` is honoured for the share arm only when it is registered for that table by + name, which places it in the second class; and the switch card's changeset says the same, in the release where the + subquery starts. O8's census reads registrations that name no object as well, and records any that changes a system + read of the table; none was found in this repository at the review of record `6902450506`. The maintainer rules + this boundary with Q2's host row. - **The refusal** is ADR-0139 D3's envelope wherever it occurs: status 500, `INTERNAL_ERROR`, a message naming the evaluator, the leaf and the remedy, logged at `error` once per evaluator (`packages/core/src/utils/readable-ids-driver-refusal.ts#refuseReadableIdsOnce` is the device). ⛔ It is not @@ -437,6 +457,7 @@ recommended answer). That is one mechanism: | The executor seam's pass-through, its position and verb checks, its recipient rule, its descent into composed scopes | once. The recipient rule compares this leaf's recipient with the reading context's user and delegator, and ADR-0147's anchor, caller and organization together, with the anchor that context carries | | The fixed inner read: one table, one projected column, a closed set of bound equality and membership predicates, the blank-id guard, system authority, and the tenant scope each record rules for its leaf (none in ADR-0147 D-b; ① here) | once per evaluator (`driver-sql`, the Turso remote transport, `driver-memory`, and the analytics native compiler if ② rules that it compiles). Each leaf supplies its description, and no evaluator restates either leaf's predicate by hand | | What a leaf compiles to outside its subquery | per leaf. ADR-0147 ORs its caller arm in, and issues no subquery when no organization is active (its D-a and D-c). This leaf is the subquery alone | +| The recognition of D4's two classes | once, in the seam. The analytics native compiler asks the seam's recognition before it compiles and restates none | | The refusal envelope and its once-per-evaluator log | once | | The conformance case-set | once, with a case per leaf | | A driver's declaration that it evaluates such leaves | once, if either record consults one. ADR-0147 D-d does. This record does under every answer to ② but R1 | @@ -572,7 +593,7 @@ recognises second. It is here because the same three answers apply to it. | `driver-odata` (`packages/drivers/driver-odata/src/odata-driver.ts#refuseReadableIds`) | As above; the backend's own ceiling is its request length | As above | **R2**, with R1 behind it | | A driver this repository does not ship | As above, unless it declares that it evaluates the leaf | As above | **R2**, with R1 behind it | | An object bound to another datasource than `sys_record_share`. That includes a federated object that declares a real remote owner column, which keeps its shares today (`packages/plugins/plugin-sharing/src/sharing-service.ts#inertGrantReason`) | As above | As above | **R2**, with R1 behind it | -| A host that registers an object-scoped middleware or a find hook for `sys_record_share` by name (D4's second class). Today's grant read runs the registration, and the subquery would not. No package in this repository names the table in one on its own, but a host that opts the table into plugin-audit's record-view auditing is in the class (D4), although that hook returns at once on a system read, which the grant read is | The list is read through the engine, so the registration still runs and what works today keeps working, up to the bound. The SQL family keeps a list path for this class | **R1**: every sharing-scoped read and predicate update on that host fails with 500 until the registration is removed. For a host whose registration is that opt-in, removing it gives up record-view auditing of share rows. A boot check can name the registration, middleware or hook, and refuse the boot before any request is served. ADR-0139 D5's seventh-consumer note is the precedent, and it is keyed on what writes the leaf: the boot there refuses a `controlled_by_parent` detail whose master is in the middleware class, not the middleware alone. So the check lands with the switch (plan step 6) and refuses only where a producer writes the leaf: until then today's grant read still runs the registration, and nothing reads around it. A registration made after boot still meets the seam's refusal at read. **R2**: record sharing is unsupported on that host. No object takes a share arm, grants stop counting and are refused at both doors, and owner, queue and approval access is unchanged | **R1, at boot**, with the seam's refusal behind it, and the class kept whole (D4). The other answer exempts a registration that declares it skips system reads; its price is that declaration on hook registration, enforced by the engine. The maintainer rules which | +| A host that registers an object-scoped middleware or a find hook for `sys_record_share` by name (D4's second class). Today's grant read runs the registration, and the subquery would not. No package in this repository names the table in one on its own, but a host that opts the table into plugin-audit's record-view auditing is in the class (D4), although that hook returns at once on a system read, which the grant read is. A registration that names no object is outside the class, and the host is told (D4's boundary) | The list is read through the engine, so the registration still runs and what works today keeps working, up to the bound. The SQL family keeps a list path for this class | **R1**: every sharing-scoped read and predicate update on that host fails with 500 until the registration is removed. For a host whose registration is that opt-in, removing it gives up record-view auditing of share rows. A boot check can name the registration, middleware or hook, and refuse the boot before any request is served. ADR-0139 D5's seventh-consumer note is the precedent, and it is keyed on what writes the leaf: the boot there refuses a `controlled_by_parent` detail whose master is in the middleware class, not the middleware alone. So the check lands with the switch (plan step 6) and refuses only where a producer writes the leaf: until then today's grant read still runs the registration, and nothing reads around it. A registration made after boot still meets the seam's refusal at read. **R2**: record sharing is unsupported on that host. No object takes a share arm, grants stop counting and are refused at both doors, and owner, queue and approval access is unchanged | **R1, at boot**, with the seam's refusal behind it, and the class kept whole (D4). The other answer exempts a registration that declares it skips system reads; its price is that declaration on hook registration, enforced by the engine. The maintainer rules which. The boundary is ruled with this row: the recommended line leaves a registration that names no object outside the class and tells the host (D4); the other line refuses at boot every host that has one, which includes every host running a platform plugin that registers one | | The analytics native-SQL compiler (`packages/services/service-analytics/src/read-scope-sql.ts#compileScopedFilterToSql`). Today it binds one parameter per `$in` member and refuses `ReadableIds` at entry | The cap, or an unbounded list, returns on this path | It declines the query to the engine strategy, as it does for `ReadableIds` (`packages/services/service-analytics/src/strategies/native-sql-strategy.ts#readScopeCarriesReadableIds`). With the leaf on every sharing-scoped read, that is nearly every member query on such an object, and the shapes only native SQL serves, such as a multi-hop join (`packages/services/service-analytics/src/strategies/cross-object-where.ts#UnservedCrossObjectReason`), are then refused | **Neither: it compiles the leaf**, where the seam would hand the leaf to a driver. It is SQL, and the leaf needs no composition. Where either of D4's two classes applies, it declines the query to the engine strategy before anything compiles, so the class gets the answer this table rules for it, at boot or from the seam after it. The price: for those objects and hosts the shapes only native SQL serves are refused | | The analytics engine strategy's merge and the dry-run SQL echo | not applicable | Unless its merge admits the brand (`packages/services/service-analytics/src/read-scope-sql.ts#assertReadScopeComparandsRunnable`), every query it serves on such an object is refused | **It admits the brand** and hands the scope to the engine, as it does `ReadableIds`. The echo prints the subquery the statement runs | | The explainer's record pass (`packages/plugins/plugin-security/src/explain-engine.ts#matchUnderDeclaredColumns`). Today it matches the list in process and publishes it as the sharing layer's `rowFilter` (`packages/spec/src/security/explain.zod.ts#ExplainRecordAttributionSchema`) | It materialises the caller's whole grant list for each explanation, and the published filter grows with it | The record pass matches the sharing read filter for every record-grained explanation, whatever the verb. So each one on such an object fails, on every driver, and with it the attachment and comment gates that ask the explainer for a parent record's by-id judgement | **Neither: it resolves the leaf at the record.** One indexed read under the fixed predicate, keyed by the record ids it judges, the read `checkEdit` makes for one | @@ -721,7 +742,7 @@ leaf adds no bound and removes none. the spec card, and shared with ADR-0147's O1 where the declaration is shared. - **O2** — Key comparison. The subquery compares two columns where today a column meets bound strings. On the tables the platform manages both are strings. The driver card pins the comparison, type and collation, on every dialect - `driver-sql` ships, and answers an outer key of another type with the same rows or a loud refusal. + `driver-sql` ships, and answers an outer key of another type with the same rows (D-0). - **O3** — The index. `(object_name, recipient_type, recipient_id)` serves the predicate and does not carry `record_id`. Whether it should is measured on the driver card, with the R9 bench as the instrument. - **O4** — The approval arm stays a list. Its size is the approvals service's, and its ceiling is not measured here. @@ -740,7 +761,8 @@ leaf adds no bound and removes none. - **O8** — Readers of `buildReadFilter` and of the security service's read filter outside this repository (the cloud repository's packages) were not read from this tree, and neither was any host that registers an object-scoped middleware or a find hook for `sys_record_share` by name (D4), an opt-in of that table into record-view auditing - among them. The census reads both, and for each outside reader the context it runs its read under (Consequences). + among them, nor any registration that names no object and changes a system read of that table (D4's boundary). + The census reads all three, and for each outside reader the context it runs its read under (Consequences). The seat that cuts the switch card produces the census, as a condition of cutting that card, and records it in the card's body: each tree it read, named by repository and commit, and what it found there. Under the host row's recommended answer that card carries the boot check, so it is the first card that can refuse a boot, and the @@ -764,8 +786,10 @@ The seats cut the cards after acceptance, in this order. Each card declares its The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ②'s rows add cards as they are ruled. 1. **Spec: the leaf.** The brand, its factory and guard beside `ReadableIds`; the comparand door's option; the fixed - inner read's description; the conformance case-set; the `ISharingService` and `ISecurityService` prose. The shared - pieces take the two-leaf shape (D4). + inner read's description; the conformance case-set; the `ISharingService` and `ISecurityService` prose. The + `ISharingService` prose says what a host does for a narrowing of reads of `sys_record_share` to be honoured by the + share arm: it registers the narrowing for that table by name (D4's boundary). The shared pieces take the two-leaf + shape (D4). 2. **Engine: the seam.** Door admission, pass-through, the position rule, the verb rule (③ as ruled) and the recipient rule, the two recognised classes (② as ruled), the descent into composed scopes, the refusal, and the declaration's consult if ② rules one. The recipient rule is pinned on its four cases: the context's user, its @@ -774,7 +798,9 @@ The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ② delegator's rebuilt one, reading under the anchor it carries; a system context; and an anchor that differs in its caller or in its organization, or a context that carries none, each refused. 3. **`driver-sql` and the Turso remote transport: the compile.** The subquery and its tenant scope (① as ruled), the - update path (③ as ruled), the pins per dialect, O2, O3, and D6's reading for a caller with no grant. + update path (③ as ruled), the pins per dialect, O2, O3, and D6's reading for a caller with no grant. Under ③'s + A the update card pins the rows each of a predicate update's two statements answers, the prior-row read and the + write, each evaluating the share arm for itself (Consequences, Freshness). 4. **`driver-memory`: the in-process evaluation**, on reads and on the update path (③ as ruled). 5. **The rest of the census, as ② is ruled**: the storage rows' refusal for this brand, the analytics compilers, the explainer's record pass. The native compiler's card carries the recognition of D4's two classes and the decline to @@ -783,7 +809,9 @@ The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ② card's body; without the census the card is not cut. `buildReadFilter` and `buildWriteFilter` write the leaf, and the approval ids become a disjunct of their own. Each tightening lands here, at the moment it takes effect: under R2 the inert arm and its report, when those grants stop counting, and - under the host row's recommended answer the boot check, when a producer first writes the leaf. The middleware also + under the host row's recommended answer the boot check, when a producer first writes the leaf. Its changeset tells + a host whose narrowing of the grant table names no object to register it for that table by name (D4's + boundary). The middleware also mirrors its scope under the AST's `filter` key, which the executor seam does not walk and no driver in this repository reads; the card stops mirroring the leaf there or pins that the key stays unread. The card carries D6's pins and the narrow figure, and #33787 ends with it. ⛔ It lands last: landed earlier, it hands the leaf to an From ea5e72ef8704a9812a9504278d6602c885ca11b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 22:54:39 +0000 Subject: [PATCH 6/7] =?UTF-8?q?docs(adr):=20ADR-0155=20fix=20round=205=20?= =?UTF-8?q?=E2=80=94=20one=20telling=20for=20a=20named=20narrowing,=20the?= =?UTF-8?q?=20price=20of=20the=20no-object=20line?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01ADHkmSrxgDeeJWnQpVfLcX Co-authored-by: Claude --- ...er-to-an-engine-internal-semi-join-leaf.md | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md index a18d3d860fc..2764787b28c 100644 --- a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md +++ b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md @@ -250,7 +250,8 @@ Name the set once, so every later sentence can point at it: - **Above it the answer is the corrected one**: every member of G counts. - **Nothing else moves.** No row enters or leaves a scope through the owner match or its depth, the queue arm, the approval arm, the org-wide default, the external floor, the guest denial, the phantom-anchor narrowing, the - delegation intersection or the outer read's tenant wall. + delegation intersection or the outer read's tenant wall. On a host with a registration that names no object, this + holds by telling the host, not by a check (D4's boundary; the price is among Q2's costs). - **An outer key of another type answers the same rows.** Where an object's `id` column is not a string, the subquery answers the rows today's list answers (O2). A refusal there would narrow this invariant on that object, so it is no driver card's to choose: a card that cannot keep the same rows stops, and the case goes to the maintainer under ②. @@ -433,13 +434,14 @@ After the switch the read scope is: (`packages/objectql/src/engine.ts#hasObjectMiddleware`). A registration keyed to no object says nothing the engine can read about one table, and platform plugins in this repository register middleware that names no object (`packages/plugins/organizations/src/organizations-plugin.ts` is one), so a class that took them in would refuse - every host that runs such a plugin. The rule this record keeps for them: a sharing-scoped read answers the same rows before and after the - switch on every host, or the host is told. The host is told twice: the contract prose of plan step 1 says that a - narrowing of reads of `sys_record_share` is honoured for the share arm only when it is registered for that table by - name, which places it in the second class; and the switch card's changeset says the same, in the release where the - subquery starts. O8's census reads registrations that name no object as well, and records any that changes a system - read of the table; none was found in this repository at the review of record `6902450506`. The maintainer rules - this boundary with Q2's host row. + every host that runs such a plugin. The rule this record keeps for them: a sharing-scoped read answers the same + rows before and after the switch on every host, or the host is told. The contract prose of plan step 1 and the + switch card's changeset (plan step 6) tell it one thing: a narrowing of reads of `sys_record_share` registered for + that table by name is never read around, and the host gets the answer ② rules for the second class; a narrowing + that names no object is not run on the share arm. That line has a price, stated among Q2's costs: on such a host + D-0's same rows rest on the telling alone. O8's census reads registrations that name no object as well, and records + any that changes a system read of the table; this record's own reading at `e9fb0987` (Provenance) found none in + this repository. The maintainer rules this boundary with Q2's host row. - **The refusal** is ADR-0139 D3's envelope wherever it occurs: status 500, `INTERNAL_ERROR`, a message naming the evaluator, the leaf and the remedy, logged at `error` once per evaluator (`packages/core/src/utils/readable-ids-driver-refusal.ts#refuseReadableIdsOnce` is the device). ⛔ It is not @@ -619,6 +621,11 @@ recognises second. It is here because the same three answers apply to it. registration that declares it skips system reads. Such a host then starts and keeps its auditing, and the price is one more contract: a declaration on hook registration, which the engine enforces by not dispatching that hook on a system read, and which the seam and the boot check read. The maintainer rules which, with the host row. +- **On a host with a registration that names no object, D-0's same rows rest on the telling alone.** Under the + recommended line nothing at run time refuses, reports or logs such a registration: the seam and the boot check read + a registration by the object it names, and this one names none. A host that does not act on what plan steps 1 and + 6 tell it can get an answer that differs from today's. The other line refuses every such host at boot (the host + row). The maintainer rules which, with the host row. - **It consults a driver declaration**, so ADR-0139 D3's "⛔ No `DriverCapabilities` bit returns" is revisited for this leaf as ADR-0147 D-d revisits it for its own, and ADR-0111 D7 gains an arm. - **A later compile lifts R2 for that evaluator** with no amendment here: a `$lookup` form on MongoDB (O9), or a @@ -787,9 +794,9 @@ The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ② 1. **Spec: the leaf.** The brand, its factory and guard beside `ReadableIds`; the comparand door's option; the fixed inner read's description; the conformance case-set; the `ISharingService` and `ISecurityService` prose. The - `ISharingService` prose says what a host does for a narrowing of reads of `sys_record_share` to be honoured by the - share arm: it registers the narrowing for that table by name (D4's boundary). The shared pieces take the two-leaf - shape (D4). + `ISharingService` prose tells a host that a narrowing of reads of `sys_record_share` registered for that table by + name is never read around and gets the second class's answer, as ② is ruled, and that a narrowing which names no + object is not run on the share arm (D4's boundary). The shared pieces take the two-leaf shape (D4). 2. **Engine: the seam.** Door admission, pass-through, the position rule, the verb rule (③ as ruled) and the recipient rule, the two recognised classes (② as ruled), the descent into composed scopes, the refusal, and the declaration's consult if ② rules one. The recipient rule is pinned on its four cases: the context's user, its @@ -799,20 +806,20 @@ The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ② caller or in its organization, or a context that carries none, each refused. 3. **`driver-sql` and the Turso remote transport: the compile.** The subquery and its tenant scope (① as ruled), the update path (③ as ruled), the pins per dialect, O2, O3, and D6's reading for a caller with no grant. Under ③'s - A the update card pins the rows each of a predicate update's two statements answers, the prior-row read and the + A this card pins the rows each of a predicate update's two statements answers, the prior-row read and the write, each evaluating the share arm for itself (Consequences, Freshness). 4. **`driver-memory`: the in-process evaluation**, on reads and on the update path (③ as ruled). 5. **The rest of the census, as ② is ruled**: the storage rows' refusal for this brand, the analytics compilers, the explainer's record pass. The native compiler's card carries the recognition of D4's two classes and the decline to the engine strategy. ⛔ No card up to here refuses a boot. 6. **plugin-sharing: the switch.** The seat that cuts this card first produces O8's census and records it in the - card's body; without the census the card is not cut. `buildReadFilter` and - `buildWriteFilter` write the leaf, and the approval ids become a disjunct of their own. Each tightening lands - here, at the moment it takes effect: under R2 the inert arm and its report, when those grants stop counting, and - under the host row's recommended answer the boot check, when a producer first writes the leaf. Its changeset tells - a host whose narrowing of the grant table names no object to register it for that table by name (D4's - boundary). The middleware also - mirrors its scope under the AST's `filter` key, which the executor seam does not walk and no driver in this - repository reads; the card stops mirroring the leaf there or pins that the key stays unread. The card carries - D6's pins and the narrow figure, and #33787 ends with it. ⛔ It lands last: landed earlier, it hands the leaf to an - evaluator that has no answer for it yet. + card's body; without the census the card is not cut. `buildReadFilter` and `buildWriteFilter` write the leaf, and + the approval ids become a disjunct of their own. Each tightening lands here, at the moment it takes effect: under + R2 the inert arm and its report, when those grants stop counting, and under the host row's recommended answer the + boot check, when a producer first writes the leaf. Its changeset tells a host what plan step 1's prose tells it: a + narrowing of reads of `sys_record_share` registered for that table by name is never read around and gets the + second class's answer, as ② is ruled, and one which names no object is not run on the share arm (D4's boundary). + The middleware also mirrors its scope under the AST's `filter` key, which the executor seam does not walk and no + driver in this repository reads; the card stops mirroring the leaf there or pins that the key stays unread. The + card carries D6's pins and the narrow figure, and #33787 ends with it. ⛔ It lands last: landed earlier, it hands + the leaf to an evaluator that has no answer for it yet. From 0913316313f149bfda68774c486323fa4f5e9a2d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 23:11:33 +0000 Subject: [PATCH 7/7] =?UTF-8?q?docs(adr):=20ADR-0155=20fix=20round=206=20?= =?UTF-8?q?=E2=80=94=20the=20no-object=20exception=20scoped=20to=20a=20reg?= =?UTF-8?q?istration=20that=20changes=20the=20grant=20read?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01ADHkmSrxgDeeJWnQpVfLcX Co-authored-by: Claude --- ...er-to-an-engine-internal-semi-join-leaf.md | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md index 2764787b28c..647f9c02141 100644 --- a/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md +++ b/docs/adr/0155-sharing-scope-share-grants-lower-to-an-engine-internal-semi-join-leaf.md @@ -125,6 +125,10 @@ Three things are the maintainer's and are put, not decided: ([`6901557418`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6901557418)) on `b29f2dd1`, and those added after its third delta review ([`6902450506`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6902450506)) on `e9fb0987`. + The sentences changed after its fourth delta review + ([`6902721135`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6902721135)) and its fifth + ([`6902940583`](https://github.com/objectstack-ai/objectstack/pull/34064#issuecomment-6902940583)) add no new code + reading. ## Context @@ -250,8 +254,9 @@ Name the set once, so every later sentence can point at it: - **Above it the answer is the corrected one**: every member of G counts. - **Nothing else moves.** No row enters or leaves a scope through the owner match or its depth, the queue arm, the approval arm, the org-wide default, the external floor, the guest denial, the phantom-anchor narrowing, the - delegation intersection or the outer read's tenant wall. On a host with a registration that names no object, this - holds by telling the host, not by a check (D4's boundary; the price is among Q2's costs). + delegation intersection or the outer read's tenant wall. One exception: on a host with a registration that names no + object and changes a system read of `sys_record_share`, the share arm's rows can differ after the switch, and the + host is told (D4's boundary; the price is among Q2's costs). - **An outer key of another type answers the same rows.** Where an object's `id` column is not a string, the subquery answers the rows today's list answers (O2). A refusal there would narrow this invariant on that object, so it is no driver card's to choose: a card that cannot keep the same rows stops, and the case goes to the maintainer under ②. @@ -438,10 +443,11 @@ After the switch the read scope is: rows before and after the switch on every host, or the host is told. The contract prose of plan step 1 and the switch card's changeset (plan step 6) tell it one thing: a narrowing of reads of `sys_record_share` registered for that table by name is never read around, and the host gets the answer ② rules for the second class; a narrowing - that names no object is not run on the share arm. That line has a price, stated among Q2's costs: on such a host - D-0's same rows rest on the telling alone. O8's census reads registrations that name no object as well, and records - any that changes a system read of the table; this record's own reading at `e9fb0987` (Provenance) found none in - this repository. The maintainer rules this boundary with Q2's host row. + that names no object is not run on the share arm. That line has a price, stated among Q2's costs: on a host whose + registration names no object and changes a system read of the table, D-0's same rows rest on the telling alone. + O8's census reads registrations that name no object as well, and records any that changes a system read of the + table; this record's own reading at `e9fb0987` (Provenance) found none in this repository. The maintainer rules + this boundary with Q2's host row. - **The refusal** is ADR-0139 D3's envelope wherever it occurs: status 500, `INTERNAL_ERROR`, a message naming the evaluator, the leaf and the remedy, logged at `error` once per evaluator (`packages/core/src/utils/readable-ids-driver-refusal.ts#refuseReadableIdsOnce` is the device). ⛔ It is not @@ -621,11 +627,11 @@ recognises second. It is here because the same three answers apply to it. registration that declares it skips system reads. Such a host then starts and keeps its auditing, and the price is one more contract: a declaration on hook registration, which the engine enforces by not dispatching that hook on a system read, and which the seam and the boot check read. The maintainer rules which, with the host row. -- **On a host with a registration that names no object, D-0's same rows rest on the telling alone.** Under the - recommended line nothing at run time refuses, reports or logs such a registration: the seam and the boot check read - a registration by the object it names, and this one names none. A host that does not act on what plan steps 1 and - 6 tell it can get an answer that differs from today's. The other line refuses every such host at boot (the host - row). The maintainer rules which, with the host row. +- **On a host with a registration that names no object and changes a system read of `sys_record_share`, D-0's same + rows rest on the telling alone.** Under the recommended line nothing at run time refuses, reports or logs such a + registration: the seam and the boot check read a registration by the object it names, and this one names none. A + host that does not act on what plan steps 1 and 6 tell it can get an answer that differs from today's. The other + line refuses at boot every host with a registration that names no object (the host row). The maintainer rules which, with the host row. - **It consults a driver declaration**, so ADR-0139 D3's "⛔ No `DriverCapabilities` bit returns" is revisited for this leaf as ADR-0147 D-d revisits it for its own, and ADR-0111 D7 gains an arm. - **A later compile lifts R2 for that evaluator** with no amendment here: a `$lookup` form on MongoDB (O9), or a @@ -796,7 +802,8 @@ The card sizes the whole program L, about 2.5–4k lines over 5–7 PRs, and ② inner read's description; the conformance case-set; the `ISharingService` and `ISecurityService` prose. The `ISharingService` prose tells a host that a narrowing of reads of `sys_record_share` registered for that table by name is never read around and gets the second class's answer, as ② is ruled, and that a narrowing which names no - object is not run on the share arm (D4's boundary). The shared pieces take the two-leaf shape (D4). + object is not run on the share arm from the switch on (D4's boundary). The shared pieces take the two-leaf shape + (D4). 2. **Engine: the seam.** Door admission, pass-through, the position rule, the verb rule (③ as ruled) and the recipient rule, the two recognised classes (② as ruled), the descent into composed scopes, the refusal, and the declaration's consult if ② rules one. The recipient rule is pinned on its four cases: the context's user, its