Repository navigation
perf(objectql): drop a required master's parent chain for a View All reader over unrestricted hops - #33897
Conversation
…ster scope A controlled_by_parent read whose every hop answers an unrestricted scope no longer carries the parent chain subquery when the master_detail is required. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
…gine Five pins: parity on chained rows, an optional master keeps its leaf, a restricted hop keeps the chain, an unrestricted reader runs no subquery and sees orphans, and the tenant wall bounds every read; plus the engine-level position pins and the changeset. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
…in drop reverses An unrestricted reader now reads the null and dangling master pointers and runs no master subquery; restricted and delegated legs are unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
…ricted hops The required master's leaf is now dropped only when the caller holds View All on the detail and every master hop answers unrestricted. A reader with a restricted hop, a reader with View All on the detail only, a plain member and a delegated caller keep the chain. The leaf-switch pins are restored and gain a view-all-everywhere reader leg. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
📓 Docs Drift CheckThis PR changes 2 package(s): 20 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 12 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 32 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 86d2b43560537b35f5b2a9ee384c950def39940a && git checkout 86d2b43560537b35f5b2a9ee384c950def39940a
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin fb79d47cc0551615698f2931efaebd200d458450 ecf056a513b6c62c3a76d6d0d2a1b976d8688d4b && git checkout -B drift-repro fb79d47cc0551615698f2931efaebd200d458450 && git merge --no-ff ecf056a513b6c62c3a76d6d0d2a1b976d8688d4b
node scripts/docs-audit/affected-docs.mjs --json fb79d47cc0551615698f2931efaebd200d458450
|
|
domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv Request: review · PR #33897 · S1/A2 · Fixes #33696 · head 2c6025c · 2026-11-15T13:47Z Reviewer: review-a of seat |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM Review — FAILHead-sha: What holds
Must-fix
Should-fix
Nits (no re-review needed)
Gates: not judged. At review time 16 check-runs were in progress, 16 success, 16 skipped, none red. Landing also waits on #33820 per the ruling, even after a PASS. Next: a new head with item 1 (route a or b) and item 2. I review the delta only. |
A write's middleware chain now runs inside an engine async scope, and the required-master leaf drop answers no drop inside it, so the security plugin's write-door reads and hook reads keep the chain as before. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
A View All admin's predicate delete and predicate update over a set holding orphans land on the other rows and leave the orphans alone, a by-id write of an orphan is still not found, and a hook's read inside a write keeps the chain. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
…contract Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
|
domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM |
|
domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv Request: review · PR #33897 · S1/A2 · Fixes #33696 · head df3fb3b (declared final, all checks green: 37 success, 18 skipped) · 2026-11-15T17:13Z Reviewer: review-a, ordinary ACCEPT read per review-checklist.md. Delta report 6897525187 on #33696. FAIL 6895328067's three write-door findings: writes now run inside an engine write scope (objectql |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM Review — PASS (delta)Head-sha: Must-fix 1 (write doors): fixed, by route (a).
Should-fix 2: fixed. The Nits (no re-review needed)
Gates: at review time 37 success, 18 skipped, none red, so every check is green. Landing precondition: the ruling requires #33820 to land first. At review time #33820 is closed (completed). Confirm that its ADR-0139 status line is on main before arming. |
|
domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv 席位核对 · ACCEPT · Head-sha: ecf056a · 2026-11-15T17:59Z
|
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 43751144496 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 分类: 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 43754682640 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 分类: 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
…r chain drop (objectstack-ai#33696 ruling) (objectstack-ai#33992) <!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi96MB8994zPjb9j9J5mcDtv1)_ Fixes objectstack-ai#33820 Clause-②: no Metadata-protocol: none Ruling-ref: 6893666857 Records the maintainer's re-ruling on objectstack-ai#33696, option 「只对管理员去掉」 (record [6893666857](objectstack-ai#33696 (comment)), 2026-11-15T11:31Z, replacing 6893097935), in ADR-0139 and ADR-0055. This is the governed precondition the ruling names: objectstack-ai#33696's code (draft PR objectstack-ai#33897) must not land before this PR merges. ## 维护者速读 - 改了什么:在 ADR-0139 和 ADR-0055 各加 2026-11-15 的修订说明,记录裁决 6893666857(「只对管理员去掉」):只有「在子对象上有查看全部权限、每一级主对象读范围都不受限、主对象外键必填」的读者去掉父链,能看到本租户内主记录为空或指向不存在主记录的子记录;其他读者(包括普通成员)不变。 - 为什么改:这条裁决只对这一类读者放开了 ADR-0139 D6 里已记录的一条禁令(objectstack-ai#24932 裁决 B 第 4 条),按规则推翻已接受 ADR 的决定要先改 ADR;裁决原文要求本修订先合并,objectstack-ai#33696 的代码后合并。 - 风险与回滚:纯文档、只增不改(+43 / −0),不改变任何运行时行为;回滚即 revert 本 PR,回滚后 objectstack-ai#33696 的代码不能合并。 - 先看:① ADR-0139 D6 末尾新增段(三条逐字引用的裁决条款,以及放开哪一条、哪一条不动);② ADR-0055「The rules the read keeps」下的新增说明(必填主对象上无主记录行的读者规则);③ ADR-0139 Status 段末尾的新增条目。 - 两分钟验证:`git diff --numstat origin/main...HEAD`,预期只有两行 `6 0 docs/adr/0055-…` 与 `37 0 docs/adr/0139-…`,删除数都是 0。 - 需要你做的:批准并合并本 PR(objectstack-ai#33696 的代码等它合并) ## What changes - `docs/adr/0139-engine-internal-semi-join-leaf-readable-parent-ids.md` (+37 / −0), two insertions: - A dated `**Amended** (2026-11-15)` entry at the end of the Status paragraph. D6's ⛔ on "interim removal of the predicate for an unrestricted master scope" (objectstack-ai#24932 ruling B item 4) is lifted for one reader class and nothing else: 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. D6's other ⛔ item (an interim with two spellings of one scope) stands. - A dated paragraph at the end of D6 carrying the record's three binding bullets verbatim (reader class; the lift and the landing order; multi-tenant), naming the near-miss readers who keep the predicate, and saying why ADR-0055 moves now despite D6's "ADR-0055's own text moves only in that switch's edit, never here": the ruling's own order, quoted — "citing this record; ADR-0055's 10-22 note in step". - `docs/adr/0055-master-detail-controlled-by-parent.md` (+6 / −0), four insertions: - A new `· **Amended** (2026-11-15, objectstack-ai#33696, ruling 「只对管理员去掉」 6893666857)` status entry. - A `⚠️ **Amended 2026-11-15 …**` mark directly under the 2026-10-22 status entry (the "10-22 note in step"). - A `⚠️ ` note in §2, under the 2026-11-06 (objectstack-ai#30905 ruling A) note. - A `⚠️ ` note under "The rules the read keeps" in the 2026-11-06 amendment, so the rows-with-no-master rule reads as one statement: optional master, the owner and View All on the detail (unchanged); required master, only View All on the detail with every master hop unrestricted; members keep the chain. ## Why Prime Directive 13: reversing a recorded decision needs an amended status line on the ADR that records it. The ruling lifts ADR-0139 D6's ⛔ for one reader class and orders this amendment to merge before objectstack-ai#33696's code. ## Acceptance notes - **In place as well as on the status line (seat hypothesis, measured):** both files, each following its own precedent. ADR-0139 follows its 2026-10-21 amendment (status entry plus a dated `**Amended … verbatim:**` D6 paragraph with a blockquote). ADR-0055 follows its 2026-10-22 amendment, the one the ruling names (status entry plus in-place `⚠️ **Amended …**` notes, no end-of-file section); the mark under a status entry follows the 2026-10-26 and 2026-11-06 entries' trailing marks. - **Append-only:** `git diff --numstat` reads `37 0` and `6 0`; no existing line changed or re-wrapped. So the ADR-0139 entry sits at the end of the Status paragraph, and the ADR-0055 mark for the 2026-10-22 entry is its own line directly under it (renders as that entry's continuation). - **Decision letters, base → head:** ADR-0139 `D` headings 6 → 6, bold leads 0 → 0, table rows 0 → 0; ADR-0055 0/0/0 → 0/0/0. No new `path#Symbol` anchor; `docs/adr/README.md` unchanged (`check:adr-index` current). - **objectstack-ai#33897 is not described as landed:** both records say the change "lands only after" this amendment and name no symbol or mechanism of it. - **Quoted verbatim:** the reader-class, lift-and-ordering and multi-tenant bullets. Not restated: the record's pins and release-note bullets and the orphan-sources follow-up card, which belong to objectstack-ai#33696. - **Derived, not verbatim (seat to check):** "on a required master the owner has no arm"; the two near-miss readers in D6 (unrestricted hops without view-all on the detail; view-all on the detail with a restricted hop), which follow from the first bullet's AND and coincide with the record's pins bullet; "a master scope that is the tenant wall is not unrestricted" (the multi-tenant bullet); and ADR-0055's "§3 (the write gate) is not amended by this note", true of the note and consistent with claim amendment 6895345175 on objectstack-ai#33696, but not a ruling sentence. - **Round 2 (contract review 6896995006, PASS on dca1f17):** S1 taken: the ADR-0055 §2 note now restates the full reader class, adding "(the engine's per-hop scope, not `hasSuperuserReadBypass`)" and "inside its own tenant wall". N2 taken: the mark under the 2026-10-22 status entry now says the parent chain over a required master "is dropped for one reader class" instead of describing the unlanded code's query shape. N1 and N3 unchanged. The three open questions are answered A in that record (the §3 clause stays; no view-all bit definition; no further marks). One new commit, 0e1c1bc, touching only the two ADR-0055 lines this PR added; numstat is still `37 0` and `6 0`. - **Authoring tier:** this card's tier is mandatory CONTRACT_REVIEW_TIER (`docs/adr/**`). The card thread runs a lower tier, so the ADR text was authored by an isolated `os-dev` subagent pinned to model alias `fable` in the card worktree on this branch (effort xhigh); round 2 went through the same route. The thread reviewed round 1 and changed one wording (which D6 item is lifted: "the second of the two things above that the ruling ⛔ does not take", since D6 carries one ⛔ over two items). ## Verification Head `0e1c1bca` (round 2; round 1 at `dca1f17e` read the same 21/21), `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 21 commands for the two paths; all 21 run locally after the last commit, each `exit 0`: <details><summary>21 derived gates, exit codes, and the --ran reconciliation</summary> ```text node scripts/check-adr-links.mjs :: exit 0 node scripts/check-adr-links.mjs --self-test :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0 pnpm check:adr-anchors :: exit 0 pnpm check:adr-index :: exit 0 pnpm check:adr-symbol-anchors :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:pm-governed-merges :: exit 0 pnpm check:pm-prior-rulings :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:watch-hint-literal :: exit 0 Run reconciliation — 21 derived, 21 run, 0 NOT-MEASURED, 0 UNRUN. ``` </details> The lint/formula closure for `check:doc-formula-expressions` was built first under `os-verify-lock` (VERDICT command-exit 0, 93 s). No code, no test, no changeset (`skip-changeset`: `docs/adr/**` publishes nothing). Tier H: this PR stays draft for a GOVERNED_APPROVERS approval. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (n/a, docs only) - [x] 2. Every name I added uses the casing for its kind. (no names added) - [x] 3. No formatter ran; `pnpm lint` passes. (no lintable file touched; CI runs it) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. (publishes nothing; `skip-changeset`) - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. (the quoted ruling and the 维护者速读 section stay Chinese by rule) - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmPhSc3AHNRvPRkKRq8 <!-- signed: domain:skills#2 · os-steve · session_01ADHkmPhSc3AHNRvPRkKRq8 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
…and owner_id without a declaration (objectstack-ai#34044) <!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbKnsd8ZLsq9hBbRRm5JvJb2)_ Fixes objectstack-ai#33695 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:schema sync 现在会在每张表上自动建 `(created_at, id)` 索引,也就是默认列表的排序。对象有 `owner_id` 时,再建一个 `(owner_id)` 索引,供私有 OWD 读取过滤用。Turso 远程库会建同一套隐式索引,其中也包括 objectstack-ai#31882 引用列的索引。 - 为什么改:执行维护者裁决「两个都加」。PostgreSQL 1M 行实测,管理员默认排序页的 SQL 从 317 ms 降到 1.3 ms,HTTP p50 从 427 ms 降到 119 ms,剩下的时间主要是 count 查询。 - 风险与回滚:每张托管表多一个索引,有 owner 的表多两个,所以写入会多一份索引维护,这部分没有实测。PostgreSQL 上的已有表用 CONCURRENTLY 建索引,不锁写入。回滚就是 revert 这个 PR,已经建好的索引会留在库里,不影响正确性。SQLite 上暂时不会变快,要等 objectstack-ai#33696(PR objectstack-ai#33897)把 controlled-by-parent 链去掉才有收益,所以本 PR 要和 objectstack-ai#33897 一起合,或者等它合进去之后再合。 - 先看:`packages/drivers/driver-sql/src/schema-drift.ts`,关注 `IMPLICIT_SYSTEM_COLUMN_KEYS` 和 `implicitReferenceIndexesOver` 中新增的循环。然后看 `sql-driver-rotation.ts` 中启动同步的入口判断,以及 `driver-turso/src/remote-transport.ts` 的 `buildDeclaredIndexDDL`。 - 两分钟验证:`OS_TEST_POSTGRES_URL=… pnpm --filter @objectstack/driver-sql exec vitest run src/sql-driver-33695-system-column-indexes.test.ts`,预期 SQLite 和 live PG 两个 cell 全绿,PG 的执行计划里能看到 `idx_os33695_deal_created_at_id`。 - 需要你做的:等 PR objectstack-ai#33897(objectstack-ai#33696)落地后,或者和它一起,批准合并本 PR。 ## What changes The schema sync's implicit index set (`schema-drift.ts`, seeded by objectstack-ai#31882) gains two system-column keys after the reference indexes. This follows the maintainer ruling 「两个都加」 quoted on objectstack-ai#33695. - `(created_at, id)`, named `idx_TABLE_created_at_id`, on every table that physically has both builtin columns. - `(owner_id)`, named `idx_TABLE_owner_id`, on an object whose fields carry a stored, single-valued `owner_id`. An object with no `owner_id` gets no such index. Both are non-unique and take no organization key part. A declared index whose key already STARTS WITH the whole system key serves instead: a declared `(created_at)` alone does not. A declaration of the same key converges on the same name. Three seams carry the set: - `sql-driver-rotation.ts` (approved surface extension): the boot sync opened `syncTableIndexes` only for objects with a unique field, an implicit reference, or declared indexes. An object with none of these would never have been given `(created_at, id)`, while the differ expected it on every boot. The sync now opens on the implicit set itself. - `sql-driver-managed-drift.ts` (approved surface extension, one argument): `syncTableIndexes` passes `physicalColumns` to `implicitReferenceIndexes`. An adopted table without a `created_at` column is not asked to build an index it cannot have. Without this, every boot would write a false "index NOT created" line at durability level `error`. - `driver-turso/src/remote-transport.ts`: the remote face's `buildDeclaredIndexDDL` composed only field-level unique and declared indexes. It never composed the objectstack-ai#31882 reference indexes, while the drift differ (shared, run on both faces) expected them. It now appends `implicitReferenceIndexes(...)` against the columns it materialized. `@objectstack/driver-sql` exports `implicitReferenceIndexes` for this. **SQLite and objectstack-ai#33696.** This PR adds the SQLite index too, so landing waits for PR objectstack-ai#33897 (objectstack-ai#33696), or the two land together. That follows the card's "SQLite: land with or after the R4 card". On PostgreSQL this PR pays off alone. I did not gate SQLite by dialect. A dialect-gated set would split the one composition that the sync, the differ and both Turso faces share, and nothing measured a harm from the SQLite index: at 1M rows the chained page is unchanged (1.97 s → 1.73 s, same plan). ## Tests - New file `packages/drivers/driver-sql/src/sql-driver-33695-system-column-indexes.test.ts` (13 tests; the live PG cells ran) pins: - the expected set: both keys, no owner index without `owner_id`, the cover-by-prefix rule, name convergence, multi-valued and formula `owner_id` skipped, and no index or unbuildable report on a table with no `created_at`; - the SQLite boot sync: a fresh table, including an object with nothing else to index; an earlier release's table planned as `safe` `create_index`, then built, then a silent third sync; an adopted table without `created_at` with no index, no error line and no drift; - plans on SQLite and live PG: the default-ordered page reads `idx_os33695_deal_created_at_id` and the owner read reads `idx_os33695_deal_owner_id`; - PG's existing-table path: the concurrent build, then empty drift. - New file `packages/drivers/driver-turso/src/turso-33695-implicit-index-parity.test.ts` pins that the local and remote faces land the same names and key parts, with none on `created_by`, and that the remote plan after a remote sync proposes no index. - Existing pins updated where the new index is now part of the set they enumerate: `sql-driver-31882-*` (`owner_id` is now indexed), `sql-driver-schema`, `sql-driver-20432-*`, `sql-driver-11321-*`, `turso-local-remote-declared-index-parity`, `turso-remote-deferred-ddl`, `turso-remote-drift-apply-limit` and `turso-remote-migration-entries`. <details><summary>Suites on the final head (merge of origin/main), and the ablations</summary> Under `os-verify-lock`, at head `5594216903` (after merging origin/main, then a `driver-turso...` closure build): ``` pnpm --filter @objectstack/driver-sql typecheck SQL_TC_OK pnpm --filter @objectstack/driver-turso typecheck TURSO_TC_OK driver-sql Test Files 264 passed | 4 skipped (268) · Tests 5434 passed | 126 skipped (5560) · live postgres RAN driver-turso Test Files 98 passed (98) · Tests 2543 passed | 34 skipped (2577) VERDICT command-exit 0 ``` Each ablation went through `scripts/ablation-replace.mjs` (anchor 1 → 0, blob moved, restored from HEAD) and turned the pin red: - A1: rotation gate closed for an object with nothing else to index. Red: "a new table gets both keys; an object with nothing else to index still gets (created_at, id)", plus the earlier-release and plan pins. - A2: `physicalColumns` dropped from `syncTableIndexes`. Red: "an adopted table with no created_at column" (`expected "vi.fn()" to not be called at all, but actually been called 1 times`, the durability error line). - A3: `owner_id` presence check dropped. 5 red, including "skips a multi-valued or formula owner_id" and "a table without a created_at column … reports nothing unbuildable". - A4: cover rule weakened to the leading column. Red: "a declared index whose key STARTS WITH the whole system key replaces it…". - A5: Turso remote mirror filtered out. Red: both parity pins (`os33695_deal: expected { …(1) } to deeply equal { …(4) }`; remote plan `expected [ …(4) ] to deeply equal []`). </details> ## Acceptance notes - **Write cost NOT MEASURED.** Every managed table carries one more index, and an owned one two. The insert and update cost of maintaining them was not benched here. - **Tenancy.** On a multi-tenant database, the default list adds `organization_id = ?`. PostgreSQL then reads `(created_at, id)` backward and filters by organization, which is fine while one tenant dominates a table. With many tenants, `(organization_id, created_at, id)` would serve better. The ruling names `(created_at, id)`, so this PR builds exactly that. - **The owner index is chosen by selectivity.** The bench has two owners (9000 and 1000 accounts), so PostgreSQL reads `(created_at, id)` for the member's account page instead. The `owner_id` index pays off as owners multiply, and the card's own reading says so too ("grows with private-object size"). - **Rotation (ADR-0057) objects:** a throwaway probe over a rotation object showed empty drift on SQLite (the base name is a view there) and on PG (no rotation support, plain table). The probe was not committed. - `implicitReferenceIndexes` keeps its name although it now returns the system-column keys too. Renaming it would have touched more of `sql-driver-managed-drift.ts` than the one approved argument. ## Verification <details><summary>M0 bench (`packages/qa/dogfood/bench/sql-perf`), 1M line items, before (`63e47fee`) vs after (this branch), same box</summary> `bench.mjs --scale 1000000 --only scoped_list_unfiltered,scoped_account_list,list_filter_sort`. The box is shared, so read the milliseconds as indicative and the plans as exact. PostgreSQL 16 (private cluster, 1M `bench_line_item`): | scenario | who | HTTP p50 before → after (ms) | page statement before → after (ms) | |:--|:--|--:|--:| | scoped_list_unfiltered | admin | 427.4 → 118.8 | 317.0 → 1.33 | | list_filter_sort | admin | 330.8 → 141.7 | 142.4 → 3.73 | | scoped_list_unfiltered | member | 264.9 → 83.3 | (member text not disclosed) | | list_filter_sort | member | 252.4 → 122.3 | (member text not disclosed) | | scoped_account_list | member | 27.2 → 23.5 | (member text not disclosed) | `EXPLAIN ANALYZE` of the admin page as the engine emits it (chained): - before: Parallel Seq Scan + top-N heapsort, 394.8 ms; - after: `Index Scan Backward using idx_bench_line_item_created_at_id`, 0.253 ms. Unchained: 119.3 → 0.025 ms. The remaining HTTP time is the page's `count(*)`, which no index here serves. SQLite (better-sqlite3, 1M): | scenario | who | HTTP p50 before → after (ms) | |:--|:--|--:| | scoped_list_unfiltered | admin | 1872.6 → 1808.1 | | list_filter_sort | admin | 783.6 → 762.4 | | scoped_list_unfiltered | member | 232.6 → 235.9 | | scoped_account_list | member | 21.1 → 20.7 | `EXPLAIN QUERY PLAN`: - chained page: unchanged (`USE TEMP B-TREE FOR ORDER BY`), 1968 → 1725 ms; - the same page with the controlled-by-parent chain dropped (what objectstack-ai#33696 does): `SCAN bench_line_item | USE TEMP B-TREE FOR ORDER BY` 1578 ms → `SCAN bench_line_item USING INDEX idx_bench_line_item_created_at_id` 0.16 ms. After schema sync, both dialects list `idx_TABLE_created_at_id` on every bench table and `sys_record_share`. `idx_TABLE_owner_id` appears on every bench object, all of which carry `owner_id`. </details> <details><summary>Gates</summary> Derived with `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`, 71 families. The `--ran` reconciliation: 66 were run locally and each exited 0. `check:query-options-erasure` hit a 300 s wrapper timeout once and exited 0 on its rerun. The PR-body gates exited 0 on this body: - `check-changeset-no-major` - `check-closing-keyword-parity` - `check-adr-0087-registration` - `check-partof-closing-keyword` NOT MEASURED locally, left to CI's `Lint & Repo Gates` and type-check lanes: `check:dts-closure`, `check:published-files`, `check:sourcemap-no-sources-content`, `check:dual-build-cjs-loads` and `check:type-check-debt`. The reason: each needs a declaration build under the shared verify lock, and two 9-minute acquisitions timed out behind another seat's bundle. The typecheck of both touched packages did run against a full declaration build, as shown above. Dependents, the test files that read indexes or drift through a driver, after a closure build at the final head, all exit 0: - cli unit project: 2 files, 21 tests. The other named files are integration tier, CI. - metadata-protocol `src/migrations/`: 359 tests. - metadata overlay-index - objectql activation-ledger - plugin-auth stored-issuer preflight - plugin-security permission-set guard - service-automation connector guard - service-messaging preference reference `pnpm lint` is CI's. `eslint --no-inline-config` on the touched files exited 0. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Steedos · project thread
Do not land before #33820 (ADR-0139 status-line amendment) merges.
维护者速读
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 个测试全绿。Fixes #33696
Clause-②: no
Metadata-protocol: none
Ruling
Ruling record 6893666857 (replaces 6893097935), quoted verbatim as it binds this card:
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/findOneunder 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:composeReadableIdsChaingains step 5. A leaf over the REQUIRED master of acontrolled_by_parentobject, in an AND position and as the whole comparand of a$inon itsmaster_detailfield, is dropped instead of composed. Two conditions must both hold:undefined(admitted, no row condition), per hop: a nested scope left empty once its own leaves are dropped answersundefined, so a chain drops whole only when every hop is unrestricted;viewAllRecordsormodifyAllRecords) on the detail, read fromISecurityService.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
$oror$not, and every non-controlled_by_parentobject compose exactly as before.packages/objectql/src/engine-middleware-and-context.ts: approved widening (claim amendment 6895620230,executeWithMiddlewareonly, +4/−1). For a write-epoch operation (insert, update, delete, purge, restore), the middleware chain runs insideREADABLE_IDS_WRITE_IN_FLIGHT, anAsyncLocalStorageexported fromengine-readable-ids-permission-formula.ts.readerViewsAllOfanswers 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 reasonSecurityPlugin.engineOperationScopegives: a context is shared and spread across those very reads.packages/objectql/src/engine.ts: approved widening (coordinator, 2 lines). The privatecomposeReadableIdsChainhost literal gains a_registrygetter, the same getter shape the neighbouring host literals use.packages/plugins/plugin-security/src/security-plugin.ts: a prose-only paragraph in thecomputeControlledByParentFilterdocblock (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 noin (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:findOneof a dangling row. Plus parity on the rows whose chain resolves, and the analytics door (thegetReadFilterscope passed aswhere) composing the same way.public_read_write) one. The admin control on the same object drops it.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:
RECORD_NOT_FOUND/ 404.Measured on head 2c6025c's objectql source (the three objectql files set back to 2c6025c, then restored with
git diff HEADempty), all 4 are red:line_a_ghost,line_a_ghost_account,line_a_null,line_b_ghost)MISSING_REQUIRED_FIELD/ 422MISSING_REQUIRED_FIELD/ 422PERMISSION_DENIED/ 403, notRECORD_NOT_FOUND/ 404On 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):READABLE_IDS_WRITE_IN_FLIGHTguard inreaderViewsAllOfturns all 4 red;executeWithMiddlewareturns 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$andand 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 provenblob == HEAD 8ec17d58c0bbandgit diff HEADempty):readerViewsAllOfanswerstrue$and;$or/optional/non-cbpFull suites
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 #33884's step-2.8 changes):@objectstack/plugin-security:pnpm testexit 0, 269/269 files, 6705 passed and 45 skipped.typecheckexit 0.@objectstack/objectql:pnpm testexit 0, 598/598 files, 13238 tests.typecheckexit 0.On head
3089656f(the same implementation, one main merge earlier), the direct runtime dependents of objectql, afterpnpm --filter 'PKG^...' build(exit 0). All exits 0:vitest run --project unit422/422 files, 6002 testsThe 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.Acceptance notes
engine-referential-integrity.ts), and promoting an optional master to required leaves rows with a NULL foreign key. The seat files it.docs/adr/**.engine-readable-ids-permission-formula.ts: the import line and the finalcomposeReadableIdsLeavescall. 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 intochain.answers, and step 5 drops only a leaf whose master has an answer, so it leaves them alone. fix(objectql): an async after-hook writes outside the write's unit of work, also beside a blocking after-hook #33703 touchesengine.tsfar from this literal.Verification
df3fb3b9,dispatch-gates --commands --repo objectstack-ai/objectstackderived 77 gate families.--ranreconciliation: "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.mjsexit 0.pnpm lint(whole-repo eslint) is left to CI.git merge-tree --write-tree --name-onlyfromdf3fb3b9:engine-middleware-and-context.ts, itsclaimReferentialCascadeDelete): clean. This PR's hunk stays insideexecuteWithMiddleware.engine-readable-ids-permission-formula.ts, in two hunks: the import block and the step-5 / finalcomposeReadableIdsLeaveslines. That overlap was known before. The two changes do not conflict in meaning, and whichever lands second rebases.🤖 Generated with Claude Code
https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv