Repository navigation
Description
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz
Filing gate: ② a maintainer fork a ruled record routes to the maintainer (ADR-0155 D-0) · Source: fleet (os-dev report 7046516194 on #35872, open_questions[0]; PR #35893). Carries the O2 non-text-key item of #35872; #35872 keeps every other item (compile, declaration, update path, N4, O3 and D6 readings), delivered by PR #35893.
维护者速读
- 问题:在 PostgreSQL 上,主键是数字或 uuid 的外部表,用新的共享子查询读记录会直接报错;今天按名单读能正常返回被共享的记录。最后一步切换前碰不到用户,切换后这类表上被共享的人会读不到。
- 选项:A 按表的主键类型做比较,结果和今天完全一样,约一个中等 PR;B 用另一种类型转换,个别超长编号会报错而不是查不到,一个小 PR;C 把主键转成文本比较,写法不同的编号会悄悄对不上,还会变慢,一个小 PR;D 这类表继续用今天带五千上限的名单,这里不改,最后一步多一条分支。
- 推荐 A:只有它让这类表上的共享和今天读出完全相同的记录,又不留下带上限的老路。
- 不定会怎样:最后一步(切换共享读取方式)不能在 PostgreSQL 外部表上开启,否则那里的共享读取会报错。
Analysis
Background. ADR-0155 lowers the sharing scope's share-grant arm to an engine-internal semi-join leaf (SharedRecordIds) that SQL drivers compile to id IN (SELECT record_id FROM sys_record_share WHERE …). Step 3 (#35872, PR #35893) compiled it on driver-sql and the Turso remote transport. record_id is a text column; on the tables the platform manages id is also text. On PostgreSQL, a federated (external) object keyed by integer or uuid is sharing-scoped (packages/plugins/plugin-sharing/src/federated-phantom-anchors.ts), and there the compiled comparison fails with DATABASE_ERROR 42883 ("operator does not exist: integer = character varying", and the uuid twin), where today's bound id list answers [7, 42] and both uuids (measured live on PostgreSQL 16 by the dev; PR #35893 Acceptance notes, O2). SQLite answers the same rows through column affinity (measured). MySQL and SQL Server convert implicitly by documentation (unmeasured); Oracle RAW(16) keys are expected to differ (unmeasured).
Governing text. ADR-0155 D-0, verbatim: "An outer key of another type answers the same rows. Where an object's id column is not a string, the subquery answers the rows today's list answers (O2). A refusal there would narrow this invariant on that object, so it is no driver card's to choose: a card that cannot keep the same rows stops, and the case goes to the maintainer under ②." O2: "The driver card pins the comparison, type and collation, on every dialect driver-sql ships, and answers an outer key of another type with the same rows (D-0)." Ruling record 6942854600 on #33787: 「三问都按 ADR 推荐」 (② the recommended column: no capped id list kept anywhere).
Protocol. No change to what a metadata author can write under any option (Metadata-protocol: none).
Premise (re-check). Nothing writes the leaf until ADR-0155 step 6 (#33787): git grep -n 'SharedRecordIds\.' origin/main -- packages/plugins packages/services | grep -v '\.test\.' → 0 hits at eb9f8ed (no producer). The failure is loud (a 500 from the database), never a wrong row set.
Question. What should the PostgreSQL compile answer for an object whose id column is not text?
| Option | What it does | What the customer sees | Effort |
|---|---|---|---|
| A | Type-aware inner read on PG: cast record_id to the outer key's base type, read once per object from the catalog and cached |
Same rows as today's list for integer and uuid keys; a malformed grant id fails the statement as a list literal does today | domain:server · 1 PR, M · no precedent |
| B | jsonb_populate_record-typed inner read on PG external objects |
Same rows for int and uuid (measured), but an over-long grant id errors ("value too long for type character varying(10)") where the list answers no match | 1 PR, S · no precedent |
| C | Cast the outer column to text (id::text IN (…)) |
Grant 07 no longer matches 7, an uppercase uuid grant does not match; the outer pk index is lost (full scan) |
1 PR, S · no precedent |
| D | Leave the compile; step 6's producer keeps today's capped id list for non-text keys on non-SQLite SQL dialects | Those tables keep the 5,000 cap #33787 retires; behaviour splits by key type | 0 here, cost moves to step 6 |
Business meaning: A is "compare like with like"; B is a second conversion with its own edge failures; C changes which records a person sees on spelling differences; D keeps the old silent cap for one class of table.
os-decision-facets
- ① Long-term: A keeps one statement shape and every grant for every key type (shrinks special cases); C and D each add a permanent special case (a lossy cast, or a second capped path).
- ② Business pull: federated PG tables keyed by integer/uuid are sharing-scoped today; reachable the moment step 6 writes the leaf; no customer hits it before.
- ③ AI-safety: A and the current loud 500 never return wrong rows; C changes rows silently (worst); B adds a quieter divergence.
- ④ Startup focus: D keeps a capped second path alive; A adds driver code for a narrow path but retires the list everywhere.
Prior rulings read: "ADR-0155 D-0 O2", "6942854600" → ADR-0155 D-0, O2, ② ruled the recommended column; thread: none
Recommendation: A (the dev's, report 7046516194; the card thread concurs). Two years out the platform answers sharing on any SQL table with one in-database semi-join whatever the key type, as mainstream platforms type their joins; A is the only option that meets D-0 as written without keeping the capped list (D) or changing rows silently (B, C). Self-check: only ① picks A; ②③④ flip it: no. Confidence gaps: MySQL/SQL Server implicit conversion and Oracle RAW keys unmeasured; A's catalog read needs a pin per type.
After the ruling. A: a domain:server card in packages/drivers/driver-sql (catalog read + cache, a pin per type on live PG), landing before step 6. D: step 6's card carries the producer branch. B/C: a small driver-sql PR.
Related. #33787 (step 6, Blocked-by this card), #35872 / PR #35893 (step 3), #35873 (step 4), #35874 (step 5), ADR-0155.
Activity
objectstack-fleet commentedon Nov 20, 2026
triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH
Triage: lands in
domain:server·needs-user-decision(kept); rationale: area:data · Task · decision card for ADR-0155 O2: on PostgreSQL, the share-grant subquery errors on an object whose id is not text (integer, uuid); options A (compare by key type, same result as today, a medium PR), B (another cast, a small PR, rare over-long ids refuse), C (cast to text); no user sees it until the switch → p2 as filed · size S–M by the option. Waits on the maintainer's letter.objectstack-fleet commentedon Nov 20, 2026
repo:objectstack#7 · os-tesla · session_01L9qibvvVzM5KhCWkT5f45c
Seat note · 2026-11-20T19:11Z · scope carried from step 3's contract review
Step 3 (#35872) landed as PR #35893 (643fe3b). Its CONTRACT_REVIEW_TIER review (7047602668) leaves two readings for this fork, carried here so whichever option is ruled covers them before step 6 (#33787) is cut:
RAW(16)keys are unmeasured. The card that implements the ruled option measures each dialectdriver-sqlships, or names the ones it leaves.id = ANY(ARRAY(SELECT …))form, outside D2's stated SQL, may keep PostgreSQL's owner index for the no-grant caller's total (the D6 reading). Unmeasured; for the maintainer to weigh at step 6, not a fifth option here.objectstack-fleet commentedon Nov 20, 2026
repo:objectstack#7 · os-tesla · session_01L9qibvvVzM5KhCWkT5f45c
Ruled: A — type-aware inner read on PostgreSQL · 2026-11-20T22:01Z
The maintainer (Tesla) picked option A on seat 7's decision card at 2026-11-20T22:01Z. The card's question was 「PG 上主键是数字或 uuid 的外部表,共享子查询怎么比较?(#35906)」 and the option chosen was 「A 按主键类型比较」.
So
driver-sqlcastsrecord_idto the outer key's base type on PostgreSQL. The type is read once per object from the catalog and cached. The result is the same rows as today's id list for integer and uuid keys, with a pin per type on live PG. The card also measures, or names as left, the other dialectsdriver-sqlships (MySQL, SQL Server, OracleRAW(16)), per the seat note above.This card becomes the work card. It is part of the ADR-0155 chain, which the maintainer counted as work in hand (2026-11-20T18:06Z). It lands before step 6 (#33787), which keeps
Blocked-by: #35906until then.needs-user-decisioncomes off; triage does the first touch for domain and queue.objectstack-fleet commentedon Nov 20, 2026
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz
Claim: PM loop round 1
Session:
session_01L9qibyXo4gSy8DJPNz4ANzAccount:
os-teslaBranch:
claude/project-thread-thptm0(platform exception: this card thread can push only its assigned branch. PR #35945 (#35874) holds it now, so the build runs locally on a worktree branch and is pushed to it after #35945 merges, restarted from main)Worktree:
objectstack-issue-35906Domain:
domain:serverSeat:
repo:objectstack#7Area:
card #35906File surface:
packages/drivers/driver-sql/src/**: the PostgreSQL arm of the fixed-read leaf's inner read (sql-driver-internal-helpers.ts#fixedReadLeafSubquery,fixed-read-leaf-compile.ts), a catalog read of the outer key's base type with its per-object cache, in a sibling module, sincesql-driver.tsis at 10067 of its 10071-line ceiling; thefixedReadLeavescomment (step 3 L2 nit N3, "every dialect"); tests beside each (live PG pins per key type);scripts/adr-anchors/(new anchor files only); one new changeset.changeset/35906-*.md. Stop on breach and explain in the report. ⛔ No producer writes the leaf (step 6). Nodriver-tursochange unless measured necessary (SQLite answers by affinity). Nodocs/adr/**,skills/**orpackages/objectql/src/engine.tsedit.Container & model:
M,mode:subagent,model: default,effort: high(FRAME: "M/L high")Clause-②: yes
Clause-② basis: the compiled share-grant subquery changes its SQL on PostgreSQL for non-text keys, keeping D-0's same rows (ruled A).
Metadata-protocol: none
Responsibility: n/a — not a defect card (a ruled fork of ADR-0155 O2)
Thread-read: 7051669729
Premise: holds (origin/main 170ca48: step 3's
fixedReadLeafSubquerycomparesrecord_id(text) to the outeridwith no cast, so PostgreSQL 16 answers 42883 for an integer or uuid key, as measured on PR #35893; no producer writes the leaf:git grep -n 'SharedRecordIds\.' origin/main -- packages/plugins/plugin-sharing | grep -v '\.test\.'→ 0)Serial constraints cleared: overlap-check (probe commit over
sql-driver.ts,sql-driver-internal-helpers.ts,sql-driver-filter-helpers.ts,fixed-read-leaf-compile.ts, origin/main 170ca48): merges cleanly, 0 open PR heads share them; reruns before each push. Push waits for PR #35945 (same branch, disjoint packages).Pre-claim lane:
repo:objectstackseat 7, card threadcard #35906(the ADR-0155 L program's thread, which landed step 3);domain:server(drivers/*); noskills/**,docs/adr/**or workflow pathPre-claim deps: #35872 (step 3) closed, merged as 643fe3b; ruling 7051669729 (A) recorded; no
Blocked-by:line on the cardScope-review: exempt — a ruled route (maintainer ruling 7051669729, option A)
Prior rulings read: ruling 7051669729 (「A 按主键类型比较」: cast
record_idto the outer key's base type on PostgreSQL, type read once per object from the catalog and cached, pin per type on live PG; measure or name the other dialects); seat note 7048341758 (MySQL / SQL Server / OracleRAW(16)unmeasured, owed here;id = ANY(ARRAY(SELECT …))is not a fifth option, step 6's to weigh); ADR-0155 D-0, O2, D2 (the SQL shape: "⛔ NoEXISTS, no correlated form, no join"), ruling record 6942854600; step 3's close-out 7048322381 and L2 7047602668 (N3).check-prior-rulings.mjs --card 35906: ADR-0139 D4 among the named; thread: none beyond the above.objectstack-fleet commentedon Nov 21, 2026
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz
os-dev-report · #35906 · PR #35967 (draft) · head 0f3e1d4 (code f00b631)
The dev built locally while PR #35945 held the branch; the card thread replayed both commits onto main 523ada4 (patch-ids identical) and opened #35967. Status: done. Condensed report:
packages/drivers/driver-sql/src/fixed-read-leaf-key-type.ts: pg_catalog read of the outer key's base type (pg_attribute + pg_type, domains walked to base, no typmod), cache = WeakMap keyed by knex client → physical [schema, table] → column → cast. Primed at every where-compiling door beside the existingprimeMssqlGuidColumnscall (findRows, count, updateMany, deleteMany, aggregate + joined parents, distinct, analyzeQuery, window functions: 8 sites in 6 facet files). Compile site:sql-driver-internal-helpers.tsfixedReadLeafSubquery projectsCAST(NULLIF(record_id, '') AS <type>)viacastFixedReadLeafColumn(knex, column, cast)only on PG when the base type is not text/varchar; other dialects read nothing and keep step 3's SQL. The$inarm insql-driver-filter-helpers.tspassestable(threaded through $or via tableHint) andfield. sql-driver.ts stays 10067/10071 (stub signature + N3 comment changed in place).sql-driver-oracle-dialect.ts#oracleUuidRawBinding, columns primed inoracleRawUuidFieldsByObjectat every Oracle door), refuses non-uuid with INVALID_FILTER/400; subquery's implicit VARCHAR2→RAW of a dashed uuid expected ORA-01465. Dev's suggested shape: HEXTORAW(REPLACE(record_id,'-','')) when the outer column is a known RAW(16) uuid. NUMBER keys convert like the list's binds.driver-sql/src/**(the MSSQL-GUID precedent); the character(n) silent-miss fix is in scope (same mechanism), declared under Clause-②; local suite ran live SQLite + PG only; check:dual-build-cjs-loads and check:lean-entry-closure NOT MEASURED locally (CI's).objectstack-fleet commentedon Nov 21, 2026
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz
os-dev-report · #35906 · PR #35967 (draft) · amendment, fix round on L1 REWORK and L2 F1 · head c7cc4e2
New head
c7cc4e28ca, fast-forward from0f3e1d467ein three commits:707ffb5cc2(R1, R2, N1 to N3),7f4974aac8(F1),c7cc4e28ca(the CI erasure-ratchet fix: the five{ transaction } as anybags in the new pins are typedDriverOptions, test surface back to 236).R1, done. Each door runs as the first statement of a fresh
SqlDriveron thecharacter(4)key. Each pin asserts the list's rows or count, plus thebpcharcast in every statement that readssys_record_share. Every ablation below removed one door's prime throughablation-replace.mjsafter the commit (at707ffb5cc2), and each restore was blob-equal to HEAD.k3left + cast[k1, k2]+ cast{1: 2, 0: 1}over acharacter(4)FK + cast[k1, k2]+ castR2, done. New
PG_KEY_CASESrows:smallint: grants07,42, castint2.numeric(10,2): grants7,07,42.0, expected[42.00, 7.00], castnumericwith no typmod.The changeset sentence now matches the pins: eight key types.
Nits.
aggregateprimes$and: [where, ...measureFilters], the way the SQL Server prime does.RAW(16)is expected to fail (ORA-01465, by reading) and is tracked on driver-sql: the share-grant subquery on Oracle for a RAW(16) uuid key (ADR-0155 O2, ruling A applied to Oracle) #35952.F1, preferred route, taken. No reading is now distinct from "read: a text key".
INTERNAL_ERROR/ 500, logged once per knex client. It is never compiled uncast.Evidence:
find,countandupdateManywith{ transaction }each answerINTERNAL_ERROR/ 500. Zero statements read the grants, nothing was written, and the error was logged once. The next statement re-reads the catalog and answers the list's rows.character(4)table created in an uncommitted transaction. The list in that transaction answers[k1]; the leaf is refused 500.7f4974aac8): 5 failed / 130 passed / 1 skipped, as predicted: 2 unit pins, the compiled-statement refusal, (a) and (b). Unrefused, (a) answered[k2]against the list's[k1, k2]and (b) answered[]against[k1]. That is the silent miss F1 names. The restore was blob-equal.applyFilterssite primes. No other package compiles the leaf through driver-sql on PG; service-analytics has its own compiler. The full driver-sql suite on live PG at7f4974aac8is 277 files passed / 4 skipped, 5767 tests passed / 133 skipped, with TZ=America/New_York.The fallback route was not needed.
Gates at c7cc4e2.
check:query-options-erasure: exit 0 (236, at the ceiling).--ran: 80 derived, 80 run, 0 NOT-MEASURED.check:dts-closureandcheck:dual-build-cjs-loadsfirst read 1. The cause was anorganizationsdist rebuilt mid-run by an overlapping earlier gate run of mine. After rebuilding that package, both exit 0.9ed18a50e0.The PR body was brought to this head through the relay
issue_patch(stored identical). Its false sentences were the six key types, uncast on a failed read, the test counts and the local-gates head.api_writes this round: 2 (
issue_patchon #35967, this comment). mcp_calls: 0.objectstack-fleet commentedon Nov 21, 2026
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz
os-dev-report · #35906 · PR #35967 (draft) · amendment, S1 from delta L2 · head 99e085e
New head
99e085ec96, fast-forward fromc7cc4e28ca, one commit.S1, code route, done. A door in the caller's transaction now reads the catalog on that transaction's own connection. The read runs inside a savepoint:
trx.transaction(sp => sp.raw(...)), with the transaction taken from the door's options, passed to the prime at all 9 sites and to the compile-site lookup.Live PG pins, turned around:
find,countandupdateManyanswer the list's rows ([k1, k2], 2, 2). All 3 grant-reading statements carry thebpcharcast, and nothing is logged.character(4)table created in the uncommitted transaction. The list returns[k1], the leaf returns[k1], count is 1, and both statements carry the cast.select 1/0, a real PostgreSQL error on the caller's connection.findandcountare refused withINTERNAL_ERROR/ 500, logged once, and the read was attempted twice. The caller's transaction then still runsselect 1and a list read. With the seam removed, the next leaf statement answers the list's rows.Ablation. I moved the read back to the pool, through
ablation-replace.mjsafter the commit: 4 failed / 133 passed / 1 skipped (138), as predicted. Live (a) and (b) are refused with 500 (no reading), (c) answers rows instead of refusing, and the unit pin fails. The restore was blob-equal to HEAD.Text keys. The changeset's "Unchanged" bullet now says exactly what changes: the compiled statement is step 3's, with no cast. The first leaf statement per table (once per driver, or once per transaction) is preceded by the catalog read, and if that read fails or finds no relation, the statement is refused with 500 instead of run. The PR's step-6 line is narrowed: the saturated pool and the in-transaction table are no longer preconditions. What remains is a failing catalog read refusing where step 3 ran uncast.
Gates at 99e085e.
check:query-options-erasure(236, at the ceiling) all exit 0.--ran: 80 derived, 80 run, 0 NOT-MEASURED, all exit 0 on the first pass.9ed18a50e0.The PR body was updated through the relay
issue_patch(stored identical).api_writes this round: 2 (
issue_patchon #35967, this comment). mcp_calls: 0.objectstack-fleet commentedon Nov 21, 2026
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz
os-dev-report · #35906 · PR #35967 (draft) · amendment, delta-2 L1 R1 and L2 S2 · head 1e61bf8
New head
1e61bf84ed, fast-forward from99e085ec96, one commit.R1 / S2, done. I took the second route: the lookup reaches the parent transaction's reading from a derived savepoint.
transactionReadingwalks knex'sparentTransactionchain. The prime uses it to skip a read and the compile-site lookup uses it to find one.issue:attemptWithoutPoisoningopens a new savepoint on every presumed write. Priming insideissuewould pay one more savepoint and one more catalog read on every such write, because the reading would be cached under a transaction object that is thrown away.The pin. Pin (d) runs on live PG, on a fresh driver, as the first statement. The object is managed (
registerObjectMetadataover a table the driver did not create), so itsupdated_atis presumed. There is one object with a text key and one with acharacter(4)key. A predicateupdateManywith the write-form leaf, inside a caller transaction, answers the list's rows (2), touches them, settles the presumption, and thecharacter(4)statement carries the cast.99e085ec96: 2 failed / 126 passed / 1 skipped. Both areINTERNAL_ERROR/ 500 "holds no reading", for the text key and thecharacter(4)key.at = undefined): 3 failed / 137 passed / 1 skipped (141), as predicted. The red pins are the unit pin and (d) for both key types. The restore was blob-equal to HEAD.Sweep.
grep -n 'applyFilters('overdriver-sql/src(non-test) finds 12 call sites.sql-driver-bulk-operations.ts:326, which isupdateMany'sissueand is now covered.sql-driver-internal-helpers.ts:145, the composed scope, uses the door's options.sql-driver-latest-per.ts:133is reached only fromfindRows, with its options.I also grepped for derived transaction options:
{ ...options, transaction: … },.transaction(asyncandattemptWithoutPoisoning(. That findsbulkUpdate(:268, which goes toupdateby id),upsert(sequence-semantics.ts:842and:853) and the autonumber sequence (autonumber.ts:193). None of them callsapplyFilters. So I found no other door, which agrees with L1.L2 additions.
updated_atwrite path. The bullet also states the cost: one savepoint and one catalog read per transaction per table.Gates at 1e61bf8.
check:query-options-erasureexits 0 (236, at the ceiling).--ran: 80 derived, 80 run, 0 NOT-MEASURED.9ed18a50e0.The PR body was updated through the relay
issue_patch(stored identical).api_writes this round: 2 (
issue_patchon #35967, this comment). mcp_calls: 0.objectstack-fleet commentedon Nov 21, 2026
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz
Close-out · 2026-11-21T04:59Z · ADR-0155 O2 (PostgreSQL share-grant key type) landed
Merged as
850bcec018via PR #35967 (head1e61bf84ed, 2026-11-21 04:58 UTC). Reviews: L1 REWORK 7055124444, delta ACCEPT 7056216450, delta-2 REWORK 7056796280, delta-3 ACCEPT 7057216047. L2TIER_DEFAULT(declaration face only): PASS 7055157866 (F1), delta PASS 7056236983 (S1), delta-2 PASS 7056813710 (S2), delta-3 PASS 7057221897 (all closed). Landing 7057235388. Dev amendments on this card: 7056181587, 7056768200, 7057194515.What landed (
@objectstack/driver-sql, patch):CAST(NULLIF(record_id,'') AS <base type>)when the outer key is not text. The type is read frompg_catalog(domains walked to base, no typmod), cached per knex client outside a transaction, and per transaction inside one. Text keys compile exactly as step 3 did.updated_atretry ofupdateMany) reaches the parent's reading, one way only.INTERNAL_ERROR/500, logged once per knex client; a failed read is not cached. It is never compiled uncast.character(n)was a silent miss under step 3 and now answers the list's rows.Carried:
RAW(16)keys: driver-sql: the share-grant subquery on Oracle for a RAW(16) uuid key (ADR-0155 O2, ruling A applied to Oracle) #35952 (d7-D). plugin-sharing: a member with more than 5000 share grants on one object silently loses access to the grants past 5000 (list misses rows, GET answers 404) #33787 stays Blocked-by it.Temporal Conformance (live PG + MySQL)) for this cell.objectstack-fleet commentedon Nov 21, 2026
repo:objectstack#7 · os-tesla · session_01L9qibyXo4gSy8DJPNz4ANz
Closed by PR #35967;
pm:dispatchedremoved.fix(plugin-sharing)!: every share grant counts; the sharing scopes ca…