Repository navigation
Commit d7c257e
feat(objectql, core, spec): the engine seam for the fixed-read leaf and its driver declaration (ADR-0155, step 2 of 6) (#35839)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoW11cvRcbZ7pZthNEZt4aqc)_
Fixes #35786
Clause-②: yes
Metadata-protocol: added
Skills-docs: none — DriverCapabilities keys are declared by driver code,
not taught under skills/** (zero readableIdsLeaf hits in skills/ at
origin/main); the generated references
(content/docs/references/data/driver*.mdx) carry the describe text
## 维护者速读
- 用户无感:这一步只在引擎内部装上"共享授权"读取凭据的放行与拒收关口,目前没有任何功能写出这种凭据,线上行为前后一致。
- 属于"共享授权读取不再截断、每条授权都算数"系列的第二步(共六步),为后续让数据库直接按共享表过滤、不再拼一长串编号铺路。
- 关口判错时,带这种凭据的查询会被拒收并报内部错误,不会多放出任何数据;眼下没有写入方,直接撤回本次合并即可复原。
- 无。
## What changes
ADR-0155 step 2 of 6: the engine seam for a fixed-read leaf
(`SharedRecordIds`) and the driver declaration that gates it. Nothing on
main writes the leaf yet (step 6) and no driver declares it (steps 3 and
4), so no observable behaviour on main changes.
- **Driver declaration** (`@objectstack/spec`, `data/driver.zod.ts`).
`DriverCapabilities.fixedReadLeaves`: a list of leaf names
(`z.enum(FIXED_READ_LEAF_NAMES)`), today `['SharedRecordIds']`; absence
= none. It stays separate from `readableIdsLeaf`. A `ReadableIds` leaf
is not a fixed-read leaf, and a fixed-read leaf inside a composed
`ReadableIds` scope needs both bits, because a driver without
`readableIdsLeaf` refuses the composed leaf (ADR-0139 D3). Both
describes now point at each other. The name vocabulary
(`FIXED_READ_LEAF_NAMES`, `FixedReadLeafName`, `fixedReadLeafNameOf`)
lives in `data/fixed-read-leaf.ts`, beside the brands.
- **Door** (`@objectstack/objectql`, `filter-comparand-shape.ts` and the
array branch in `engine-top-level.ts`). A branded leaf is admitted as a
`$in` comparand. The position walk runs before the list-shape door, so a
misplaced branded leaf (`$nin`, `$eq`, a list member, a filter node, a
nested-relation condition) answers the D4 refusal rather than a non-list
400. An unbranded JSON copy is still `INVALID_FILTER` / 400 at the door.
- **Seam** (`fixed-read-leaf-position.ts` for the walk,
`fixed-read-leaf-seam.ts` for the pass-through). It runs at the executor
boundary after the security scope is composed, and on the predicate
`update` / `delete` paths. The leaf is handed to the driver by reference
only when all of these hold:
- **position:** on `id` of the object the leaf names, directly or inside
a composed scope over that object;
- **verb and form:** a read verb with the read form, or a predicate
`update`'s `where` with the write form (③ A). Otherwise it is refused;
- **recipient:** the context's user or its delegator; a system context
is exempt;
- **class:** outside both D4 classes, i.e. the object is on the same
datasource as `sys_record_share`, and no middleware and no `beforeFind`
/ `afterFind` hook is registered for `sys_record_share` by name;
- **driver:** the target driver's `fixedReadLeaves` names the leaf.
Anything else is refused before any driver is asked.
- **Refusal** (`@objectstack/core`, `utils/fixed-read-leaf-refusal.ts`).
`fixedReadLeafRefusal` / `refuseFixedReadLeafOnce` /
`describeFixedReadLeaf` build the one envelope: `INTERNAL_ERROR` / 500,
naming the evaluator, the leaf (its name and its inner-read table, never
the recipient) and the remedy, logged at `error` once per evaluator.
`logRefusalOnce` is factored out of `refuseReadableIdsOnce`, whose
behaviour is unchanged.
- **Filter tokens** (`@objectstack/core`, `utils/filter-tokens.ts`).
`resolveFilterTokens` returns a fixed-read leaf by reference, as it
already does a `ReadableIds` leaf.
- **Conformance** (`@objectstack/spec`,
`data/fixed-read-leaf-conformance.ts`).
- The open-question sentence is dropped.
- 11 seam cases are added (32 in all): the write form on each read verb
and inside a composed scope, and the leaf outside `$in` in five
positions.
- objectql now runs every seam case against the real seam.
### Compile surfaces (one conclusion each)
| Surface | Conclusion |
|---|---|
| `driver-sql` filter compiler | Out of scope (step 3). On this step the
seam refuses before the driver is called, since no driver declares
`fixedReadLeaves`. |
| Turso remote | Out of scope (step 3), for the same reason. |
| analytics `compileScopedFilterToSql` | Out of scope (step 5). The
analytics merges do not admit the brand, so a leaf there is still a
non-list 400. |
| `lowerAnalyticsWhere` | Out of scope (step 5). |
| formula `matchesFilterCondition` | Already compliant on this step. The
seam refuses a leaf in `having` and in `aggregations[].filter` at both
the door and the boundary, so the in-memory matcher never sees one. Its
other callers are step 5's. |
| `driver-memory` | Out of scope (step 4). |
| `driver-mongodb` | Out of scope (step 5). |
### Zone 2 measurements (A to G)
- **A.** No driver declares the leaf: zero `fixedReadLeaves` hits under
`packages/drivers`, `packages/plugins` and `packages/services`. Control:
`readableIdsLeaf: true` hits
`packages/drivers/driver-memory/src/memory-driver.ts:605` and
`packages/drivers/driver-sql/src/sql-driver.ts:415`. D-0 holds. The
pass-through is proven against a recording driver in
`engine-fixed-read-leaf-seam.test.ts`.
- **B.** Step 1 shipped brands (`FixedReadLeafBrand`,
`fixedReadLeafBrandOf`) but no names. The names were added in
`packages/spec/src/data/fixed-read-leaf.ts`, so the declaration is a
list of names, not symbols.
- **C.** Door call sites:
- `engine-top-level.ts:1061` (array branch);
- the `filter-comparand-shape.ts:137` wrapper (object branch, `having`,
aggregation filters).
- The write-path collectors sit beside it at `engine-update.ts:530` and
`engine-delete-and-aggregate.ts:245`.
- **D.** `composeReadableIdsChain`
(`engine-readable-ids-permission-formula.ts:183`) composes the security
scope by reference. `composeReadableIdsLeaves`
(`filter-comparand-shape.ts:263`) returns an unchanged subtree by
reference, so a nested leaf survives composition. The seam descends
every composed scope (`fixed-read-leaf-position.ts`, the `$in` composed
branch).
- **E.**
- ① `resolveDatasourceBinding` (`engine.ts:3436`), already on the
security host.
- ② `hasObjectMiddleware` (`engine.ts:1914`).
- There was no by-name find-hook reader, because `hasHooksFor` counts
global hooks. `hookNamesObject` is added at `engine-top-level.ts:3755`,
and `hooks` is exposed on the security host (`engine.ts:6148`, +1 line).
- **F.** The recipient is compared against `userId` and
`onBehalfOf.userId`
(`packages/spec/src/kernel/execution-context.zod.ts:298`); `isSystem` is
exempt. The seam only reads them and never writes.
- **G.** The seam reads `IDataEngine.getDriverForObject`
(`packages/spec/src/contracts/data-engine.ts:535`) plus
`driverEvaluatesFixedReadLeaf` (`fixed-read-leaf-seam.ts`). No new
public engine method is added.
## Tests
Code readings are at `7473e42d46`, except the patch round 2 block, which
is at head `9e745a0607`.
All readings are local, under the shared verify lock (`VERDICT
command-exit` lines quoted). `test:repo` is not run locally; CI's `Test
Core` owns it.
<details><summary>Patch round 2: a door refusal is logged on the
boundary's flag (head 9e745a0)</summary>
- Every verb's door calls now run through `atFixedReadLeafDoor`
(`fixed-read-leaf-seam.ts`): the `where` lowering of find, findOne,
count, aggregate, update and delete, plus the aggregate's `having` and
per-aggregation `filter` doors. The helper logs the seam's refusal at
`error` on the same per-engine flag `passFixedReadLeaves` uses, then
re-throws it unchanged.
- `pnpm --filter @objectstack/objectql typecheck`: exit 0. The seam
test: `Tests 64 passed (64)`, `VERDICT command-exit 0`.
- New pins in `describe('[ADR-0155 D4] a refusal at the door is logged
on the boundary\'s flag, once per engine')`:
- two misplaced-leaf refusals log one line;
- a door refusal and a boundary refusal share one log, in either order;
- one per door site, nine in all;
- an unbranded copy stays `INVALID_FILTER` / 400, is not logged and does
not spend the flag.
- Ablations, committed first and restored to the HEAD blob
`24ffa64865d4` with `git diff HEAD` empty:
- M1, the door logs nothing: `Tests 11 failed | 53 passed (64)`, the
per-site and two-refusal pins;
- M2, the door logs on its own flag: `Tests 1 failed | 63 passed (64)`,
the share-one-log pin.
- Derived gates for the round's paths: 59 families, all run on
`9e745a0607` and every one exited 0. `--ran` reports `59 run, 0
NOT-MEASURED`. `check:facade-delegation-only` reports `engine.ts: 6854
lines, ceiling 6854 (0 left)`.
</details>
<details><summary>objectql: full local suite, typecheck, seam
test</summary>
- `pnpm --filter @objectstack/objectql exec vitest run --project local
--maxWorkers=2` at `1726a5644b`: `Test Files 620 passed (620)`, `Tests
14038 passed (14038)`, `VERDICT command-exit 0`.
- `pnpm --filter @objectstack/objectql typecheck` plus the seam test, at
`b40270ee52` (after the test's options were typed): `Tests 52 passed
(52)`, `VERDICT command-exit 0`.
- After that, the only commit is `7473e42d46`, a docs-only census row.
</details>
<details><summary>spec and core: typecheck and full local
suites</summary>
- `pnpm --filter @objectstack/spec typecheck`: exit 0.
- `pnpm --filter @objectstack/spec exec vitest run --project local
--maxWorkers=2`: `Test Files 865 passed (865)`, `Tests 27732 passed | 1
todo (27733)`.
- `pnpm --filter @objectstack/core exec vitest run --project local
--maxWorkers=2`: `Test Files 155 passed (155)`, `Tests 3676 passed
(3676)`.
- One locked run, `VERDICT command-exit 0`. Core typecheck: exit 0. Spec
build: `VERDICT command-exit 0`. The closure build `--filter
'@objectstack/objectql^...'`: `VERDICT command-exit 0`.
</details>
<details><summary>Ablation: the recipient rule (one behaviour, one
run)</summary>
- Mutation: `principalAdmitted` in `fixed-read-leaf-position.ts`
short-circuited to `true`, through `scripts/ablation-replace.mjs`. On
disk: `anchor 1 -> 0`, blob `8caf15107ba9 -> 4a7c5bd39384`. The objectql
test imports this source relatively, so no dist rebuild was involved.
- Predicted direction: red on the recipient refusals. Observed: `Tests 5
failed | 47 passed (52)`. The five are:
- any other recipient is refused;
- the recipient rule holds on the write form;
- the recipient rule holds inside a composed scope;
- a delegated operation carrying a third identity's leaf is refused;
- a context with no user and no system flag is refused.
- Restore: `git checkout HEAD -- PATH`. The blob is back to
`8caf15107ba9…` (the HEAD blob), `git diff HEAD` is 0 bytes, and the
tree is clean.
</details>
<details><summary>Reverse type verification (cross-package)</summary>
- Run against the rebuilt `packages/spec/dist/data` declarations: `const
ok: DriverCapabilities = { fixedReadLeaves: ['SharedRecordIds'] }`
compiles (exit 0).
- `{ fixedReadLeaves: ['ReadableIds'] }` is red: `error TS2322: Type
'"ReadableIds"' is not assignable to type '"SharedRecordIds"'` (exit 2).
</details>
<details><summary>Derived gate families (local, final head
7473e42)</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derives 131 families.
- All 131 were run on `7473e42d46`, and every one exited 0.
- `--ran` answers: `131 derived famil(ies) accounted for — 131 run, 0
NOT-MEASURED (a DERIVED zero — all 131 recorded an exit code and none of
them is 3)`.
- The first pass (at `1726a5644b`) went red on two ratchets, both fixed
in this PR:
- `check:query-options-erasure`: the test surface grew 236 to 243. The
seven option bags in the new test are now typed, and the surface is back
to 236.
- `check:system-context-census`: `passFixedReadLeaves` reads `isSystem`
with no row for it. Row 18f was added and the register regenerated.
</details>
## Acceptance notes
- **Metadata-protocol: `added`, `@objectstack/spec` at `minor`** (patch
round 1). The claim spelled `none`, but the diff moves
`packages/spec/authorable-surface/data.json`
(`data/DriverCapabilities:fixedReadLeaves` enters). Under AGENTS.md's
Post-Task step 3, a new key is `added`, as the `readableIdsLeaf`
precedent (#34565) declared. `@objectstack/core` and
`@objectstack/objectql` stay `patch`, following the gate's remedy: raise
the package that carries the protocol change. Under `none`,
`check-changeset-no-major` measured exit 1 (`none-baseline-moved`).
- **Deviations from the dispatch's suggested route**:
1. Leaf names (`FIXED_READ_LEAF_NAMES`, `FixedReadLeafName`,
`fixedReadLeafNameOf`) are added to spec. Step 1 shipped brands only,
and the declaration is a list of names.
2. There are two seam modules, not one. The door walk lives in
`fixed-read-leaf-position.ts` because `engine-top-level.ts` imports the
door, and a single module would close an import cycle.
3. `engine-update.ts` and `engine-delete-and-aggregate.ts` import
`securityResolversHost`, the first importers besides `engine.ts`.
`engine.ts` is at 6854 of its 6854-line ceiling
(`scripts/facade-delegation-registry.json`, 0 left): +1 for the security
host's `hooks`, and +1 in patch round 2 for `count`'s host, which gains
`facade` and `logger`.
4. A misplaced leaf refused at the door is logged at `error` on the same
once-per-engine flag as a boundary refusal (patch round 2,
`atFixedReadLeafDoor`). `judgeFilter` is not logged: it returns the
refusal as a judgement and runs nothing.
5. An array-form `in` / `nin` carrying a leaf stays a 400 from the
authoring lowering (`parseFilterAST`); only `=` lowers it by reference,
and that is refused by name (500).
6. `logRefusalOnce` is factored out of `refuseReadableIdsOnce`; that
function's behaviour is unchanged.
- **Holds respected**: no boot refusal; no producer writes the leaf;
ADR-0147 anchor cases are not pinned; no driver declares
`fixedReadLeaves`.
- **Changeset**: `@objectstack/spec` at `minor`; `@objectstack/core` and
`@objectstack/objectql` at `patch`. No `skip-changeset`.
- **Liveness row**: n/a. `DriverCapabilities` is not a registered
metadata type, and `check:liveness` exits 0.
## Verification
**Files to read first (by risk)**
1. `packages/objectql/src/fixed-read-leaf-position.ts`, the `judge`
hunk. The position, verb and form rules decide what reaches a driver; a
wrong admission here is the only way a leaf passes.
2. `packages/objectql/src/fixed-read-leaf-seam.ts`,
`passFixedReadLeaves`. The recipient, the two classes and the
declaration consult, and the once-per-evaluator log.
3. `packages/objectql/src/filter-comparand-shape.ts`, the wrapper. The
position walk now runs before the list-shape door; this ordering is what
turns a misplaced branded leaf into a 500 instead of a 400.
**Two-minute verification**
`pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2
src/engine-fixed-read-leaf-seam.test.ts` should report `Tests 64 passed
(64)`. That covers all 33 conformance seam cases against the real seam,
plus the recipient, declaration, class, pipeline-written, door and
door-log cases.
L2: this PR owes a contract review (`CONTRACT_REVIEW_TIER`).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibvQwUyVQ6n8wEMcUgF)_
<!-- signed: repo:objectstack#7 · os-tesla ·
session_01L9qibvQwUyVQ6n8wEMcUgF -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f51578e commit d7c257e
32 files changed
Lines changed: 1411 additions & 44 deletions
File tree
- .changeset
- content/docs
- permissions
- references/data
- packages
- core/src
- utils
- objectql/src
- spec
- api-surface
- authorable-surface
- export-origins
- src/data
- scripts/adr-anchors
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
| |||
561 | 562 | | |
562 | 563 | | |
563 | 564 | | |
| 565 | + | |
564 | 566 | | |
565 | 567 | | |
566 | 568 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
| 171 | + | |
| 172 | + | |
172 | 173 | | |
173 | 174 | | |
174 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
| 98 | + | |
| 99 | + | |
98 | 100 | | |
99 | 101 | | |
100 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
212 | 215 | | |
213 | 216 | | |
214 | 217 | | |
| |||
0 commit comments