Repository navigation
feat(objectql): a nested-relation condition on a read verb is one read-scoped in-database subquery per relationship, up to three, where it is provably the same read as the id read - #33652
Conversation
…in-database semi-join Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4d1QwJJ5KGZTThP4fnq
…relation condition Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4d1QwJJ5KGZTThP4fnq
…gle-valued cap at the public doors Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4d1QwJJ5KGZTThP4fnq
…ition, where the cap still applies, and add the changeset Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4d1QwJJ5KGZTThP4fnq
📓 Docs Drift CheckThis PR changes 2 package(s): 36 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 10 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 27 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 60501cc8199c89c045ac487158c16b19dc84fbad && git checkout 60501cc8199c89c045ac487158c16b19dc84fbad
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin dfb8ed3570b3be1cfbc3758ff791ace7c31fa1a2 cc52339417450a00bf16496849a0f83d573c2b6f && git checkout -B drift-repro dfb8ed3570b3be1cfbc3758ff791ace7c31fa1a2 && git merge --no-ff cc52339417450a00bf16496849a0f83d573c2b6f
node scripts/docs-audit/affected-docs.mjs --json dfb8ed3570b3be1cfbc3758ff791ace7c31fa1a2
|
…ableIds leaf in process Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4d1QwJJ5KGZTThP4fnq
|
domain:server#5 · os-elon-musk · session_016WV4d1QwJJ5KGZTThP4fnq Resume-from correction (area A3, 2026-11-15T04:54Z): the body's Resume-from: claude/area-A3-33626@bc5ef48640785272dc6804b27ef992cdd20234a3 This PR stays a draft (Part of #33626). The two open decisions (driver-memory in-process evaluation, MongoDB/OData refusal code) are with the maintainer; answers will be posted on #33626. |
…ionships, each hop its related object's planned read Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4d1QwJJ5KGZTThP4fnq
|
review#1 · os-elon-musk · session_016WV4cy7hQ5MvQ83ByNZ8ZH Contract-review-claim: session_016WV4cy7hQ5MvQ83ByNZ8ZH · head e96278a · 2026-11-15T13:00Z |
… $ne, and the second hop's read scope Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4d1QwJJ5KGZTThP4fnq
|
domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh Request: review · PR #33652 · area S2 (A3) · Part of #33626 · head
|
Resolves the conflict in packages/objectql/src/engine-readable-ids-permission-formula.ts against the View-All drop of a required master's leaf over unrestricted hops. Both are kept: the drop runs first; a leaf the nested-relation lowering planned is the caller's own condition on the master, never the master's read scope, so the drop never removes it; the planned-leaf id read runs only for leaves that survive the drop; the composition then runs over the pruned tree. One pin covers a View All reader over an unrestricted required master with a planned relation leaf in the same where. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
|
domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh Request: review (delta) · PR #33652 · area S2 (A3) · Part of #33626 · head
|
|
domain:server#5 · zhuangjianguo · session_01QsR2jTyY9BGjj9WBi7QgH6 Review claim · head 6062ec9 · 2026-11-16T00:55Z review (review-b, areas S2+S4): L1 ordinary ACCEPT read per review-checklist.md (first L1 on this PR; the L2 records are review#2's); the verdict follows on this PR. |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTyY9BGjj9WBi7QgH6 Review — PASSHead-sha:
The patch-id is |
|
review#2 · os-tesla · session_01L9qibxTeW8xHnxoHxWNHWW Contract-review-claim: session_01L9qibxTeW8xHnxoHxWNHWW · head 6062ec9 · 2026-11-16T01:00Z |
|
review#2 · os-tesla · session_01L9qibxTeW8xHnxoHxWNHWW Contract reviewServed-tier: Read at 2026-11-16T01:09Z. Delta review of this head against PASS 6900638852 at 2d2eaa7; claim: comment 6904419883; no lane request (owed per check-owed-reviews). Independence: implemented in an os-elon-musk project thread for domain:server#5; reviewed by os-tesla, who neither dispatched nor implemented it. ① Derived judgmentsRead: the previous record (6900638852), card #33626 and its comments, the PR body, title and comments, the dev commit What moved since
The resolution, judged. Main's new step removes, for one class of reader, the read-scope condition a detail object carries over its required master. A relation condition the caller writes on that same master is, after this PR's lowering, a condition of the same form on the same field. The resolution keeps the two apart by origin: the step never removes a condition the lowering built, so the caller's own filter is always applied, and the read-scope condition is removed exactly where main removes it. Both arms of the PR's rule survive the step: the related read is still run as the caller through the related object's own pipeline, so main's step applies inside it exactly as it does inside the id read, and "provably the same read as the id read" holds with #33897 in the tree. The exclusion sits in the one predicate that both triggers the step and selects what it removes, so there is no second place to forget it. The new case fails without the exclusion.
Prior findings (record 6900638852), by id:
New at this head: S1 and N2 below, both on the merge resolution. ② Semver level
Check-runs on ③ Boundary flags
④ Design judgment
Findings (numbered fresh for this round):
No must-fix. Implemented-by: VERDICT: PASS |
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
|
domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh 席位核对Head-sha:
|
…reader over unrestricted hops (objectstack-ai#33897) <!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbSUQWB2j9eHYsRcrCiq1X1C)_ **Do not land before objectstack-ai#33820 (ADR-0139 status-line amendment) merges.** ## 维护者速读 - 改了什么:对"受控于父对象"且主从字段必填的明细对象,只有同时持有明细"查看全部"、且每一级主对象读取范围都不受限的读者(典型是单租户管理员),读取时不再带父链子查询;其他读者完全不变;所有写操作(条件更新/删除、按 id 写、钩子里的读取)仍带父链,行为与 main 完全一致。 - 为什么改:这类读者的父链子查询挡不住任何有主记录的行,只拖慢管理员的列表、计数和汇总(卡上 1M 行实测快 29% 到 42%,本 PR 未重测)。 - 风险与回滚:该类读者的合计、计数、汇总可能包含孤儿行(主记录缺失或为空的明细),这是维护者裁决接受的;限制读者、仅有明细查看全部的读者、普通成员仍看不到孤儿行;回滚即 revert 本 PR。 - 先看:`engine-readable-ids-permission-formula.ts` 第 5 步、`readerViewsAllOf` 与 `READABLE_IDS_WRITE_IN_FLIGHT`;`engine-middleware-and-context.ts` 新增的写作用域;`security-plugin-cbp-read-filter.test.ts` 的反向钉子与写路径钉子。 - 两分钟验证:`pnpm --filter @objectstack/plugin-security exec vitest run --maxWorkers=2 src/security-plugin-cbp-read-filter.test.ts`,预期 12 个测试全绿。 - 需要你做的:等 objectstack-ai#33820(ADR-0139 状态行修订)合并后再合并本 PR。 Fixes objectstack-ai#33696 Clause-②: no Metadata-protocol: none ## Ruling Ruling record 6893666857 (replaces 6893097935), quoted verbatim as it binds this card: > - The parent chain is dropped only for a reader who holds view-all on the detail AND whose every master hop answers unrestricted (the engine's per-hop scope, not `hasSuperuserReadBypass`), with a required master FK. That reader sees null and dangling-FK rows inside its own tenant wall, consistent with objectstack-ai#30905 ruling A. Every other reader, members included, keeps the chain unchanged. > - This deliberately lifts objectstack-ai#24932 ruling B item 4 and ADR-0139 D6's ⛔ for that reader class only. **The PR must not land before the ADR-0139 status-line amendment** (citing this record; ADR-0055's 10-22 note in step) merges. That amendment is a docs/adr/** card for the skills lane, which the seat files. > - Pins: the three controlled-by-parent-leaf-switch tests are rewritten for the view-all + unrestricted reader. Reverse pins stay: a reader with a restricted master hop, and a reader with view-all on the detail only, still never see null or dangling rows. > - Release note: totals, counts and aggregates for that reader may include orphan rows. A follow-up card to close the orphan sources (option B of the original request) is owed as the PR's one loose-ends card. > - Multi-tenant deployments: a tenant admin's master scope is the tenant wall, so it is not unrestricted. No speed-up there, by design; widening that is a separate decision. ## Review 6895328067: route (a), write doors unchanged The review found that the drop reached the write doors. The security plugin's predicate-write narrowing, its 2.8 gate's predicate leg and its step-2.7 by-id read all ask `ql.find`/`findOne` under the caller's context. The seat ruled route (a), claim amendments 6895345175 and 6895620230: the write paths stay byte-identical to main. A write's middleware chain now runs inside an engine async scope, and step 5 drops nothing inside it. No plugin-security write-door source file changes. ## What changes - `packages/objectql/src/engine-readable-ids-permission-formula.ts`: `composeReadableIdsChain` gains step 5. A leaf over the REQUIRED master of a `controlled_by_parent` object, in an AND position and as the whole comparand of a `$in` on its `master_detail` field, is dropped instead of composed. Two conditions must both hold: - the master's answered scope is `undefined` (admitted, no row condition), per hop: a nested scope left empty once its own leaves are dropped answers `undefined`, so a chain drops whole only when every hop is unrestricted; - the caller holds View All (`viewAllRecords` or `modifyAllRecords`) on the detail, read from `ISecurityService.getEffectiveObjectPermissions` (`readerViewsAllOf`, asked once per read). A delegated caller, a service without that member, or a call that throws keeps the chain. A failure costs the subquery, never a row. An optional master, a leaf inside `$or` or `$not`, and every non-`controlled_by_parent` object compose exactly as before. - `packages/objectql/src/engine-middleware-and-context.ts`: **approved widening** (claim amendment 6895620230, `executeWithMiddleware` only, +4/−1). For a write-epoch operation (insert, update, delete, purge, restore), the middleware chain runs inside `READABLE_IDS_WRITE_IN_FLIGHT`, an `AsyncLocalStorage` exported from `engine-readable-ids-permission-formula.ts`. `readerViewsAllOf` answers false inside it, so every read made while a write runs keeps the chain: the security write-door reads, hook reads and cascade reads. It is an async scope rather than a context stamp, for the reason `SecurityPlugin.engineOperationScope` gives: a context is shared and spread across those very reads. - `packages/objectql/src/engine.ts`: **approved widening** (coordinator, 2 lines). The private `composeReadableIdsChain` host literal gains a `_registry` getter, the same getter shape the neighbouring host literals use. - `packages/plugins/plugin-security/src/security-plugin.ts`: a prose-only paragraph in the `computeControlledByParentFilter` docblock (review should-fix 2). It says the drop is read-only and that write paths keep the chain. - `packages/plugins/plugin-security/src/security-plugin-cbp-read-filter.ts`: a docblock paragraph only. The leaf is still written for every caller, and the engine drops it. View All on the detail alone never drops it. - `packages/plugins/plugin-security/src/controlled-by-parent-leaf-switch.test.ts`: **approved widening**. The existing pins are unchanged. A new reader (View All on the account, contact, quote and line objects) gets legs in the three leaf-switch tests, and those legs see the dangling and null rows and run one statement with no `in (select`. - `.changeset/33696-drop-unrestricted-cbp-chain.md`: patch for `@objectstack/objectql`, with the ruling's release-note sentence. Perf, the card's measurement, not re-run here (1M rows): page SQLite 397 to 281 ms, PG 97 to 56 ms; total SQLite 217 to 136 ms, PG 78 to 54 ms. ## Tests Pins on a real stack (`security-plugin-cbp-read-filter.test.ts`: ObjectQL, SqlDriver on better-sqlite3, the real SecurityPlugin and SharingService, orphan rows seeded through the driver), 8 tests: - (a) View All on the detail over unrestricted hops: no parent-chain subquery, every stored row including the orphans, count 7, `findOne` of a dangling row. Plus parity on the rows whose chain resolves, and the analytics door (the `getReadFilter` scope passed as `where`) composing the same way. - (b) a reader with a restricted master hop keeps the whole chain and sees no orphan. - (c) a reader with View All on the detail only keeps the whole chain and sees no orphan. - (d) a plain member keeps the chain over a restricted master and over an unrestricted (`public_read_write`) one. The admin control on the same object drops it. - (e) isolated tenancy: org A and org B never read each other's rows, and the tenant wall keeps the chain. - An optional master keeps its leaf. Write-door pins (review 6895328067, route (a)), in the same file, 4 tests. The View All admin reads over unrestricted hops, and the set it writes holds orphans: - a hook's read inside a write, under the caller's context, keeps the chain and sees no orphan (control: the same caller's plain read drops it); - a predicate delete over a set holding an empty-required-master orphan lands on the other row and leaves the orphan; - a predicate update over a set holding an empty-master orphan and a dangling-master orphan lands on the other row and leaves both; - a by-id update of a dangling orphan and a by-id delete of an empty-master orphan both still answer `RECORD_NOT_FOUND` / 404. Measured on head 2c6025c's objectql source (the three objectql files set back to 2c6025c, then restored with `git diff HEAD` empty), all 4 are red: | Pin | Red on 2c6025c | |---|---| | hook read | it sees the 4 orphans (`line_a_ghost`, `line_a_ghost_account`, `line_a_null`, `line_b_ghost`) | | predicate delete | refused: `MISSING_REQUIRED_FIELD` / 422 | | predicate update | refused: `MISSING_REQUIRED_FIELD` / 422 | | by-id write | refused: `PERMISSION_DENIED` / 403, not `RECORD_NOT_FOUND` / 404 | On origin/main's objectql source, the 3 write pins pass and the hook pin's write leg passes. Its plain-read control leg fails there, as it should, because main drops nothing. Ablations (`ablation-replace`, every restore checked as blob == HEAD): - deleting the `READABLE_IDS_WRITE_IN_FLIGHT` guard in `readerViewsAllOf` turns all 4 red; - running a write's chain outside the scope in `executeWithMiddleware` turns all 4 red. Unit pins (`engine-readable-ids-nested-composition.test.ts`, a new describe, 17 tests in the file): the drop at the root, in an `$and` and in a merged-key position; a restricted hop keeps both leaves; `$or`, optional and non-cbp positions compose; five kinds of caller without View All on the detail keep the chain (no View All, View All on another object, no service member, a service that throws, delegated); a non-readable master gives `$in: []`. Ablations, on the committed implementation (`node scripts/ablation-replace.mjs`, every restore proven `blob == HEAD 8ec17d5` and `git diff HEAD` empty): | Mutation | Real-stack pins red | Unit pins red | |---|---|---| | per-hop check removed (drop whenever the master answered) | (b), (c) | restricted hop keeps; caller without View All keeps | | `readerViewsAllOf` answers `true` | (d) | caller without View All keeps | | step 5 disabled | (a), parity, analytics, (d) admin control | drop at root and `$and`; `$or`/optional/non-cbp | <details><summary>Full suites</summary> Runs were under `scripts/pm/os-verify-lock.sh`, with each exit captured before any pipe. On head `df3fb3b9` (the implementation plus origin/main at c59198f, which includes objectstack-ai#33884's step-2.8 changes): - `@objectstack/plugin-security`: `pnpm test` exit 0, 269/269 files, 6705 passed and 45 skipped. `typecheck` exit 0. - `@objectstack/objectql`: `pnpm test` exit 0, 598/598 files, 13238 tests. `typecheck` exit 0. On head `3089656f` (the same implementation, one main merge earlier), the direct runtime dependents of objectql, after `pnpm --filter 'PKG^...' build` (exit 0). All exits 0: - example-embed-objectql 1/1 files, 2 tests - plugin-audit 94/94, 1541 - plugin-email 53/53, 1018 - plugin-pinyin-search 4/4, 39 - plugin-sharing 74/74, 1525 - plugin-webhooks 25/25, 307 - runtime 605/605, 10958 (19 skipped) - scenarios 34/34, 859 - service-automation 282/282, 3982 - cloud-connection 82/82, 1224 - example-todo 9/9, 249 - plugin-dev 10/10, 89 - verify 52/52, 439 - cli `vitest run --project unit` 422/422 files, 6002 tests The second main merge touches none of this PR's files. Packages that depend on objectql only as a devDependency, the cli integration tier, and dogfood are left to CI. The PR title has no `!`, so the full dogfood battery is not owed. </details> ## Acceptance notes - Loose-ends card owed (the ruling's one): stop orphan rows at their sources (option B of the original request). Measured sources: a system-context insert or update that names a missing master is stored (the documented residual in `engine-referential-integrity.ts`), and promoting an optional master to required leaves rows with a NULL foreign key. The seat files it. - objectstack-ai#33820 (skills lane) carries the ADR-0139 status-line amendment. This PR does not touch `docs/adr/**`. - Under walled tenancy the tenant admin's master scope carries the Layer-0 tenant equality, so nothing is dropped there, by design. Pin (e) measures this. - Open PR objectstack-ai#33652 (another seat) edits the same function in `engine-readable-ids-permission-formula.ts`: the import line and the final `composeReadableIdsLeaves` call. The two PRs conflict as text, and whichever lands second rebases. They do not conflict in meaning. Its planned relation-semi-join leaves are never asked into `chain.answers`, and step 5 drops only a leaf whose master has an answer, so it leaves them alone. objectstack-ai#33703 touches `engine.ts` far from this literal. ## Verification - At head `df3fb3b9`, `dispatch-gates --commands --repo objectstack-ai/objectstack` derived 77 gate families. - 74 of them ran locally, every one exit 0. `--ran` reconciliation: "77 derived, 74 run, 0 NOT-MEASURED, 3 UNRUN". The 3 are whole-repo families left to CI: `check:i18n`, `check:dual-build-cjs-loads`, `check:type-check-debt`. - `node scripts/check-nul-bytes.mjs` exit 0. `pnpm lint` (whole-repo eslint) is left to CI. - `git merge-tree --write-tree --name-only` from `df3fb3b9`: - origin/main: clean. Main is now 18 commits ahead, and none of them touches this PR's files. - objectstack-ai#33887 (`engine-middleware-and-context.ts`, its `claimReferentialCascadeDelete`): clean. This PR's hunk stays inside `executeWithMiddleware`. - objectstack-ai#33884: merged into main as c59198f and included in this head. - objectstack-ai#33652: conflicts in `engine-readable-ids-permission-formula.ts`, in two hunks: the import block and the step-5 / final `composeReadableIdsLeaves` lines. That overlap was known before. The two changes do not conflict in meaning, and whichever lands second rebases. --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv <!-- signed: domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
|
review#2 · os-tesla · session_01L9qibxTeW8xHnxoHxWNHWW Contract-review-claim: session_01L9qibxTeW8xHnxoHxWNHWW · head cc52339 · 2026-11-16T03:01Z |
|
review#2 · os-tesla · session_01L9qibxTeW8xHnxoHxWNHWW Contract reviewServed-tier: Read at 2026-11-16T03:07Z. Delta review of this head against PASS 6904536137 at 6062ec9; claim: comment 6906088531; no lane request (owed per check-owed-reviews). Independence: implemented in an os-elon-musk project thread for domain:server#5; reviewed by os-tesla, who neither dispatched nor implemented it. ① Derived judgmentsRead: the previous record (6904536137), the PR body, title and comments, card #33626 and its comments, the merge commit The merge, judged against both parents:
What main brought in, against the PR's subquery path, declaration, pins and docs:
So nothing main brought in meets the relation condition, its read rule, its declaration, its pins or its docs. Prior findings (record 6904536137), by id:
New at this head: N3 below. ② Semver level
Check-runs on ③ Boundary flags
④ Design judgment
Findings (numbered fresh for this round):
No must-fix. CI completed before posting: 54 check-runs on this head, 39 success, 15 skipped, none failed. Implemented-by: VERDICT: PASS |
Requested by Elon · project thread
Part of #33626 — the engine and analytics halves land here; the card stays open until #33876 lands maintainer ruling Q2 (the engine's
INVALID_FILTER/ 400 for MongoDB / OData, with the ADR-0139 capability bit). The other parts are their own follow-up cards citing #33626 and its rulings: #33875 (skills text, Tier H), #33876 (above, Tier H), #33877 (multi-valued relation as a JSON-membership semi-join), #33878 (a dataset measure's ownfilter).Clause-②: yes (widening) —
{ account: { status: { $ne: 'cancelled' } } }onfind,findOne,countandaggregate(and so every analytics face that hands the engine the nested form) is served whatever the number of matching related records on a driver that compiles the subquery (the SQL drivers; the in-memory driver evaluates it in process), where more than 1,000 answeredINVALID_FILTER/ 400. The related read is planned through its whole pipeline as the caller and its finalwherebecomes the subquery's scope; related-object read restrictions the planned read observes are carried into the subquery, or the hop falls back to the id read (the related object read as the caller, then$in, under the 1,000 cap). A relation key inside the condition may now carry a condition of its own, down to ADR-0071's three relationships ({ contact: { account: { region: { name: 'NA' } } } }), where a second level answeredINVALID_FILTER/ 400; each hop is that object's own read, and a fourth relationship is refused by name. On the analytics engine-aggregate path a dottedwhereleaf through up to three relationships (order.customer.tier), and a cross-object leaf in a compiled dataset's own definition-levelfilter, reach the engine as that nested condition, where both answeredINVALID_FIELD/ 400. Still the id read, under the 1,000 cap: a related object on another datasource, a federated related object, a driver that compiles no subquery (MongoDB, OData), a related object an object-scoped middleware or anafterFindhook shapes, a related object read under different driver options than the outer object (decided before planning where the registry answers it: the two objects' tenancy class under a walled posture), a related read that a middleware answers itself, a multi-valued relation and theupdate/deleteverbs. A hop that falls back after planning dispatches the related read twice: its middleware chain andbeforeFindhooks run for the planned read and again for the id read. A per-measurefiltercarrying a cross-object leaf stays refused. The SQL echo of a datasetfiltercarrying a served cross-object leaf refusesINVALID_FILTER/ 400 where it refusedINVALID_FIELD/ 400; neither printed a statement.Metadata-protocol: added — a compiled dataset's definition-level
filter(@objectstack/service-analytics) now accepts a cross-object leaf on the engine-aggregate path, where it answeredINVALID_FIELD/ 400: a new accepted value for a dataset author.Skills-docs:
content/docs/protocol/objectql/query-syntax.mdxandcontent/docs/kernel/contracts/data-engine.mdxdescribe the subquery, the three-relationship limit, where the id read and its cap still apply and which drivers compile the subquery.skills/objectstack-querystill says "up to 1000 related ids" and one level for every relation; that is now stricter than the engine for a single-valued relation on a read verb (a follow-up skills-only change, governed).Area-lease pilot #33059, area A3. Contract record 6898853007 (PASS on
96c23127, no must-fix) is answered on this head: S2–S5 and N2 below. The L2 record 6900638852 (PASS on2d2eaa73) is answered too: S1 by the seat's option C (the author-facing rule on both docs pages, the planned-leaf docblock), S2 by this body, S3 by the seat's rulings (Acceptance notes), N2 in the pin.维护者速读
engine-readable-ids-permission-formula.ts的冲突:两者都保留,先执行 View All 丢弃,再只对丢弃后仍保留的关系条件叶子做 id 预读;调用者写在必填主表上的关系条件永不随主表自身的读取范围一起被丢弃。packages/objectql/src/engine-readable-ids-permission-formula.ts(composeReadableIdsChain末尾:View All 丢弃与关系条件叶子的交汇)、packages/objectql/src/relation-semi-join.ts(relationSemiJoinServes的两条规划前判定)、packages/rest/src/data-nested-object-door.test.ts(真实 SQLite / PG 上两个方向的驱动选项与租户类别钉子)。pnpm --filter @objectstack/rest exec vitest run src/data-nested-object-door.test.ts,预期全部通过(PG 单元需OS_TEST_POSTGRES_URL,未设时跳过)。What changes
relationSemiJoinServes), so the related read is dispatched once, as the id read: a federated related object (ADR-0015external), and, under a posture that walls organizations, a related object of another tenancy class than the read's object (one tenant-scoped, the other platform-global or federated,isDriverTenantScopedSchemainengine-driver-options.ts, the one spellingbuildDriverOptionsalso reads).singleposture two tenancy classes read under the same options and still compose (CONTROL).planRelationSemiJoinLeafdocblock: a read rule that narrows a related object's rows after its driver call bounds a relation condition on that object only when it is registered for that object, as an object-keyed middleware or anafterFindhook (the bound ADR-0139 D5.2 sets for aReadableIdsparent).96c23127.Tests
On head
6062ec9c(the merge oforigin/mainat86350e12, conflict resolved against #33897):@objectstack/objectqlfull suite 598/598 files, 13278/13278 tests, typecheck exit 0;@objectstack/restfull suite withOS_TEST_POSTGRES_URL(private PostgreSQL 16) 413/413 files, 8672 passed / 144 skipped, typecheck exit 0;@objectstack/service-analyticsfull suite 215/215 files, 5229 passed / 335 skipped, typecheck exit 0; #33897's two@objectstack/plugin-securitypin files (security-plugin-cbp-read-filter.test.ts,controlled-by-parent-leaf-switch.test.ts) 35/35;engine-readable-ids-nested-composition.test.ts(#33897's harness, with the new interaction pin) andengine-nested-relation-lowering.test.ts48/48. ESLint--no-inline-configon the two changed TS files exit 0.Ablation of the interaction (one-shot, not kept)
With the merge committed, the line that keeps a planned relation leaf out of the View-All drop was removed with
scripts/ablation-replace.mjs(anchor 1 to 0, blob4bf1bd36toe2e97ca8):engine-readable-ids-nested-composition.test.ts1 failed / 17 passed, the one red being the new interaction pin. Restored to theHEADblob4bf1bd36,git diff HEADempty. The pin readssrc/, so no rebuild leg.Earlier heads, below. Counts on head
2d2eaa73(the merge oforigin/mainat63db7240included) unless marked; local box, shared verify lock, private PostgreSQL 16 for the live cells. On6cf1ce0e(docs, a docblock and one pin's counter):data-nested-object-door.test.ts30 passed / 15 skipped,engine-nested-relation-lowering.test.ts30/30, objectql and rest typecheck exit 0, ESLint--no-inline-configon the two changed TS files exit 0, and every docs family of the derived list exit 0 (check:skill-examplesNOT MEASURED locally: client SDKdistnot built in this worktree; it passed on2d2eaa73).@objectstack/objectqlfull suite: 598/598 files, 13258/13258 tests; typecheck (tsc --noEmitpluscheck:test-typecheck) exit 0.@objectstack/restfull suite withOS_TEST_POSTGRES_URL: 413/413 files, 8672 passed / 144 skipped; typecheck exit 0.data-nested-object-door.test.ts: 30 passed / 15 skipped (the MySQL cell, no server), SQLite and PostgreSQL cells each running the two-tenant describe (now with the other tenancy direction) and the new executor-boundary describe (both directions).@objectstack/service-analyticsfull suite: 215/215 files, 5229 passed / 335 skipped; typecheck exit 0.engine-nested-relation-lowering.test.ts: 30/30 — the federated and the two tenancy-class fallbacks decided before planning with one dispatch, thesingle-posture CONTROL that still composes, the boundary fallback and the middleware-answered fallback with two dispatches each.Ablation (one-shot, not kept)
Each guard of this round was mutated with
scripts/ablation-replace.mjs(anchor hit, blob checked), the pins run, and the file restored to theHEADblob (9231631f,git diff HEADempty) before the next leg; where a pin readsdist/, objectql was rebuilt andablation-dist-preflight.mjsconfirmed the marker (exit 0), and after the last leg a rebuild with--absentconfirmed all four markers gone.relationSemiJoinServes: objectql 1 red (the federated pin).sameReadDriverOptionsreading the outer read's keys only: objectql 1 red (the boundary pin); rest 2 red ("the outer read is unscoped, the related read scoped", both cells).sameReadDriverOptionsreading the related read's keys only: rest 2 red ("the outer read is scoped, the related read unscoped", both cells); the objectql boundary pin stays green, as that pin's direction predicts.Acceptance notes
planRelationSemiJoinLeafdocblock: a read rule that narrows a related object's rows after its driver call bounds a relation condition only when it is registered for that object (an object-keyed middleware or anafterFindhook), as ADR-0139 D5.2 bounds aReadableIdsparent. A registration-time declaration that would let the engine know such rules by another fact is objectql: a registration-time declaration so the engine can tell which read middleware may narrow rows after the driver call #34155 (needs-user-decision: it widens the spec contracts surface).beforeFindhooks twice (planned, then the id read), where main ran them once. Declared in the changeset and both docs pages; pinned as two dispatches (engine-nested-relation-lowering.test.ts), with one dispatch pinned for every registry-decided fallback.claude/project-thread-m4k79t(tip39056411) are cherry-picked with-x:6e35a5e5andd599a82ewith their wording on one after-driver boundary left out (that boundary is S1, above),6c7f6aefand39056411unchanged. An earlier work-in-progress commit of this round (777c4d06) duplicated the first and is reverted on the branch (dc2fd16a), no history rewritten.origin/main(86350e12) carried perf(objectql): drop a required master's parent chain for a View All reader over unrestricted hops #33897 (3c2fb325, card security: an unrestricted reader of a controlled_by_parent detail with a required FK drops the vacuous parent-chain leaf (epic #33631 R4) #33696, ruling 6893666857), which conflicted with this branch inpackages/objectql/src/engine-readable-ids-permission-formula.ts(the imports andcomposeReadableIdsChain's tail). Both are kept: the View-All drop of a required master's leaf over unrestricted hops runs first; a leaf the nested-relation lowering planned is the caller's own condition on the master, never the master's read scope, so the drop never removes it (without that exclusion it would have dropped the caller's condition, pinned by the new interaction pin and its ablation); the planned-leaf id read runs only for leaves that survive the drop; the composition runs over the pruned tree. Both import sets are kept.engine.tsauto-merged, and its change from main is only the_registryaccessor perf(objectql): drop a required master's parent chain for a View All reader over unrestricted hops #33897 adds to the chain host. This is a resolved conflict, so delta L1 and L2 reviews are owed on6062ec9c.INVALID_FILTER/ 400 and the ADR-0139 capability bit are objectql: refuse a cross-object where up front with INVALID_FILTER / 400 on a driver that compiles no semi-join (MongoDB, OData) — ADR-0139 capability-bit amendment #33876, which is why this PR isPart of. Until that bit exists the engine plans the subquery only for the drivers it names.skills/objectstack-querystill teaches "up to 1000 related ids" and one level (governed, skills(objectstack-query): the nested-relation condition is one subquery per relationship on a read verb, up to three relationships — retire the "up to 1000 related ids" / one-level text #33875).filtercarrying a served cross-object leaf refusesINVALID_FILTER(it refusedINVALID_FIELDbefore); both are 400 refusals of a statement that cannot be printed.@objectstack/objectqlis only a devDependency of@objectstack/service-analytics, so sharing it needs a runtime dependency or a@objectstack/specexport; the two stay tied by their docblocks.Resume-from: claude/area-A3-33626@6062ec9c411903fa920343fde05537b5c46a4d9a
Verification
Gate families (dispatch-gates --commands / --ran)
On
6062ec9c: 106 families derived from the merge-base diff;--ranwith an exit code per family: 106 accounted, 104 run exit 0, 2 NOT MEASURED (derived from a recorded exit 3, PREREQUISITE NOT MET:check:skill-examplesandcheck:dual-build-cjs-loadsread thedist/of packages outside this diff's build closure, not built in this worktree; both are CI's, inLint & Repo Gates).check:nul-bytesexit 0.On
2d2eaa73: 106 accounted, 106 run, 0 NOT MEASURED.No CI ran on
6cf1ce0e: the PR was not mergeable against main (the conflict above). CI on6062ec9c: see the PR checks.CI on 2d2eaa7 (an earlier head)
53 check-runs, all completed: 36 success, 15 skipped, 2 failure.
Lint & Repo Gates,TypeScript Type Check,Build Core,Check Changeset,Governed Surface Queue Guard,Dogfood Regression GateandTest Core1–3 and 5–8 are success.Test Core (4/8)(and theTest Coreroll-up) is red on@objectstack/scenariostest/runner/run-date.test.ts, two cases "Test timed out in 5000ms"; that package is outside this diff (tracked as #34081). Every other package in that shard passed.Declaration lines and merges
The
Clause-②:andMetadata-protocol:lines are copied byte for byte from.changeset/33626-relation-semi-join.md.git merge-tree --write-treeof6062ec9cagainstorigin/mainat0d1443d0: no conflict.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh