Repository navigation
feat(driver-sql, driver-turso): compile the SharedRecordIds fixed-read leaf to an in-database subquery (ADR-0155 step 3) - #35893
Conversation
…d leaf to an in-database subquery (ADR-0155 step 3) driver-sql's filter compiler and the Turso remote transport compile a SharedRecordIds leaf, as the $in comparand of a field, to its fixed inner read: field IN (SELECT record_id FROM sys_record_share WHERE object_name = ? AND recipient_type = ? AND recipient_id = ? [AND access_level IN (...)] AND record_id IS NOT NULL AND record_id <> ?), every value bound, with no tenant scope on the subquery (ADR-0155 1 ruled A) and the outer statement's wall untouched. Oracle omits the <> '' half, since it stores '' as NULL. Both faces declare fixedReadLeaves: ['SharedRecordIds'] in this commit: SqlDriver declares it, and TursoDriver inherits it in every mode now that its remote transport compiles the leaf with its own compiler. A leaf anywhere else is refused with ADR-0139 D3's envelope (INTERNAL_ERROR / 500), logged once per driver. The tenant chokepoint guard reads the new builder, so its absence of a tenant scope is recorded as an EXEMPT entry citing the ruling. The shared case-set gains the cross-organization nested witness (step 1's L2 N4): note n5 names d7, whose only grant is stamped org_b. Claude-Session: https://claude.ai/code/session_01L9qibyXo4gSy8DJPNz4ANz Co-authored-by: Claude <noreply@anthropic.com>
…ialect and on both Turso faces (ADR-0155 step 3) The shared case-set runs on every live dialect cell and on both Turso faces, find and count; the predicate update's two statements (the prior-row find and updateMany, same AST) each answer the write-form cases' rows, and each reads the grants as they stand when it runs. A record whose id is the empty string witnesses the <> '' half of the blank-id guard (step 1's L2 N4). O2: the leaf answers today's list's rows for case and padding variants, and for an INTEGER federated key on SQLite. The compiled statement is pinned on SQLite, PostgreSQL, MySQL, SQL Server and Oracle; refusals assert code and status. Also: a changeset, and ADR anchors for the three files whose behaviour ADR-0155 decides. Claude-Session: https://claude.ai/code/session_01L9qibyXo4gSy8DJPNz4ANz Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 3 package(s): 28 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 11 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 178 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 5a04db8b66c157753a53d459a126ea8ffb9afedf && git checkout 5a04db8b66c157753a53d459a126ea8ffb9afedf
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin f44758b21e61094570ee9c04bfe26f228ffefdf7 71324295d471099c8ab8926e1b44ddace72ce7ae && git checkout -B drift-repro f44758b21e61094570ee9c04bfe26f228ffefdf7 && git merge --no-ff 71324295d471099c8ab8926e1b44ddace72ce7ae
node scripts/docs-audit/affected-docs.mjs --json f44758b21e61094570ee9c04bfe26f228ffefdf7
|
|
repo:objectstack#7 · os-tesla · session_01L9qibyQBB3KuDoNobNq9LH L1: REWORK at
|
…aredRecordIds compile (ADR-0155 step 3) The changeset said the compile covers every dialect without saying that on PostgreSQL an object whose id column is not text fails the subquery with DATABASE_ERROR 42883. It now says so, says the case is open on its own decision card (ADR-0155 D-0) and settled before the sharing plugin writes the leaf, and says which dialects ran live and which are pinned at compile shape. Claude-Session: https://claude.ai/code/session_01L9qibyXo4gSy8DJPNz4ANz Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#7 · os-tesla · session_01L9qibyQBB3KuDoNobNq9LH L1 delta: ACCEPT at
|
|
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz Contract-review-claim: session_01L9qibyXo4gSy8DJPNz4ANz · head 7132429 · 2026-11-20T18:27Z L1 ACCEPT 7047412922 (delta, on this head). The CONTRACT_REVIEW_TIER review runs as an isolated sub-agent of this card thread; its record and the filled brief follow on this PR. |
|
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz Contract reviewServed-tier: Read: card #35872 (body, triage 7042499013, claim 7043112112, reports 7046516194 and 7047340985), PR #35893 (body, 16 files, net diff from Check-runs on this head: 78 runs, 61 success, 17 skipped, 0 failure, none pending. ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentNo must-fix, no should-fix.
The implementing files agree with the contract.
Nits, none with an effect on correctness or the contract:
Implemented-by: VERDICT: PASS |
|
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz The brief handed to the isolated CONTRACT_REVIEW_TIER sub-agent whose record is 7047602668 (PASS on Contract review brief — PR #35893 @
|
|
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz Landing · 2026-11-20T18:39Z · head
|
| Probe | Reading |
|---|---|
check-governed-merges.mjs --pr 35893 |
NOT governed: 0 of 16 paths hit the register; 1,134 changed lines ≤ 3,000 |
landing-k.mjs --pr 35893 |
K = 3 < 15; no new locale pack; no shared book moved |
overlap-check.mjs |
clean against origin/main, 0 PR heads |
| Reviews on this head | L1 ACCEPT 7047412922 (delta after REWORK 7046597905); L2 CONTRACT_REVIEW_TIER PASS 7047602668 (brief 7047621799), no must-fix, no should-fix |
| Check-runs on this head | every check success or skipped by its own selector, 0 failure |
State: needs:contract-review removed with the brief; ready + auto-merge armed by this stroke. On merge, #35872 closes by Fixes; its close-out follows. O2's PostgreSQL non-text key is on #35906 (#33787 Blocked-by it).
Requested by Tesla · project thread
Fixes #35872
The one item round 0 left open, O2's non-text outer key on PostgreSQL, moved to its own decision card, #35906 (ADR-0155 D-0). This PR carries every other item of the card.
Refs #33787
Clause-②: yes
Metadata-protocol: none
维护者速读
What changes
The SQL drivers now compile the
SharedRecordIdsfixed-read leaf. This is ADR-0155 plan step 3. Nothing on main writes the leaf yet; step 6 (the plugin-sharing switch) will.driver-sql). A leaf in a field's$incompiles to one subquery in the list's own position:id IN (SELECT record_id FROM sys_record_share WHERE object_name = ? AND recipient_type = 'user' AND recipient_id = ? AND record_id IS NOT NULL AND record_id NE ''). HereNEstands for SQL's not-equal operator.AND access_level IN (…)inside the subquery.''as NULL.driver-turso).RemoteTransportis its own compiler. It builds the same subquery from the same predicates (fixedInnerReadPredicates, exported bydriver-sql). It also compiles the subquery inside a resolvedReadableIdssemi-join scope.SqlDriver.supports.fixedReadLeaves = ['SharedRecordIds']lands in the same commit as the compile.TursoDriverinherits it on both faces; remote mode declares it only because the remote compiler now compiles it.$incomparand is refused before any statement runs. It uses ADR-0139 D3's envelope,INTERNAL_ERROR/ 500, and is logged aterroronce per driver. The message names the position and the leaf, never the recipient.spec). It gains noten5(a doc whose only grant is stamped in another organization) and a nested case read under a tenant. Together they witness, in the nested position, that the inner read carries no tenant scope.check:tenant-chokepointreads the builder written here and flagged it unscoped, as predicted (A6). It now holds oneEXEMPTentry forfixedReadLeafSubquery, which cites ① ruled A.Compile surfaces, one conclusion each
driver-sqlapplyFilterCondition: changed here. The$inarm compiles the leaf, andapplyFiltersrefuses a misplaced one.SqliteWasmDriverand Turso local inherit it. SqliteWasmDriver was measured ad hoc: it declares["SharedRecordIds"]and passes 14 of 14 shared cases.RemoteTransport.buildWhereSQL: changed here. It addsfixedInnerReadSQLand the$inarm.TursoDriver.toRemoteWhererefuses a misplaced leaf.compileScopedFilterToSql: out of scope. It belongs to step 5 (ADR-0155 step 5: the rest of the census — storage refusal for the share-grant leaf, the analytics compilers, the explainer record pass #35874).lowerAnalyticsWhere: out of scope. It belongs to step 5.formulamatchesFilterCondition: already compliant, by step 2's seam. The seam isobjectqlfixed-read-leaf-position.ts#collectFixedReadLeaves, reached throughfixed-read-leaf-seam.ts. It refuses a leaf inhavingand inaggregations[i].filterwithINTERNAL_ERROR/ 500 before any in-memory evaluation. The engine's only caller of the matcher ishaving-filter.ts. This PR does not change it.applyHaving/matchesHaving: already compliant, by step 2's seam. The seam refuses a leaf inhaving("the leaf is legal only in the where of a read, never in having"). This PR does not change it.driver-memory: out of scope. It belongs to step 4 (ADR-0155 step 4 (driver-memory): evaluate the share-grant leaf in process, on reads and the predicate update path #35873).driver-mongodbtranslateFieldOperators: out of scope. It belongs to step 5.Read these first (risk order)
packages/drivers/driver-sql/src/sql-driver-internal-helpers.ts,fixedReadLeafSubquery. This is the unwalled builder (① A) and the Oracle branch. The risk is a tenant wall missing where it is owed, or present where it is ruled away.packages/drivers/driver-sql/src/fixed-read-leaf-compile.ts,findMisplacedFixedReadLeaf. This is the role-aware walk that separates a legal$incomparand from every refused position. The risk is a legal position refused, or a misplaced leaf compiled as a value.packages/drivers/driver-turso/src/remote-transport.ts,fixedInnerReadSQLand the$inarm. This is the second, independent compiler. The risk is drift from thedriver-sqlshape.Tests
Two new suites cover the compile:
sql-driver-fixed-read-leaf-conformance.test.ts(driver-sql, every live dialect cell) andturso-fixed-read-leaf-conformance.test.ts(both Turso faces). Each covers:findandcount, plusaggregate;updateManywith the same AST, each answering the case's rows;organization_idpredicate, outside the subquery;find,countandupdateMany, each assertingcode+statuswith no row written;Temporal Conformancejob, which runs on push to main and not on pull requestsTemporal Conformanceafter merge. No MySQL server in this containerexecuteThe package runs below are at
9a099c3d2. The head is now71324295d, which changes only the changeset text (git diff --stat 9a099c3d2 71324295d: 1 file, 1 insertion, 1 deletion), so they stand for the head's code. The ablations ran at71324295d. Every run went through the shared verify lock.Package suites and typechecks at 9a099c3
The first
driver-sqlrun used a UTC PostgreSQL server. Six live-PG timezone files failed on their own precondition ("the live postgres server runs at UTC … this cell proves nothing"). The run above uses the three-way zone skew those files ask for, and every file passes.specwas narrowed tosrc/data, because the case-set's only consumers inspeclive there. The fullspecsuite andtest:reporun in CI.Ablation. Five mutations, each made after the code was committed and each through
scripts/ablation-replace.mjs. That tool proves the anchor left the file and the blob changed. Each restore is proven by the file's blob equalling HEAD's and by an emptygit diff HEAD. Each count was predicted before its run. The SQL suite ran with live SQLite and live PG, plus the five compile-shape pins; the MySQL cell is the skip. Both suites were green at the head before the first mutation: SQL78 passed | 1 skipped (79), Turso54 passed (54). Every observed count equals its prediction.$inarm'swhereIndeleted, so the leaf is dropped50 failed, 28 passed, 1 skipped (79)1 = 152 failed, 26 passed, 1 skipped (79)10 failed, 68 passed, 1 skipped (79)fixedInnerReadSQL4 failed, 50 passed (54)18 failed, 60 passed, 1 skipped (79)driver-sql13 failed, 41 passed (54)notEmptyline offixedReadLeafSubquerydeleted (round 0, at9a099c3d2)12 failed, 66 passed, 1 skipped (79)What went red in each ablation, and the restore proofs
aggregate, both write cases, the tenant write and freshness;$andwith idd2, and the read scope ofu3.$ornarrows the result, so the nested case answers[n2].8dbf613e04b1.u3: 24 on SQLite, 23 on PG and 5 compile-shape.[n1, n2, n3, n5]: n3 too, as the case's note predicts. I had also predicted n4, and was wrong on that one row: n4 names no record.8dbf613e04b1.organization_id = tenantIdontofixedReadLeafSubquery's builder at the$inarm.optionsis threaded into nested scopes, so it reaches the nested position too.org_b), the nested-under-tenant case,aggregateunderorg_a, the tenant write and the statement pin.8dbf613e04b1.remote-transport.ts, the first held.scopedWhereSQLhands its scope tofixedInnerReadSQLfor the length of one compile, and that call appends the scope inside the subquery.bfafe299e93e.if ((globalThis as any).ABLATION_C_SKIP_WALK !== 0) return null;at the head offindMisplacedFixedReadLeaf.INTERNAL_ERROR/ 500 was expected.ea97d9f49ecb, taken after the Turso leg below.driver-sqlthroughdist/, so the mutation was built.ablation-dist-preflightfound the marker indist/index.jsanddist/index.mjs.RemoteTransportpin.ablation-dist-preflight --absentreported the marker absent from all 6 built files and the tree clean. The Turso suite then ran54 passed (54)again.ea97d9f49ecb.9a099c3d2.bd8d9c663c2c.Acceptance notes
K1,k2andk3against idsk1,k2,k3. Both answer onlyk3: deterministic and unpadded, as the list is.42and07answer 42 and 7), through column affinity.[7, 42]and both uuids. The leaf fails withDATABASE_ERROR42883 ("operator does not exist: integer = character varying", and the uuid twin).plugin-sharingfederated-phantom-anchors.ts), so the case is reachable once step 6 writes the leaf.RAW(16)keys are expected to differ, because the list goes throughHEXTORAW(unmeasured).packages/qa/dogfood/bench/sql-perf/bench.mjs --shares N). Today's statement was read from the bench's own--sql-log:owner_id = ?with no grants, and(owner_id = ?) or (id in (…list…))with grants. The figures below are the median of 15 runs at 100k and 9 runs at 1M, after one warmup, on a shared box, with plans fromEXPLAIN. The page isorder by created_at desc, id desc limit 50. The member owns every 10th account.MULTI-INDEX OR: theowner_idindex plus the subquery probe on(object_name, recipient_type, recipient_id). Across 1,000 and 10,000 accounts and 900 to 109,000 grants in the table, the page goes from 0.164 ms to 0.190 ms at the smallest and 1.825 ms to 1.954 ms at the largest (×0.86 to ×1.34 across the eight readings). The total goes from 0.015–0.051 ms today to 0.047–0.123 ms with the leaf (×1.8 to ×3.1).idx_bench_account_created_at_idbackward with the OR as a filter: ×0.65 to ×1.19, no regression at this owner share. At 10,000 accounts today's page already walks that index.Bitmap Index Scan on idx_bench_account_owner_idinto aSeq Scan on bench_account: ×1.55 to ×2.5 at 1,000 accounts (0.149 ms to 0.346 ms), and ×2.1 to ×6.0 at 10,000 accounts (0.162 ms to 0.972 ms, and 0.394 ms to 1.968 ms).record_id. This is an out-of-scope finding with numbers, for the seat. The index was not edited.(object_name, recipient_type, recipient_id, record_id)makes the inner read index-only on both (PG afterVACUUM ANALYZE).--scale 1000000 --shares 9000the bench member reads 6,000 accounts of the 10,000 expected, and the last shared account answers 404. With the leaf, the same statement counts 10,000.INVALID_FILTER". ADR-0155 and step 2's seam sayINTERNAL_ERROR/ 500, "neverINVALID_FILTER". The refusals here follow the ADR.Temporal Conformanceafter merge.objectql'sengine-fixed-read-leaf-seam.test.ts: it reads only the case-set's.seam, which is byte-unchanged, and it needs a closure not built here. CI's Test Core runs it.Verification
Two minutes, with a PostgreSQL URL or without one:
Expect every test to pass. Without
OS_TEST_POSTGRES_URL, the live postgres and mysql cells report NOT RUN in the live-dialect block. With it, they reportTests 78 passed | 1 skipped (79), where the skip is the MySQL cell.Local gates at 9a099c3: 114 derived families, each exit code captured before any pipe
The list comes from
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackat 9a099c3. It was reconciled with--ran(codes recorded):114 derived, 113 run, 1 NOT-MEASURED, 0 UNRUN.check:tenant-chokepoint("every unscoped one is an insert or one of 1 EXEMPT entr(ies) with its reason"),check:adr-anchors,check:nul-bytes,check:facade-delegation-only("4 file(s) within their line ceiling"),check:driver-conformance,check:test-source-alias,check:error-status-conformanceandcheck:where-matcher.check-plugin-teardown-shape --self-testexited 3, because its positive control is pinned to a commit this shallow checkout lacked. After fetching that one commit, the rerun exited 0.check:dts-closureexited 1, naming 55 built packages without declarations. That was this box's state, not this diff: the CLI closure had been built withOS_SKIP_DTS=1to boot the R9 bench. None of the three touched packages is among the 55. Rebuilt with declarations and rerun: exit 0, "81 built package(s) swept - 260/260 declared declaration file(s) present".check:dual-build-cjs-loadsexited 3 (PREREQUISITE NOT MET: some packages had nodist/). NOT MEASURED locally; CI builds everything and runs it.engine.tsis untouched at 6854 of 6854 lines.sql-driver.tsis at 10067 of its 10071-line ceiling.Local gates at 7132429: the families that read the changeset, the only path round 1 changed
The 14 families the derivation matches through
.changeset/35872-shared-record-ids-sql-compile.mdwere run at71324295d, each exit code captured before any pipe.check:changeset-gate-self-tests,check:closed-ceremony-textandcheck:published-files;check-adr-0087-registration(--base origin/mainand--self-test);check-changeset-no-major --base origin/main;check-empty-changeset(--base origin/mainand--self-test);snapshot-next,check-governed-queue-guard,release-rehearsal-cloneandrelease-pending-publish;check-governed-queue-guard --toolchain-needed.check-governed-queue-guardwith no flag exited 1: "could not read GITHUB_EVENT_PATH". It reads only the workflow event payload.--ranclassifies it, and the toolchain leg, as CI-measured only and outside the derived total.check-issue-citationsandcheck-nul-bytesalso exited 0.--ranon round 1's record alone:114 derived, 12 run, 0 NOT-MEASURED, 102 UNRUN. The 102 read only paths that are byte-identical between the two heads.--ranwith round 0's codes for those 102:114 derived, 113 run, 1 NOT-MEASURED, 0 UNRUN. The NOT-MEASURED one ischeck:dual-build-cjs-loads, as above.