Skip to content

fix(driver-sql): split a long $in/$nin list on Oracle, refuse one past SQL Server's parameter ceiling - #39782

Draft
objectstack-fleet[bot] wants to merge 5 commits into
mainfrom
claude/issue-39312-wip
Draft

objectstack-fleet[bot] wants to merge 5 commits into
mainfrom
claude/issue-39312-wip

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread

Fixes #39312

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用 Oracle 或 SQL Server 的部署:一次按超过 1,000 个编号查询的读取,在 Oracle 上从报错变为正常返回;在 SQL Server 上超过 2,100 个的单个列表从数据库报错变为一条写明上限的明确拒绝。其它数据库用户无感。
  • 为什么做:SQL 驱动把长编号列表原样塞进一个 IN 条件,评论表情权限、共享规则等未自行分批的调用方在这两种数据库上会失败。
  • 出错会怎样:只影响 Oracle 与 SQL Server 上的长列表查询;其它数据库生成的 SQL 与之前逐字节相同,可整体撤回。
  • 要你做什么:无。

What changes

packages/drivers/driver-sql, the $in / $nin arms of FilterHelpersFacet now go through a new sibling module, sql-driver-in-list-ceiling.ts (the filter-helpers file is over 1,000 lines, so the new concern lives beside it and the arms only call it):

  • Oracle (ORA-01795, at most 1,000 expressions per IN list): a list longer than 1,000 is emitted as consecutive lists of at most 1,000. $in becomes their disjunction, (col IN (...) OR col IN (...)); $nin becomes their conjunction, (col NOT IN (...) AND col NOT IN (...)), inside the existing NULL-safe arm. Under three-valued logic each is the same set test as the one long list, member for member.
  • SQL Server (at most 2,100 parameters per request): splitting cannot help, since every member is still a parameter of the one statement. A $in / $nin list of more than 2,100 values is refused before any statement is built, as INVALID_FILTER / 400, with a message that names the 2,100-parameter ceiling and the remedy (batch the read or narrow the filter). The field name stays withheld from the client message, the same as the driver's other filter refusals.
  • Every other dialect, and every list within the ceilings, compiles to byte-identical SQL.

Two companion edits, both mechanical consequences of the new module:

  • sql-driver-compile-refusal-seam.test.ts gets a roster row for assertInListWithinRequestCeiling. The roster pins every builder that goes through withheldFilterError, and the new row drives the refusal under the policy, author, unmarked and merged marks.
  • scripts/check-tenant-chokepoint.mjs adds the new sql-driver-in-list-ceiling.ts to DECLARED_WATCH_HINTS, as that gate's self-test requires of every newly scanned sql-driver-*.ts module.

What this does not cover: a SQL Server statement whose lists each fit but whose parameters together pass 2,100 still reaches the server and comes back as the server's error. The driver sees one list at a time, not the whole statement.

Tests

