Repository navigation
feat(objectql): a bulk update recomputes its parents' roll-up summaries once, at the end of the batch - #34439
Conversation
…e per descriptor and one write per parent Claude-Session: https://claude.ai/code/session_01FEkQ5pHNFS9mn8hS13iGyL Co-authored-by: Claude <noreply@anthropic.com>
…y on SQLite and PostgreSQL Claude-Session: https://claude.ai/code/session_01FEkQ5pHNFS9mn8hS13iGyL Co-authored-by: Claude <noreply@anthropic.com>
…ubles the $in a grouped aggregate asks Claude-Session: https://claude.ai/code/session_01FEkQ5pHNFS9mn8hS13iGyL Co-authored-by: Claude <noreply@anthropic.com>
…gress, #33795 second half) Work in progress, stopped by the seat mid-build. Not reviewed, not built, not tested. Done: - IObjectQLEngine.deferSummaryRecompute? (optional by ruling 6922040858) and the same optional member on MetadataHostEngine. - ObjectQL.deferSummaryRecompute: callback form, ambient AsyncLocalStorage scope (summaryBatchStore), nested call joins the outer scope; inside it recomputeSummaries records the rows' foreign keys (merged per child object, tenant and user) instead of running; the outermost call runs one recompute per entry after the callback settles, on every way out; a failure after a resolved callback throws SummaryRecomputeError with written = the callback's result. Not done: - protocol-batch-data.ts: runUpdateManyLoop and the update arm of runBatchDataLoop do not probe or use the member yet (non-atomic: log stale lines and keep the outcome; atomic: roll back). - Pins (statement counts, value parity, ablations, the three extra pins), changeset, generated spec artifacts, PR. Claude-Session: https://claude.ai/code/session_01FEkQ5pHNFS9mn8hS13iGyL Co-Authored-By: Claude <noreply@anthropic.com>
runUpdateManyLoop and the update arm of runBatchDataLoop probe the engine's optional deferSummaryRecompute and run their per-row loop inside it, so the parents' summaries recompute once when the loop settles. Atomic: a recompute failure fails the last landed row and rolls the batch back with today's envelope. Non-atomic: logged, rows stay written. WIP: untested. Claude-Session: https://claude.ai/code/session_01FEkQ5oe2Rer5VB78pdZqkr Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oe2Rer5VB78pdZqkr Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oe2Rer5VB78pdZqkr Co-Authored-By: Claude <noreply@anthropic.com>
…d values Claude-Session: https://claude.ai/code/session_01FEkQ5oe2Rer5VB78pdZqkr Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oe2Rer5VB78pdZqkr Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oe2Rer5VB78pdZqkr Co-Authored-By: Claude <noreply@anthropic.com>
…he facade engine.ts is a facade under a line ceiling; the method there is a one-line delegation and the contract text lives with the body. Claude-Session: https://claude.ai/code/session_01FEkQ5oe2Rer5VB78pdZqkr Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oe2Rer5VB78pdZqkr Co-Authored-By: Claude <noreply@anthropic.com>
… collection Claude-Session: https://claude.ai/code/session_01FEkQ5oe2Rer5VB78pdZqkr Co-Authored-By: Claude <noreply@anthropic.com>
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5oe2Rer5VB78pdZqkr Final head for review: Local verification at this head: the three pin files green (objectql Landing waits for two things: the maintainer's word on the open question in the body (a validation rule reading a parent roll-up during a bulk update; rulings 6922040858 and 6377847361), and the contract review (ruling parameter 6). Stacked on #34421, which lands first. |
📓 Docs Drift CheckThis PR changes 4 package(s): 40 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 — 177 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 c13daf2ab5977604b12fca7f477c5eae8996bb12 && git checkout c13daf2ab5977604b12fca7f477c5eae8996bb12
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin ec6b5fd3464ce5413691a7cab810d1c19db50182 584fd7dface2abb758ffcaf2291191ea12f94a56 && git checkout -B drift-repro ec6b5fd3464ce5413691a7cab810d1c19db50182 && git merge --no-ff 584fd7dface2abb758ffcaf2291191ea12f94a56
node scripts/docs-audit/affected-docs.mjs --json ec6b5fd3464ce5413691a7cab810d1c19db50182
|
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract-review-claim: session_01FEkQ5mjfxPu5HKjUtuveBR · head e68802f · 2026-11-16T18:10Z |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kcNtBBExhz4DZqYbi 席位核对 · ACCEPT (L1, first read; landing blocked — see B1, the open ruling and the L2) · Head-sha: e68802f · 2026-11-16T18:10ZL1 thread L1-a, routed by the seat for card #33795 (the second PR). I read the final-head comment 6924800650, dev report 6924821273, maintainer ruling 6922040858 (letter A: an optional batch-scope member on the engine contract defers the bulk update's roll-up recompute to batch end, and the parent's hooks run once per recompute), and the PR body. I read this PR's own diff against
Before landing (blocking)
Should (small)
Notes (not blocking)
Landing: not Tier H by path (the spec contract file is a published-schema face, so the L2 is owed, not a Tier H hand-off). The seat lands it after B1, the ruling, the L2 PASS, the rebase delta and green CI. |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract reviewServed-tier: First round on this head; no earlier record on the PR. Read: card #33795 with rulings 6922040858 and 6377847361, announce 6924800650, report 6924821273, the net diff against ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentThe spec member against the ruling and its first consumers (the facet,
S2 (should-fix) — ruling parameter 4 asks for a pin where a RULE reading the parent's summary sees the pre-batch value. The pin in S3 (should-fix) — the spec docblock says "Inside a transaction the recompute runs before the commit" and "a nested call joins the open scope". Together they are false for a call that joins an outer scope from inside a transaction opened within that scope (an atomic N1 (nit) — the spec docblock states the cost ("one grouped aggregate per summary field and one write per parent") as contract; it is per caller and per id chunk, and a roll-up cycle keeps the per-parent order. No must-fix. S1 to S3 close in the delta that follows the maintainer's answer; landing waits for that answer in any case. Implemented-by: VERDICT: PASS |
…ert into a second child The deferral scope covers every write made while the callback runs, including writes a hook issues on another object. The spec docblock and the changeset now say so, and an engine pin has a child-row hook insert into a second child object of the same parent: no parent is recomputed during the batch, and each child object recomputes once at the end. The batch-key docblock names which context wins when two writes share a user and tenant but not a transaction handle. Co-Authored-By: Claude <noreply@anthropic.com>
…after that commit Contract review 6925110082 S3 and N1. The spec, facet and changeset said the recompute runs before the commit inside a transaction, and that a nested call joins the open scope. Together that was false for a call that joins from inside a transaction opened within the scope: its transaction commits first and its rows recompute when the outer scope ends. Say so. The spec docblock no longer states the statement cost as contract; the facet states it per child object, caller and id chunk. Co-Authored-By: Claude <noreply@anthropic.com>
Contract review 6925110082 S1. A child-side rule or hook reads a different parent value during a bulk update, and the parent's authored hooks and validation run once per batch, not once per row: when an authored hook runs and what it reads move, as in 33760-async-hook-on-commit. objectql goes to minor; the Skills-docs line names the data skill's roll-up section as a follow-up owed after the maintainer's answer. Co-Authored-By: Claude <noreply@anthropic.com>
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract-review-claim: session_01FEkQ5mjfxPu5HKjUtuveBR · head 7c80b9d · 2026-11-16T23:02Z |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kcNtBBExhz4DZqYbi 席位核对 · ACCEPT (L1, delta) · Head-sha: 7c80b9d · 2026-11-16T23:03ZL1 thread L1-a for area o1-B, reading the delta from my REWORK 6930506752 at
Landing: L1 holds at this head. What remains is review#2's contract delta at this head and green CI. Ruling 6928862195 is built. |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract reviewServed-tier: Delta round on prior record 6930582939 (FAIL at Merge check: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
M2 (must-fix) — S4 (should-fix) — same function: a stored computed field of the row being written that reads the parent's summary one hop (
N2 (nit) — unchanged. No other earlier finding is open (S1, S2, S3, N1 closed in earlier rounds). Landing waits for M2, S4 and green CI. Implemented-by: VERDICT: FAIL |
…p read count as reading a roll-up Contract review 6932181981 M2 and S4, inside ruling 6928862195 (B). - M2: the recompute's own write of the parent computes its stored computed fields and judges their declared bounds (validateRecord, a unique index). A bound (min, max, minLength, maxLength, pattern, unique, required) on the summary itself or on a stored computed field of its object now counts as a read, and the closure follows the field to the summary it is calculated from. - S4: a stored computed field (an expression on a field that is not a formula) reading another row one hop stores what it read at its own write, so its one-hop reads seed the set too. A formula does not: it is computed when read. Door pins against today's per-row path: the cap spelled as min 0 on the parent's stored room, and a line's stored rank = owner.flagged_count. fields.mdx, the spec docblock and the changeset say so; the docblock's list now reads for all three classes (N4). Co-Authored-By: Claude <noreply@anthropic.com>
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5oe2Rer5VB78pdZqkr Head: Answers contract review 6932181981 (M2, S4, N4, N5, and the red-count note). One commit after
Landing waits for the contract-review delta (and L1's, if it reads this head) and a green CI. |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract-review-claim: session_01FEkQ5mjfxPu5HKjUtuveBR · head 8191a5d · 2026-11-17T00:02Z |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kcNtBBExhz4DZqYbi 席位核对 · ACCEPT (L1, delta) · Head-sha: 8191a5d · 2026-11-17T00:03ZL1 thread L1-a for area o1-B, reading the delta from my ACCEPT 6932033886 at
Landing: L1 holds at this head. What remains is review#2's round-4 delta and green CI. |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract reviewServed-tier: Delta round on prior record 6932181981 (FAIL at ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
S5 (should-fix) — N2 (nit) — unchanged. No must-fix. No other earlier finding is open. Landing waits for S5 and green CI. Implemented-by: VERDICT: PASS |
…t, and an unbounded stored computed field Co-Authored-By: Claude <noreply@anthropic.com>
…ary's precision or unique index, count as reading it The recompute's own write judges every value it stores against its declaration, so a stored computed field calculated from the summary is judged at each intermediate value one by one, bound or not (an option list, a value domain, a number that is not finite). The summary itself counts when it declares a bound, now including `precision`, or when a declared unique index names it. Co-Authored-By: Claude <noreply@anthropic.com>
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5oe2Rer5VB78pdZqkr Round 5 · Head-sha: 584fd7d · 2026-11-17T00:19ZAnswers contract review 6933280758 (PASS with S5 owed); L1 ACCEPT 6933240039 was at
Owed: the review#2 and L1-a deltas at this head, then green CI. The ready flip and landing belong to the seat. |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract-review-claim: session_01FEkQ5mjfxPu5HKjUtuveBR · head 584fd7d · 2026-11-17T00:20Z |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kcNtBBExhz4DZqYbi 席位核对 · ACCEPT (L1, delta) · Head-sha: 584fd7d · 2026-11-17T00:20ZL1 thread L1-a for area o1-B, reading the delta from my ACCEPT 6933240039 at
Landing: L1 holds at this head. What remains is review#2's S5 delta and green CI. |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract reviewServed-tier: Delta round on prior record 6933280758 (PASS at Merge check: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
N2 (nit) — unchanged. No must-fix. No open should-fix. Landing waits for green CI. Implemented-by: VERDICT: PASS |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5pmEYLVFDcQ1Z1CS8H Seat landing · 2026-11-17T00:23ZHead-sha:
|
Requested by Leehom · project thread
Fixes #33795
Clause-②: yes (widening)
Metadata-protocol: semantic
Skills-docs: follow-up owed —
skills/objectstack-data/rules/relationships.md(Roll-up Summaries: "the engine recomputes it server-side whenever a child is inserted/updated/deleted") does not say that a bulk update recomputes once at the end of the batch, that a summary a rule reads still recomputes after each row, or that a hook reads the pre-batch value meanwhile (ruling 6928862195); it moves as a governed skills-only change.content/docs/data-modeling/fields.mdxis updated here.维护者速读
deferSummaryRecompute(回调形,同transaction);批量更新的两个入口(updateManyData和通用批量接口的 update)在它里面逐行写,父记录汇总在整批结束时统一重算一次。被规则读到的汇总例外,仍每行算一次(裁决 6928862195 B):另一对象的校验规则隔一跳读、明细的parent.字段条件读、父对象自己的规则读,也包括经公式或存储计算字段间接读、经汇总链读,以及汇总或父对象存储计算字段上声明的 min/max/unique 等约束,和任何对象上隔一跳读汇总的存储计算字段。批量改 50 行、10 个父记录、2 个汇总字段:400 → 182 条语句(无汇总时 150,不变)。SQLite 和 PostgreSQL 16 实测。Metadata-protocol: semantic,objectql 升 minor。客户能看到的两处:批量更新进行中,钩子和流程步骤读到的父记录汇总是批前的值(与批量新建一致);被延后的汇总,父记录的钩子/校验/审计/实时事件每批每个父记录只跑一次。校验规则的结果与今天的 main 相同。回滚 = revert 本 PR。packages/objectql/src/engine-summaries-and-expansion.ts(deferSummaryRecompute,recomputeSummaries开头的记录分支,writeTransactionOf、rollUpReadByARule);packages/objectql/src/summary-rule-reads.ts(「被规则读到」的判定);packages/metadata-protocol/src/protocol-batch-data.ts(inSummaryBatch);packages/spec/src/contracts/objectql-engine.ts(契约加宽处)。pnpm --filter @objectstack/objectql exec vitest run src/summary-rollup.test.ts,预期 61 个用例全绿,其中deferSummaryRecompute: one roll-up batch一组 32 个(含裁决 B 的 20 个:规则读到的汇总每行即算,包括父对象自己的规则、经公式或计算字段、经汇总链、声明的约束、隔一跳读汇总的存储计算字段;parent.status这类读非汇总字段的条件保留延后)。Ruling 6928862195 (B 「B 被规则读到的合计不延后」), amending ruling 6922040858
The first ruling's premise, that a rule reading the parent's summary sees the pre-batch value during a bulk update "as it already does for
createMany", does not hold for validation rules: since #25579 (ruling 6377847361, 「批量等于逐条,并发不保证」) a multi-row insert overlays the batch's earlier rows on such a rule, and today's per-rowupdateManyre-reads the recomputed parent before each row. The maintainer ruled B: the deferral stands, and a roll-up summary field that a rule reads is not deferred.Built here as the ruling's parameters set it:
rollUpReadByARulein the record branch ofrecomputeSummaries), not in the doors.summaryFieldsReadByRulesbuilds a set of<object>.<field>keys from the registry: (i) a validation rule of any object reading a field one hop through a reference (collectPredicateRelationships, the hops Declarative "at most one row per parent where X" (conditional unique) — summary-based guards miss rows in the same bulk insert #25579's accumulation covers), resolved to the reference's target object; (ii) a detail object's field-levelrequiredWhen/readonlyWhenreading a field onparent(analyzeRelationshipTraversals(source, 'parent'), by field name), resolved to the master object. A recompute runs at once when any summary field among the written child object's roll-ups is in the set. The set is kept per summary index (aWeakMapkeyed by the index), so a metadata change that rebuilds the index rebuilds it too. Class (ii) could name the field, so both classes are built and no limit card is owed. Round 3 adds (iii), a rule of the summary's own object, and closes the set over computed fields and summary chains (below).parent.predicate reading a field that is not a summary keeps the deferral. Probed on the real showcase metadata (all 22 objects): the read set isshowcase_account.status,showcase_invoice.status, no summary, so the invoice line'sparent.status == 'paid'keeps its deferral; with the line'sproduct.readonlyWhenchanged toparent.total > 100the set gainsshowcase_invoice.total(one-off probe, not committed; the engine pin mirrors it).createManyand a predicate update" is gone from the spec docblock, the facet docblock, the door docblocks and the changeset; they say rule behaviour does not change against today'smain, and that hooks and flow steps read the pre-batch value during a bulk update as during a bulk create.content/docs/data-modeling/fields.mdxgains the bulk-update half (「批量等于逐条」 for a rule reading a parent summary; hooks and flows read the pre-batch value inside one batch, on create and update alike).Seat route (not a maintainer ruling)
An atomic bulk update whose end-of-batch recompute fails answers today's
200rolled-back envelope: the last row that landed carries the refusal's own row error (ERR_SUMMARY_RECOMPUTE, the withheld sentence), the rows before itROLLED_BACK, the restNOT_ATTEMPTED, and nothing is committed. That is the envelope a per-row recompute failure answered, so the response contract does not move. Pinned inprotocol.many-data-atomic.test.ts.Stacking
Built on #34421 (the grouped recompute,
Part of #33795), which merged as6aeb665f.origin/mainat6aeb665fis merged in (54bc155b), so this PR's diff againstmainis the deferral half only (17 files at7c80b9db, after a second merge ofmainat1e91fa3e). The merge took this branch's side for the three files #34421 added that this PR extends (engine-summaries-and-expansion.ts,summary-rollup.test.ts, the dogfood pin); main's copies of them were byte-identical to #34421's head1789606e. The branch name is the one the platform pins this thread to (claude/project-thread-vah7al); the hand-over head wasclaude/issue-33795-batch-deferral@7480459d.What changes
IObjectQLEngine.deferSummaryRecompute?(callback), generic over the callback's result type and answering that result, optional by ruling 6922040858 (the header's list of members optional by ruling now names four). Callback form, entered and left by the engine astransactionis; a nested call joins the open scope.MetadataHostEngine, typed off the spec member.ObjectQL#deferSummaryRecomputedelegates toSummariesAndExpansionFacet.deferSummaryRecompute. The scope is ambient (AsyncLocalStorage), because a row's write reachesrecomputeSummariesthrough hooks,ctx.apiwrites and nested engine calls. Inside itrecomputeSummariesrecords the foreign keys of the rows (copied, per child object, tenant and user) and returns no failure. When the outermost callback settles the scope closes and each recorded entry runs ONE grouped recompute (perf(objectql): recompute roll-up summaries with one grouped aggregate per field and one write per parent #34421's path), outside the scope, so a parent write recomputes its own parents at once, in dependency order. Every way out recomputes: resolved, the result, orSummaryRecomputeErrorwithwritten= the result; rejected, the recompute runs for the rows that landed and the callback's error is rethrown (a recompute failure there is logged). A write recorded after the scope closed (work the callback started and did not await) recomputes at once. The scope is ambient, not tied to the object the door updates: a write a hook issues on another object during the batch (its own insert, update or delete) is deferred too. When the call that opens the scope runs inside a transaction, the recompute runs before the commit. Only writes under the transaction the scope was opened in (or under none) are recorded: a write under another transaction opened within the scope (a hook's ownctx.api.transaction, or an atomic batch reached from inside a non-atomic one) recomputes at once inside that transaction, as before (writeTransactionOf, which reads the write's transaction the waybuildDriverOptionsdoes). A roll-up a rule reads is never recorded (ruling 6928862195, below):rollUpReadByARuleasks whether any summary field among the written child object's roll-ups is read by a rule (summary-rule-reads.ts), and if so the recompute runs at once. The engine.ts facade only delegates; the docblock lives with the body (the facade's line ceiling).inSummaryBatchprobestypeof engine.deferSummaryRecompute === 'function'and runs the loop inside it; without it the loop runs as before.runUpdateManyLoop(both arms ofupdateManyData) and theupdateoperation ofrunBatchDataLoopuse it;create,upsertanddeletekeep their per-row recompute (the ruling moved the update arm only). The atomic loop isrunAtomicBatch'srunLoop, so the scope is inside the transaction. Non-atomic stale refusal: rows answered as written, the stale column logged once aterror(staleSummaryAnswerLines, aslandedDespiteStaleSummarylogs a row's). Atomic: see the seat route above.@objectstack/metadata-protocoladded to devDependencies and aliased to source invitest.config.ts(the door wiring is the pin's subject).What a caller can see (also in the changeset): during a bulk update a hook or flow step reading a parent's summary reads its pre-batch value until the batch ends, as during a bulk create; a rule's answer does not change against today's
main(a summary a rule reads is not deferred); the parent's own write path (hooks, validation, audit, realtime) runs once per recompute, so once per parent per batch for a deferred roll-up, not once per child row. Each child row's own hooks, validation, audit and realtime run where they ran.Statements (measured, SQLite and PostgreSQL 16.15, identical)
A 50-row
updateManyDataover 10 parents, system context:With the scope a bulk update pays what a
createManypays: one grouped aggregate per summary field plus one write per parent (3 statements: the update and its two reads of the parent). The ruling's "about 608 to about 390" was an estimate on the card's admin bench; these are the measured engine-and-door counts under system context.Tests
packages/objectql/src/summary-rollup.test.ts, new top-level describe[#33795] deferSummaryRecompute: one roll-up batch(32; the round-2 to round-4 pins are listed under those rounds): a loop of single-row updates recomputes once (3 parent writes, 2 aggregates) and CONTROL outside a scope (6 writes); a hook reading the parent summary during the batch reads the pre-batch value ([5, 5]; ruling 6928862195 parameter 6 makes this the hook pin); a nested call joins; a summary over a summary recomputes up the chain when the scope ends; a throwing callback still recomputes the rows that landed and rethrows; a failed recompute answersERR_SUMMARY_RECOMPUTEwithwritten= the callback's result and the other parent still recomputed; inside a transaction the parent write precedes the commit; an un-awaited write after the scope closed recomputes at once; a scope with no roll-up write runs nothing; a child-row hook that inserts into a second child object of the same parent is deferred too (no parent write during the batch, 6 parent writes at the end for 3 parents x 2 child objects where the per-row loop pays 12, one grouped read of the second child).packages/metadata-protocol/src/protocol.many-data-atomic.test.ts, new describe[#33795] the bulk update doors run as one roll-up batch(7), over the file's store engine with a fake scope: everyengine.updateruns between entering the scope and its one recompute; a non-atomic batch stopped by a failed row still ends the scope; a non-atomic failed recompute keeps the rows and logs oneerrorline; atomic recompute runs before the commit; atomic failed recompute rolls back with the envelope above; an engine without the member is unchanged;batchDataupdate enters the scope anddeletedoes not.packages/qa/dogfood/test/rollup-grouped-recompute-33795.test.ts, new describeroll-up batch deferral through the bulk update door (#33795)(2 per cell, the rule describe of round 2, 8 per cell, and the round-3/4 parity describe, 12 per cell), real engine over a realSqlDriver, statements counted by knex'squeryevent: the table above; value parity for every summary kind (count, sum, min, max, avg, filtered count and sum) after a non-atomicupdateManyData, an atomic one,batchDataupdate, a bulk update stopped by a failed row, and the same door on the engine with the member hidden, each checked against the one-parent aggregate and a hand count, with rows moving between parents and in and out of the filters.Ablations (one-off, not committed)
node scripts/ablation-replace.mjs --file packages/objectql/src/engine-summaries-and-expansion.ts --anchor "if (scope && !scope.closed) {" --replacement "if (scope && !scope.closed && false) {": mutation landed (blob 191a8f40 → dfb0159d);summary-rollup.test.ts6 failed | 33 passed (the six scope pins that read a count or a pre-batch value; CONTROL, throw, late-write and no-op stay green as they should); restored, blob == HEAD,git diff HEADempty.ABLATED33795;pnpm --filter @objectstack/objectql build;ablation-dist-preflight.mjs @objectstack/objectql ABLATED33795found it in 4 built files; dogfood file 2 failed | 6 passed: both door statement pins red on SQLite and PostgreSQL (updateManyback to 150/350/400), every value-parity pin green. Restored; rebuilt;--absentpreflight clean in all 14 built files and the tree.--anchor "if (typeof engine?.deferSummaryRecompute !== 'function') return await runLoop();" --replacement "if (engine || true) return await runLoop(); // ABLATED-33795":protocol.many-data-atomic.test.ts6 failed | 15 passed (every door pin but the no-member CONTROL); restored, blob == HEAD. (A first attempt whose replacement contained the anchor text was refused by the tool before any run, and rerun with a distinct marker.)Package suites and typecheck
pnpm --filter @objectstack/objectql testat a4adf63: 603 files, 13485/13485 passed.pnpm --filter @objectstack/metadata-protocol testat c37b71e: 346 files passed, 9 skipped; 22975 passed, 45 skipped. The commits after them move the engine docblock from the facade into the facet, drop a test cast and an unused parameter, add a module-top import to one test file and the dogfood alias; the three pin files were re-run at the final head e68802f: objectqlsummary-rollup.test.ts39/39, metadata-protocolprotocol.many-data-atomic.test.ts21/21, dogfoodrollup-grouped-recompute-33795.test.ts8/8 (both cells, withOS_TEST_POSTGRES_URLon PostgreSQL 16.15).tsc --noEmitpluscheck:test-typecheck):@objectstack/objectql,@objectstack/metadata-protocol,@objectstack/specexit 0.@objectstack/dogfood: NOT MEASURED locally (see Acceptance notes).pnpm --filter @objectstack/spec check:generatedafter a spec build: all 14 generated artifacts up to date.dispatch-gates.mjs --commands, 109 families) at e68802f: 108 exit 0;node scripts/check-plugin-teardown-shape.mjs --self-testexit 3, PREREQUISITE NOT MET (its fixture commit is outside this shallow clone; the diff does not touch it) — NOT MEASURED, CI runs it.--ranreconciliation: 109 accounted, 108 run, 1 NOT-MEASURED.check:facade-delegation-only(engine.ts over its line ceiling by 2; the docblock moved to the facet, the facade keeps a one-line delegation),check:query-options-erasure(a newas anyon test query options; typed instead), andcheck:test-source-aliastwice (the dogfood file's new@objectstack/metadata-protocolimport, now aliased to source; the atomic test file's reach to the dynamic@objectstack/lintload, now paid at module top).Review round 1 (L1 6924908574, contract review 6925110082)
Head
54bc155b: three commits aftere68802ff, then the merge ofmain.check:closing-target-claimred). The governingClaim:on Roll-up summary recompute: one grouped aggregate per batch, not per child row per field #33795 named perf(objectql): recompute roll-up summaries with one grouped aggregate per field and one write per parent #34421's branch. Comment 6924974543 restates this card thread's claim as aClaim:line withBranch: claude/project-thread-vah7al. The guard run locally against this PR reads it as UNDETERMINED (its branch reader parses onlyclaude/issue-N-…), warned and exit 0, the outcome the guard's own card-thread fixture pins.if (scope && !scope.closed && false)) turns it red with 12 parent writes during the batch; restored, blob == HEAD.summaryBatchKeydocblock says two writes under one user and tenant but different transaction handles share an entry, and the first row's context wins.Metadata-protocol: semantic,@objectstack/objectqlminor, with aSkills-docs:line (follow-up owed on the data skill's roll-up section, after the maintainer's answer). Precedent:33760-async-hook-on-commit. This PR body carries the same lines.updateManyData) and option B are held for the maintainer's answer on the open question above, as the seat asked; they land in the next delta, in the direction he rules. N2 (an atomic batch stopped by a failed row recomputes before rolling back) is unchanged: fewer statements than before, noted.Verification on the merged head (tree
a59b04d2, identical to the tree all of the runs below measured):pnpm --workspace-concurrency=2 --filter '@objectstack/dogfood^...' run build, exit 0). Typecheck@objectstack/spec,@objectstack/objectql,@objectstack/metadata-protocolexit 0, and@objectstack/dogfoodexit 0 (measured now that the closure is built).pnpm --filter @objectstack/objectql test: 603 files, 13487/13487.pnpm --filter @objectstack/metadata-protocol test: 346 files passed, 9 skipped; 22975 passed, 45 skipped.summary-rollup.test.ts40/40,protocol.many-data-atomic.test.ts21/21, dogfoodrollup-grouped-recompute-33795.test.ts8/8 withOS_TEST_POSTGRES_URLon PostgreSQL 16.15 (no skip).pnpm --filter @objectstack/spec check:generated: all 14 current.check-plugin-teardown-shape.mjs --self-testexit 3, PREREQUISITE NOT MET (shallow clone) — NOT MEASURED.dispatch-gates --ran: 109 accounted, 108 run, 1 NOT-MEASURED.Review round 2 (L1 6927725912 M1, ruling 6928862195)
Head
0868390f: three commits after54bc155b(M1 fix, ruling B, a census row), no merge. Round 1's contract review delta (6927718273) PASSed with S2 held for the ruling; S2 is now pinned (below).ctx.api.transaction(the begin/commit trio) commits inside a non-atomic bulk update. Its writes were recorded, and the end-of-batch recompute ran on the committed handle (the trio is not tracked inopenedUnits, sobuildDriverOptionskept it) and failed withERR_SUMMARY_RECOMPUTE. Now a scope records a write only when the write's transaction is the one the scope was opened under:writeTransactionOf(host, execCtx)reads it asbuildDriverOptionsdoes (the explicit handle unless closed, else the ambient one), and the scope keeps its opening transaction. Any other write recomputes at once inside its own transaction, as before the scope existed. This also replaces round 1's S3 wording: a call that joins an open scope from inside its own transaction now recomputes inside it, so its failure rolls that transaction back again.a write under a transaction a hook opened and committed inside the batch recomputes in that transaction, not on its dead handle at the end: the fake driver marks a handle done on commit and refuses any op on it. Red before the fix (1 failed:SummaryRecomputeError … for 3 parent record(s)), green after.if (scope && !scope.closed && writeTransactionOf(this, execCtx) === scope.transaction) {back toif (scope && !scope.closed) {: mutation landed (blob 56462ff8 → 6bcc3f60),summary-rollup.test.ts1 failed | 40 passed; restored, blob == HEAD.[ruling 6928862195 B] a roll-up a rule reads is not deferred(5), each a batch of six single-row updates under a scope, counting parent writes during the batch and after it: (i) a child validation rule reading the parent summary one hop → 6 during, 0 after; (i) a rule on ANOTHER object (inv_memo) reading the same summary → 6, 0; (ii) areadonlyWhen: 'parent.line_total > 100000'→ 6, 0; aparent.predicate reading a field that is no summary (the showcase shape) → 0, 3; a rule reading another field of the related row → 0, 3.a roll-up a rule reads is not deferred (#33795 B)per cell (8 per cell, 16 with PostgreSQL): a supplier with four summaries (filtered countprimary_count,score_avg,score_min,score_max) over four child objects, each with a rule reading its summary through the reference. For each function,continueOnErrorand atomicupdateManyDataof two rows answer what two single updates answer on a twin data set, field for field (success,code, message), and leave the same state (two primary contacts: the first admitted, the second refused with the rule's text; atomic: refused, nothing written). Red first on54bc155bplus the pins:16 failed; green with the test: 24/24 on SQLite and PostgreSQL 16.15. The round-1 statement and value pins stay green, so an object with no such rule keeps its deferred counts.&& !rollUpReadByARule(this, descriptors)) {): engine3 failed | 43 passed(the three rule-class pins; the two keep-the-deferral pins stay green, as they should). Dist leg, replacement carrying a code markerABLATED33795B: objectql rebuilt,ablation-dist-preflightfound it in 4 built files, dogfood file16 failed | 8 passed(every rule pin, both cells; statement and value pins green). Restored, blob == HEAD, whole-treegit status --porcelainempty, rebuilt,--absentpreflight clean.Verification on
0868390f:pnpm --filter @objectstack/spec build && pnpm --filter @objectstack/objectql buildexit 0. Typecheck@objectstack/spec,@objectstack/objectql,@objectstack/metadata-protocol,@objectstack/dogfoodexit 0.summary-rollup.test.ts46/46,protocol.many-data-atomic.test.ts21/21, dogfoodrollup-grouped-recompute-33795.test.ts24/24 withOS_TEST_POSTGRES_URLon PostgreSQL 16.15 (no skip).pnpm --filter @objectstack/objectql testata35af28b: 603 files, 13492 passed, 1 failed:federated-injected-column-readers.test.tsasks every seam use in the engine source for a READERS row, and the newsummaryFieldsReadByRulescallsreferenceTargetOf.0868390fadds its row (caller-predicate: it names the object a rule's one hop reaches, from the declaration, and reads no row); that file 5/5. No other file changed after the suite run.pnpm --filter @objectstack/metadata-protocol test: 346 files passed, 9 skipped; 22975 passed, 45 skipped.pnpm --filter @objectstack/spec check:generated: all 14 current.dispatch-gates --commands, 132 families now that a doc page is in the diff) at0868390f: 131 exit 0;check-plugin-teardown-shape.mjs --self-testexit 3, PREREQUISITE NOT MET (shallow clone) — NOT MEASURED, CI runs it.--ran: 132 accounted, 131 run, 1 NOT-MEASURED.54bc155b: the four reds (Build UI Depstransient anchor fetch,Check Changesetpush-run read of the old body,Test Core (7/8)history fetch timeout, and its aggregate) were infrastructure, noted in 6927631653; this head supersedes that run.Out of this card, filed by the seat, neither built here: #34465 (a predicate update,
multi: true) and #34466 (a multi-row insert and a field-levelparent.predicate).Review round 3 (L1 6930506752 M1, contract review 6930582939 M1 and N3)
Head
7c80b9db: four commits after0868390f(the fix, two census rows, the merge ofmain). The seat routed both must-fixes as inside ruling 6928862195, with no new question.recordorprevious(a validation rule's CEL condition at any depth of aconditional, the field astate_machine/format/json_schemarule names, and field-levelrequiredWhen/readonlyWhen).formula, or a stored field with anexpression) is calculated from, on its row and one hop through a reference, so it covers classes (i), (ii) and (iii) alike. This is finer than the "every summary of that object" over-read the review allowed: it follows the expression. The same closure follows summary chains: a summary a rule reads that aggregates a child field makes that field read, and a filtered one makes every summary of its child object read. Without that, a rule on the top of a chain would judge only the end of the batch.fields.mdx, the spec docblock and the changeset now say that every roll-up of that child object recomputes after each row, and name the computed-field and chain cases.a roll-up a rule reads through its own row or a formula is not deferred (#33795 B)). These are four cases, each runatomicandcontinueOnError, on SQLite and PostgreSQL 16.15. The oracle is the same door on the same engine with the member hidden, which is today's per-row recompute. The answer and the stored rows must match, and each atomic case asserts first that it is live (one by one, the batch is refused or a note is locked).room = 2 - line_count.slots = 1 - primary_countone hop.readonlyWhenreading the header's stored computedroom = 1 - flagged_countonparent.continueOnErrorcases), then 40/40 green.formula(not stored) read on the parent's own row or onparentis not computed where the rule or predicate is judged today. Measured: withrecord.room/parent.roomas formulas, today's per-row path admits the batch, so no door case can diverge there. Those reads stay in the closure, which costs only statements, and are pinned at the engine level.summary-rollup.test.ts, 10 new, 56 in all), in the ruling-B describe, each counting parent writes during and after a six-row batch:previousinside aconditional, and arequiredWhen→ 6, 0;git diff HEADempty, then rebuilt, and--absentis clean for all three markers.0868390f:Test Core (5/8)was red. The core censussecond-object-read-exposure.pin.test.tsasks every caller of the reference-target arbiter to be classified;24ad0728classifiessummary-rule-reads.tsasnot-a-served-read(it reads declarations, no record). The objectql censusfederated-injected-column-readers.test.tslikewise owed a row for the newkeysReadFromhop (7c80b9db).Build Docswas the transient anchor fetch (6930468696).origin/mainmerged cleanly (1e91fa3e; K was 15).Verification on
7c80b9db:pnpm --workspace-concurrency=2 --filter '@objectstack/dogfood^...' run build, exit 0). Typecheck@objectstack/spec,@objectstack/objectql,@objectstack/metadata-protocoland@objectstack/dogfood: exit 0.check:generated: all 14 current.summary-rollup.test.ts56/56,protocol.many-data-atomic.test.ts21/21, dogfoodrollup-grouped-recompute-33795.test.ts40/40 withOS_TEST_POSTGRES_URLon PostgreSQL 16.15 (no skip). The coresecond-object-read-exposure.pin.test.tspassed 4/4.pnpm --filter @objectstack/objectql testat1e91fa3e: 604 files, 13530 passed, 1 failed. That was the federated-column census asking a row forkeysReadFrom;7c80b9dbadds it, and that file passes 5/5.summary-rollup.test.tswas re-run after: 56/56.pnpm --filter @objectstack/metadata-protocol test: 346 files passed, 9 skipped; 22975 passed, 45 skipped.check-plugin-teardown-shape.mjs --self-testexited 3, PREREQUISITE NOT MET (shallow clone), so it is NOT MEASURED.--ran: 133 accounted, 132 run, 1 NOT-MEASURED.Review round 4 (contract review 6932181981 M2, S4, N4, N5; L1 ACCEPT 6932033886 at
7c80b9db)Head
8191a5d5: one commit after7c80b9db, no merge (K = 14 againstmainat push).M2: a declared bound on a value the recompute's write stores. The write judges a bound on the summary itself, or on a stored computed field of its object (
min,max,minLength,maxLength,pattern,unique,required), so that bound now counts as reading the field. The closure then follows the stored computed field to the summary it is calculated from. Door case: the cap spelled asmin: 0on the parent's storedroom = 2 - line_count, with no rule.S4: a stored computed field reading another row one hop. A stored computed field (an
expressionon a field that is not aformula) stores what it read at its own write, so its one-hop reads seed the set. Aformuladoes not, since it is computed when read. Door case: a line's storedrank = owner.flagged_count; one by one the two lines store 0 and 1, and deferred both would store 0.N4. The spec docblock now lists the classes and the closure for all three classes, and says a stored value matches one-by-one too.
N5. Each parity case now asserts that it is live under
continueOnErrorwhere it is (the formula hop, the header lock and the stored rank). The three cap cases are parity pins only undercontinueOnError: the per-row path logs the refused recompute and ends in the same rows. That is stated in the test.Red-first counts, reconciled (review ③). In round 3 the first red run had the
(ii)case as arequiredWhen, which was not live: its liveness assertion failed, which is the wrong reason. After the switch toreadonlyWhenonly SQLite was re-run red. The round-3 "10 red first" therefore mixed two runs. The counts that do reconcile are from this round's whole-test ablation, with the rule test forced off (String('ABL33795AL').length > 0 || …) and measured in the dist leg on both cells:continueOnErrorcases (6). The 14 still green are the 8 statement and value pins and the 3 cap cases undercontinueOnError(6), which are parity only (N5).continueOnErroron both cells), then green.Ablations of the two new seeds, each with a dist leg on both cells:
Every leg was restored with blob == HEAD, the package rebuilt, and
--absentis clean for all three markers.Verification on
8191a5d5:@objectstack/spec,@objectstack/objectql,@objectstack/metadata-protocoland@objectstack/dogfood: exit 0.check:generated: current.pnpm --filter @objectstack/objectql test: 604 files, 13536/13536. Pin files:summary-rollup.test.ts61/61,protocol.many-data-atomic.test.ts21/21, dogfoodrollup-grouped-recompute-33795.test.ts48/48 withOS_TEST_POSTGRES_URLon PostgreSQL 16.15. The coresecond-object-read-exposure.pin.test.tspassed 4/4. The metadata-protocol suite is unchanged since round 3 (no file of it moved): 22975 passed, 45 skipped.check-plugin-teardown-shape.mjs --self-testexited 3, PREREQUISITE NOT MET (shallow clone), so it is NOT MEASURED.--ran: 133 accounted, 132 run, 1 NOT-MEASURED.7c80b9dbfinished green (every third-party suite completed with no failure).Review round 5 (contract review PASS 6933280758 with S5; L1 ACCEPT 6933240039 at
8191a5d5)Head
584fd7df: main merged (fff7423e, K had reached 15), then two commits.precision, an option list, a value domain, a number that is not finite). The summary itself counts when it declares a bound (the list now includesprecision) or when a declared index withuniquenames it.amountis stored fromtotal).precision; a unique index naming the summary; an unbounded stored computed field → at once; controls: a non-unique index, and a stored computed field reading no summary, keep the deferral. 3 red first, then 65/65.--absentclean for both markers.584fd7dfat hand-off: the full objectql and metadata-protocol suites, the derived gates. CI runs on the push.Acceptance notes
OS_TEST_POSTGRES_URLfor@objectstack/dogfood, so the PostgreSQL cell of both dogfood describes is a named skip in CI (noted on perf(objectql): recompute roll-up summaries with one grouped aggregate per field and one write per parent #34421 too). Measured here on a local PostgreSQL 16.15.@objectstack/dogfoodtypecheck was NOT MEASURED in round 0 (unbuilt closure); in round 1, with the closure built, it exits 0.staleSummaryAnswerLinesis unchanged.Verification
Generated by Claude Code