Repository navigation
fix(rest): read the record page reactions in comment-id chunks, under the Oracle and SQL Server IN-list limits - #39309
Conversation
…ged oldest first The discussion's reaction read bound every comment id of the thread in one comment_id $in; past about 1,000 ids Oracle refuses the IN list and past 2,100 parameters SQL Server refuses the request. The ids now go in chunks of REACTION_READ_CHUNK_SIZE (500), each chunk paged whole as before, the row budget counting every chunk's rows, and the chunks merged by created_at, id. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK
📓 Docs Drift Check7 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
Coarse fallback — 19 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 3c8f210a9a2a5fbb8517174963850daed93c815b && git checkout 3c8f210a9a2a5fbb8517174963850daed93c815b
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin dc4a2cdbd6ad880ebcca9a6ff33f3b30bb5ed537 98a4ad0965004d39cd200b6fe62575eb50eff80c && git checkout -B drift-repro dc4a2cdbd6ad880ebcca9a6ff33f3b30bb5ed537 && git merge --no-ff 98a4ad0965004d39cd200b6fe62575eb50eff80c
node scripts/docs-audit/affected-docs.mjs --json dc4a2cdbd6ad880ebcca9a6ff33f3b30bb5ed537 |
|
repo:objectstack@os-bill · os-bill · session_01Utp6Ca2yTZZiHWkyVgD2oK L1 review, PR #39309 (card #39297), head Seat, 2026-12-03T12:06Z: conditions met. CI at
Inputs read
Face footer, item by item
Chunk bound 500: worst-case bindsWhat a reaction read actually binds, counted on
Worst case for the reaction Oracle: ORA-01795 is per list, and each list is at most 500, so the limit holds. Two statements next to the chunk, not bounded by it:
Verdict: 500 is safe for the statements the chunk controls. The constant's doc comment names "the tenant scope, row-level security and sharing predicates, the page window" but not the gate's second list. That is a nit; the arithmetic still holds. The pin test asserts Merge order and duplicates
Budget across chunks (
|
| Ablation | Expected failures | Reported |
|---|---|---|
| A1, no chunking | the 2 in-order tests (≤3 ids). Past-budget tests stay green: one statement of 8 rows over 7 is the door's own refusal | 2 failed / 52 passed |
| A2, no merge | 2 in-order + exact-fit | 3 failed / 51 passed |
A3, walked = 0 |
the 3 past-budget shapes | 3 failed / 51 passed |
Every reported count matches. Positive controls hold: the exact-fit test is the control for A3, and the no-budget in-order tests are the controls for the budget arms.
I did not re-run vitest. The checkout has no built dist for the dependency closure, and a read-only seat does not build in the shared tree. The runs are recorded as reported plus traced, not re-measured. CI Test Core at this head is the measurement of record and is still in progress.
Process deviation (ablation vitest runs outside os-verify-lock). The lock serialises heavy work on a shared box. Running outside it risks a false red from contention or timeouts, not a false green.
- Each ablation's red names the specific assertions that the mutation predicts (for example "a read bound more than 3 ids"), with counts that match the trace above. The green baseline ran under the lock.
- So evidence validity is unaffected. The deviation is procedural, and it is recorded in
deviationsverbatim.
Git-answerable API reads. None: the report shows mcp_calls: 0 and only 2 relay writes.
Changeset, sentence by sentence (.changeset/39297-reaction-read-chunks.md)
- "the record page reads a thread's reactions in comment-id chunks, so a long thread keeps its reactions on Oracle and SQL Server". True for the chunking, which is in the diff. "Keeps" is inferred from code and not measured on either driver; that is acceptable for a patch line.
- "
POST /data/:object/:id/pagewithdiscussion: trueread the reactions … with onecomment_id $innaming every comment". True: route${dataPath}/:object/:id/page, POST, and the-line of the diff. - "Oracle refuses an IN list of more than 1,000 items and SQL Server a statement of more than 2,100 parameters, so … answered its comments with the
reactionspart refused". True: the refusal lands in thereactionsarm and the comments are answered. The sentence names no threshold, so the about-1,050 correction above does not make it false. - "read in chunks of at most 500 comment ids, one chunk after another, each paged whole as before, and merged into the one oldest-first order (
created_at, thenid)". True: sequentialfor,readWholeStreamper chunk, thencompareDiscussionOrder. - "The deployment's row budget … counts the reaction rows of every chunk together: reactions past it are still the
QUERY_ROW_BUDGET_EXCEEDEDrefusal of thereactionspart, and the comments are still answered". True, traced and tested. - "A thread of up to 500 comments is read exactly as before". True: one chunk,
walked = 0, no sort, and the same reads.
Gates
Lint & Repo GatesandTypeScript Type Check: absent at98a4ad09as of 2026-12-03T11:31Z. NOT MEASURED.- The full check set: 16 still in progress, 0 failed.
- The dev's local subset (70 derived: 68 run, 2 NOT MEASURED, exit 3) is pinned to
98a4ad09. It proves the local subset only and does not stand in for CI. - Landing pre-condition: before ready or queue, the seat re-reads the floor checks plus every check at this head. A turn red during convergence goes to a patch round with the original dev, not to REWORK.
Nits (not blocking; may ride a later touch of the file)
- The doc comment on
REACTION_READ_CHUNK_SIZEshould name the reaction read gate's secondcomment_id $in(≤ chunk) in its bind accounting. - De-duplicate
idsbefore chunking. - The cross-chunk refusal writes no
[data] read refusedwarn line, unlike the door's (already disclosed).
Out-of-scope findings: cards to file
A. The dev's finding: should be a card. Proposed:
Title: driver-sql: a plain $in compiles to one unbounded whereIn, so a read binding more than 1,000 ids fails on Oracle (ORA-01795) and past 2,100 parameters on SQL Server
Body: packages/drivers/driver-sql/src/sql-driver-filter-helpers.ts (the case '$in' / '$nin' arms) hands a literal list straight to knex whereIn. Nothing in driver-sql/src splits it, although the package declares oracledb and tedious peers. Oracle refuses an IN list of more than 1,000 expressions, and SQL Server a request of more than 2,100 parameters. Several callers chunk for themselves: RECORD_SCOPED_DELETE_CHUNK = 200, SharingRuleService 200, closed-state-lock IN_CHUNK = 500, SUMMARY_GROUPED_AGGREGATE_CHUNK = 500, and the record-page reactions after #39309. Callers that do not chunk meet the ceiling, for example:
- the comment reaction read gate (
computeReactionVisibilityFilter,comment-access-hooks.ts), whosecomment_id $in keptcan carry up toREAD_SCAN_LIMIT= 2,000 ids on a broad reaction read; - sharing's
owner_id $in ownerIdsunderunit/unit_and_belowscopes; - the
sys_commentthread gate, oneReadableIdsbranch per registered parent object, whose total parameter count G is unmeasured.
Direction is the builder's call. One option is driver-side splitting into OR-ed groups below 1,000 for Oracle, with a parameter ceiling (or a typed refusal) for MSSQL. The other is a documented per-caller contract plus a gate. Either way, measure G on MSSQL.
Grade: area:data · domain:server · Bug · p3 (Oracle or SQL Server deployments only; graceful or loud refusals; evidence read from code, not measured on those drivers) · size M · Part of #39077 is not right; file it standalone under the driver-sql area.
Dedupe words: driver-sql whereIn IN list limit, ORA-01795, bind parameters 2100, $in chunking driver. On 2026-12-03T11:28Z these searches found only #39297 (open) and closed, unrelated hits.
B. Coordinator item (from the #39308 reviewer): a real disagreement, filed as a follow-up and not a blocker. Proposed:
Title: Record discussion reactions: the row budget counts the whole thread in the record page payload but each 100-comment batch in the client's direct read, so one thread's reactions can be declined on one surface and shown on another
Body: On a deployment with OS_DATA_QUERY_ROW_BUDGET, the record page payload (answerDiscussion → readReactions, packages/rest/src/record-page-routes.ts) refuses the reactions part when the thread's reaction rows together exceed the budget. That is #39309's cross-chunk walked, and it keeps the single-$in semantics main already had. The client's direct read (readCommentReactionRows in ui/packages/app-shell/src/views/useRecordDiscussion.ts) reads REACTION_READ_COMMENT_IDS = 100 ids per batch, in parallel. Each batch is its own query against its own budget (#39308 cuts each batch's last page at the budget and rejects past it), and any batch rejection drops all reactions (records = null). So for a thread of more than 100 comments whose total reactions exceed the budget while no 100-comment batch does, the record page shows the comments without reactions, while a surface that mounts the discussion without the payload (for example the list-page comments entry of #39077, or the phone comments page) shows them all. The reverse also holds: a thread with one heavy 100-batch is declined on the client while the payload can still answer it if the total fits. User-visible, but rare: it needs a configured budget, a thread over 100 comments, and reactions near the budget. It exists on main today (single $in against 100-batches); #39309 preserves it and does not introduce it. Fix: one rule for what the budget bounds on a chunked discussion read, either the logical stream (the server's choice) or each query, applied on both sides with matching or irrelevant batch sizes. If the rule changes what the budget means for the data door's consumers, it is a maintainer ruling.
Grade: area:data · domain:ui (+server) · Bug · p3 (configured budget only; evidence read from code) · size S–M · Part of #39077.
Dedupe words: reaction batch row budget, REACTION_READ_COMMENT_IDS budget, record page payload vs direct read reactions declined. Adjacent but distinct: #39296, which is the per-read last-page cut, not the batch budget scope.
C. Observation for the seat (lower confidence; file only if confirmed)
The reaction read gate's candidate pre-scan reads at most READ_SCAN_LIMIT = 2,000 rows per read, offset-less. Comments whose reactions all fall past row 2,000 in created_at order are excluded fail-closed, with a warn line only. The gate's comment says "a comment feed reads … by comment_id, and never hits this". Since #39294 reads the whole thread, that assumption fails for threads with more than 2,000 reactions on main. After #39309 it fails per chunk, for 500 comments with more than 2,000 reactions, which narrows the gap but does not close it. A dedupe search for "pre-scan" + reaction on 2026-12-03T11:30Z found no open card.
Fixes #39297
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
answerDiscussion(packages/rest/src/record-page-routes.ts) read the reactions of a thread with ONEcomment_id $in [every comment id of the thread]. Verified onmainf808641: the plain$inarm ofpackages/drivers/driver-sql/src/sql-driver-filter-helpers.tscompiles to a single knexwhereInwith the whole list, and nothing indriver-sql/srcchunks it, so past 1,000 ids Oracle refuses the IN list (ORA-01795) and past 2,100 parameters SQL Server refuses the request. The reactions part then answers that refusal; the comments are still answered.Where the fix lives: in the route, as the card's claim scoped it.
driver-sqlis read, not changed.REACTION_READ_CHUNK_SIZE = 500(exported, documented): the most ids one reaction read binds. Half Oracle's 1,000 cap, which leaves SQL Server over 1,500 parameters for the rest of the statement (tenant scope, RLS and sharing predicates, the page window).readReactions(ids)reads the ids chunk after chunk, each chunk paged whole byreadWholeStreamexactly as PR fix(rest): serve the record page discussion whole past the data page size #39294 pages it, then merges the chunks into the spec's one oldest-first order (created_atas an instant, thenid) with a stable sort. A thread of up to 500 comments is one chunk and keeps the database's own order, untouched.readWholeStreamtakeswalked, the reaction rows earlier chunks already read. Each chunk is its own query, which the door counts from its own offset 0, so a walk pastOS_DATA_QUERY_ROW_BUDGETacross chunks is refused in the route by the door's own rule,planQueryReadWindowfrom@objectstack/types, asked of the whole walk. The reactions arm answers the sameQUERY_ROW_BUDGET_EXCEEDED/400refusal (the door's own message text), and the comments are still answered. Withwalked = 0(the comments, and the first chunk) the code path is the one PR fix(rest): serve the record page discussion whole past the data page size #39294 shipped, byte for byte.setReactionReadChunkSizeForTests(n)is a test seam returning a restore function, in the shape of the existingsetCelPushdownLimitsModeForTests/setPreferencePageSizeForTests. It is not re-exported from the package entry (packages/rest/src/index.tsdoes not export this module), so no published type carries it. No env var.Files to read first, by risk:
packages/rest/src/record-page-routes.ts, thereadWholeStreamhunk: the twowalked > 0branches (the check after a chunk's first read, and theroomcheck inside the paging loop) carry the cross-chunk budget.packages/rest/src/record-page-routes.ts,readReactionsandcompareDiscussionOrder: the merge order.packages/rest/src/record-page-routes.test.ts, the new[#39297]describe nested in the[#39271]one (it reuses that block'spagingDoordouble).Two-minute verification:
pnpm --filter @objectstack/rest exec vitest run --maxWorkers=2 src/record-page-routes.test.ts→Tests 54 passed (54).Tests
New, in
record-page-routes.test.ts, chunk size forced to 3 or 4 through the seam, over the existingpagingDoordouble (the door's own windowing and budget refusal):created_atand sorts after it byid, so chunk-by-chunk concatenation is the wrong order; every read binds at most 3 ids, and the chunks are exactly the thread's ids;QUERY_ROW_BUDGET_EXCEEDEDrefusal of the reactions arm, with the whole thread still answered, for three shapes: the refusal after a later chunk's first read (chunks of 3, no page size; chunks of 3, page 2) and the refusal inside a later chunk's paging loop (chunks of 4, page 2);Ablations (fix committed first; each mutation through
scripts/ablation-replace.mjs, which proved the anchor hit once, the blob changed, and the restore to HEAD blob8a599e84f830with an emptygit diff HEAD). The test imports the route by relative source path, so no build sits between mutation and run.$in)walkedpassed as 0 (no cross-chunk budget)A2's first attempt was refused by the tool before any run (its replacement text
recordsalready occurred in the file); it was re-run with a distinct replacement. Recorded here because it was a no-op.Code run at a7c52aa; the head 98a4ad0 adds only the changeset, so
src/is the same blobs.Local test and typecheck output
Derived gate families at 98a4ad0
node scripts/pm/dispatch-gates.mjs --commandsderived 70 commands for the three changed paths; all were run, each exit code captured before any pipe, then reconciled:NOT MEASURED, both PREREQUISITE NOT MET (exit 3):
check-plugin-teardown-shape.mjs --self-test(its fixture commit is unreachable on this shallow clone) andcheck:dual-build-cjs-loads(it reads every package'sdist/; only@objectstack/rest's dependency closure was built). CI runs both.check:query-options-erasureandcheck-comment-mask-corpus.mjsfirst hit a 240 s per-command wrapper on a shared box (exit 124); each was re-run alone to its verdict: exit 0 (388 s and 236 s).overlap-check.mjs --branch=HEAD:origin/main(dc4a2cd) merges cleanly, VERDICT clean.Acceptance notes
$inarm has no IN-list bound for any caller. Any other read that binds an unbounded id list hits the same Oracle and SQL Server ceilings. I inferred this from reading the code and measured it nowhere else. Carrier: none.created_atis compared as an instant (aDate, a number, or a parseable string), andidby plain code-unit order, numbers by value. This order is only used when there is more than one chunk. If a database collation orders two ids at the same instant differently (for example a case-insensitive collation), the merged order of that tie can differ from what one statement would answer.[data] read refusedwarn line. The refusal on the first chunk and on the comments is still the door's own and still logs.test:repowas not run locally: the diff edits no test in that project, and no derived family named it. CI'sTest Coreruns it.Generated by Claude Code