packages/drivers/driver-sql/src/sql-driver-39312-in-list-dialect-ceiling.test.ts:

  • Oracle: $in / $nin of 2,500 compile to three lists of 1,000 / 1,000 / 500, joined with OR / AND respectively, binding every id once and in order. A split $in under $or stays one disjunct. A list of exactly 1,000 stays one list.
  • SQL Server: $in and $nin of 2,101 are refused with code INVALID_FILTER, status 400, and a first sentence naming the ceiling. A list of 2,100 compiles as one list.
  • Byte-identity: SQLite, PostgreSQL, MySQL (2,500), SQL Server (2,100) and Oracle (1,000) compile $in / $nin to exactly the SQL a plain whereIn / NULL-safe whereNotIn gives.
  • Answer equality, measured on a real SQLite database: the split $in, and the split NULL-safe $nin, return the same rows as the one long list over 3,000 rows (every seventh NULL) and 2,400 members (some absent).
  • Thread-gate parameter count (the card's G): see Acceptance notes.
Readings at 62243fe
  • pnpm --filter @objectstack/driver-sql test: 275 files passed, 14 skipped; 4621 tests passed, 268 skipped. pnpm --filter @objectstack/driver-sql typecheck (tsc --noEmit, which includes src/**/*.test.ts): exit 0, no errors. Verify-lock verdict: command-exit 0.
  • Ablation: with sql-driver-filter-helpers.ts restored to origin/main on disk, the pin file goes from 15 passing to 5 failing and 10 passing. The 5 failures are the three Oracle split cases and the two SQL Server refusals. The tests that still pass without the fix are the within-ceiling cases, the byte-identity cases, the thread-gate count and the SQLite answer-equality cases, which call the emitters directly. The file was then restored from HEAD, and the tree was clean afterwards.
  • Gates: the derived local subset was run. Families that were not measured locally are listed in the dev report and left to CI.

Acceptance notes

  • The card's G, the sys_comment thread gate's parameter count on SQL Server. The gate ORs one branch per registered parent object: object_name = P plus record_id IN (ReadableIds subquery for P under the caller's scope). The readable-id set compiles as a subquery, not a literal list, so a branch binds 1 + s_P parameters, where s_P is the bindings of the caller's own row scope on P. The pin test measures this through the SQL Server dialect's own knex client: 120 parents with a one-binding owner scope bind exactly 240 parameters. So G = sum over parents of (1 + s_P). With one-binding scopes, G passes 2,100 only beyond 1,050 parent objects. This was measured offline through the dialect compiler. It was not run against a live SQL Server, and no live app's parent-object count was taken.
  • Neither ceiling was measured against a live Oracle or SQL Server. Both are the vendors' documented limits, read from each dialect's own toSQL() output.
  • Callers that chunk for themselves (sharing 200, record-scoped delete 200, closed-state lock 500, grouped summary 500) are unchanged. Their chunks are all within both ceilings.

Verification

Read first (by risk):

  1. packages/drivers/driver-sql/src/sql-driver-in-list-ceiling.ts: emitNotInValueTest. The $nin split must be an AND of NOT INs inside the NULL-safe group, never an OR.
  2. packages/drivers/driver-sql/src/sql-driver-filter-helpers.ts, the $in / $nin arms: the refusal runs before either emit.
  3. The test file's answer-equality block.

Two-minute check: pnpm --filter @objectstack/driver-sql exec vitest run --maxWorkers=2 src/sql-driver-39312-in-list-dialect-ceiling.test.ts. Expect all 15 tests to pass.


Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_016WV4cwiNRyb9B38wT2fjYj

…t SQL Server's parameter ceiling

Claude-Session: https://claude.ai/code/session_01Utp6CaJjkQx5fPE4Fbmoeq
Co-authored-by: Claude <noreply@anthropic.com>
…e compile seam

The new $in/$nin refusal goes through withheldFilterError, so the
compile-refusal roster gets its row, and the tenant-chokepoint gate
declares the new sql-driver module it now scans.

Claude-Session: https://claude.ai/code/session_016WV4cwiNRyb9B38wT2fjYj
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

14 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • the SDK route bridge reached 71 of 255 client-bound route-ledger rows — the other 184 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 184: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 60 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 15 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 8fdb82ab1783795932a13c3d19e2a25c0db2f59e → packageMentionDocs.

Which tree this was computed on

This run read content/docs from e50837ccf9d9784a4342eceae4252f63ec2f5f90 — the merge of head 62243fe9c9319e81e212dbbfbe8f3ceeabdb6600 into base 8fdb82ab1783795932a13c3d19e2a25c0db2f59e, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin e50837ccf9d9784a4342eceae4252f63ec2f5f90 && git checkout e50837ccf9d9784a4342eceae4252f63ec2f5f90
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 8fdb82ab1783795932a13c3d19e2a25c0db2f59e 62243fe9c9319e81e212dbbfbe8f3ceeabdb6600 && git checkout -B drift-repro 8fdb82ab1783795932a13c3d19e2a25c0db2f59e && git merge --no-ff 62243fe9c9319e81e212dbbfbe8f3ceeabdb6600

node scripts/docs-audit/affected-docs.mjs --json 8fdb82ab1783795932a13c3d19e2a25c0db2f59e

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-elon-musk · os-elon-musk · session_016WV4cwiNRyb9B38wT2fjYj

Final green head: 2026-12-05T03:02Z · 62243fe9c9319e81e212dbbfbe8f3ceeabdb6600 · check-runs 39 success, 18 skipped, 0 failed. Fixes #39312 · Clause-②: no · Metadata-protocol: none. os-dev report 7430375597. Surface widened by claim amendment 7430399399: the new sql-driver-in-list-ceiling.ts, one seam-roster row, and a DECLARED_WATCH_HINTS entry in scripts/check-tenant-chokepoint.mjs, which is a gate change. Owes an L1. Zone em-bill.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-elon-musk · os-elon-musk · session_016WV4czzaKz49WLAvKtdyiY

席位核对

L1 verdict (L1-b): ACCEPT at head 62243fe9c9 (Fixes #39312, p3; not governed). Read at 2026-12-05T03:04Z.

Face: l1-face --pr 39782: 13 ok, 1 flag (all-checks). The flag is only the standing Dogfood matrix-name skip. 39 success · 0 failed · 0 pending. mergeable_state clean.

Against the card:

  • Oracle $in. A list over 1,000 compiles to (col IN (≤1000) OR col IN (…) …), wrapped in one where/orWhere group, so under $or it stays one disjunct. The test pins this: listSizes gives [1000, 1000, 500], and the $or case is pinned too.
  • Oracle $nin. It is the conjunction the seat asked for, inside the NULL-safe arm. emitNotInValueTest adds orWhere(inner ⇒ whereNotIn × n) into applyNullSafeNegative's group, giving (col IS NULL OR (col NOT IN (…) AND col NOT IN (…))). That is the same set test as the one long list under three-valued logic, and the SQLite answer-equality pin measures it over 3,000 rows with nulls.
  • SQL Server. A list over 2,100 is refused before any statement is built, through withheldFilterError (INVALID_FILTER / 400, field withheld). The message names the ceiling ("SQL Server accepts at most 2,100 parameters in one request"). The compile-refusal seam gains the door, and SQL Server is never split.
  • Other dialects, and every list within the ceilings. The pin compares them byte-for-byte against plain knex, so they are unchanged.
  • Ablation. With the fix removed, 5 of 15 fail: the three Oracle splits and the two SQL Server refusals. The cases that still pass call the emitters directly or lie within the ceilings, as the body says.
  • Card's G. Measured offline through the SQL Server dialect at 1 + s_P per parent: the readable ids compile as a subquery, not a literal list. Recorded in Acceptance notes. The card asked for it to be "measured and recorded", and offline measurement is what the PR body honestly claims. Accepted.

Fixes is right. The ReadableIds and fixed-read-leaf $in arms (filter-helpers.ts:854-871) compile to subqueries and correctly bypass the ceiling.

Open limit, accepted. A SQL Server statement whose lists each fit but together pass 2,100 still gets the server's own error. The card allows "a parameter ceiling (or a typed refusal)", and the helper sees one list, so the changeset and the module doc both say this.

N1 (nit, outside the card's arms): the driver's own id-keyed whereIn paths, bulkDelete (sql-driver-bulk-operations.ts:393) and the CRUD id reads (sql-driver-crud.ts:193, :501), are still unsplit on Oracle and unguarded on SQL Server. The card scoped the $in / $nin filter arms, so this does not block. The seat can decide whether a follow-up card is worth it.

Changeset: a patch on @objectstack/driver-sql. Every sentence matches the code, including the open-limit sentence. check-tenant-chokepoint.mjs gains the new file as a watch hint, which is the same pattern as its siblings.

Landing: not governed, Clause-②: no, +317/−3, mostly tests. It is ready to land; per em-bill it goes through the seat.


Generated by Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants