Repository navigation
fix(objectql)!: a multi-row insert counts its earlier rows into the parent summary a field-level parent. predicate reads - #34612
Conversation
…arent summary a field-level parent. predicate reads The multi-row insert read the master-detail header once for the batch, so a detail object's requiredWhen reading a header roll-up (parent.line_count >= 2) judged every row against the summary as it stood before the batch. The batch summary accumulator now overlays the header row too (overlayRow), the way it already overlays the related binding a validation rule reads through a reference, on the write and on the multi-row insert preview. Claude-Session: https://claude.ai/code/session_01ADHkmPgdzD1Rp6LuxSPNpk Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check3 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 — 21 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 1d3f0d4a9c17de87ed189c37f5af2298d721efc0 && git checkout 1d3f0d4a9c17de87ed189c37f5af2298d721efc0
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 8dd8192cbfb35dddc4f38f228edc1fb62c909ad3 3b8da3efcece663102807c87c3fc38c876e236f1 && git checkout -B drift-repro 8dd8192cbfb35dddc4f38f228edc1fb62c909ad3 && git merge --no-ff 3b8da3efcece663102807c87c3fc38c876e236f1
node scripts/docs-audit/affected-docs.mjs --json 8dd8192cbfb35dddc4f38f228edc1fb62c909ad3 |
|
repo:objectstack#2 · os-steve · session_01ADHkmSLi1reMd27fT62jJ3 Final head · PR #34612 · 2026-11-17T04:10Z Final head for L1 and L2:
|
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract-review-claim: session_01ADHkmP44onN8RMzsPMqjRq · head 3b8da3e · 2026-11-17T04:11Z |
|
repo:objectstack#2 · os-steve · session_01ADHkmTHGRTjPqZAcBuo9WH 席位核对L1 first review · REWORK (1 body item, no head move) · head REWORK
Checklist (read on GitHub at this head, not from the report)
Owed after this
|
|
repo:objectstack#2 · os-steve · session_01ADHkmTHGRTjPqZAcBuo9WH 席位核对L1 delta · ACCEPT · head Delta read
Owed after this
|
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract reviewServed-tier: Inputs read: card #34466 body and all 5 comments; PR #34612 body, 7-file list, 3 comments and the net diff against merge-base ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentThe narrowing makes the published rule real; it takes no declared capability away. The spec on Attempts to break it, each read in the code at this head:
Tests against the card: the Done-when asks for a pinned case plus a CONTROL reading a non-summary header field. The engine pins use three rows where the third is the first one refused, on the real engine and recompute, with the one-by-one reference answer beside them, the atomic and per-row doors, the preview, the per-header split and the Findings:
No must-fix, no should-fix. Implemented-by: VERDICT: PASS |
|
repo:objectstack#2 · os-steve · session_01ADHkmQ2SN4K183oqAvUajA Seat record · 2026-11-17T04:20Z · Head-sha: 3b8da3e 维护者速读
席位意见:同意合并。这是 #25579 裁决「批量等于逐条」的同族新支,按继承元规则不另开决策卡;收窄方向就是把逐条插入会拒的行在批量里也拒掉,实测拉动为 0(无应用写此类条件),失败方向是响亮拒绝而不是静默放过。 席位核对
|
Requested by Steve · project thread
Fixes #34466
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — skills/** teaches the parent. predicate (objectstack-formula SKILL.md, parent.status) but says nothing on how a multi-row insert reads a parent summary
维护者速读
requiredWhen(例如parent.line_count >= 2)现在把同批前面已通过的行算进汇总,和一行一行插入的结果一致;导入的试运行(预览)也一样。parent.的字段级条件仍按批前的值判断,同一批三条空描述的明细会全部通过,逐条插入时第三条会被拒。parent.汇总字段写requiredWhen的明细对象,hotcrm 与示例应用里没找到)。读非汇总字段的条件(如parent.status)、单行插入、更新都不变。回滚即撤回本 PR,无数据迁移。packages/objectql/src/summary-batch-accumulation.ts(新增overlayRow)、packages/objectql/src/engine-insert.ts(insertParentOf)、packages/objectql/src/summary-rollup.test.ts(末尾 objectql: a multi-row insert does not accumulate earlier rows into a parent summary that a field-level parent. predicate reads #34466 一组)。pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/summary-rollup.test.ts,预期全过;其中 objectql: a multi-row insert does not accumulate earlier rows into a parent summary that a field-level parent. predicate reads #34466 一组 7 条,去掉修复后 3 条变红。What changes
A multi-row insert reads the master-detail header once for the whole batch (
resolveMasterDetailParents, for a detail object that declares aparent-scopedrequiredWhen). Since #25579 the rows the rules admit are accumulated in memory and overlaid on the related binding a validation rule reads through a reference; the header a field-levelparent.predicate reads was not overlaid, so every row judgedparent.SUMMARYas it stood before the batch. #25579's dev report named this as outside its card.packages/objectql/src/summary-batch-accumulation.ts—BatchSummaryAccumulator.overlayRow(object, row): the same overlay for one stored row of the roll-up's parent object (a copy; an unbound header,nullorundefined, is returned as it is).overlay()now shares its per-row body (patchRow); its behaviour does not move.packages/objectql/src/engine-insert.ts— the validation loop bindsparentthroughinsertParentOf, which overlays the header when the batch has an accumulator and the object has one master-detail relation.packages/objectql/src/engine-validate.ts— the multi-row insert preview bindsparentthe same way, so the import's dry run answers what the commit does (Declarative "at most one row per parent where X" (conditional unique) — summary-based guards miss rows in the same bulk insert #25579 changed the preview and the write together). Added to the claim's file surface by the area (comment on objectql: a multi-row insert does not accumulate earlier rows into a parent summary that a field-level parent. predicate reads #34466).content/docs/data-modeling/fields.mdx— one sentence in the bulk-create paragraph: a detail object'srequiredWhenreading the summary onparentreads it the same way..changeset/34466-batch-insert-parent-summary-predicate.md—patchon@objectstack/objectql, BREAKING, FROM → TO and the one-line fix, ADR-0087not-required (no-migration-prescription).The "Done when" fork of the card: the predicate analysis does name the field it reads (
summary-rule-reads.ts, class (ii), landed with #34439), so this PR makes the insert equal one-by-one; no docs limit is written.Why
Ruling 6377847361 (letter C, 「批量等于逐条,并发不保证」) and ruling record 6928862195 (B, 「被规则读到的合计不延后」): a rule's answer inside one batch is the answer one-by-one writes give. With
requiredWhen: 'parent.line_count >= 2'ondescription, three bare lines inserted one at a time admit two and refuse the third; inserted in one batch they were all admitted.What narrows, named in the changeset: such a batch now refuses the row one-by-one inserts refuse (
insert(array)refuses the whole batch;insertManyreports that rowok: false). Not moved: aparent.predicate reading a field that is no summary (parent.status), a single-row insert, an update, an unbound header, anavgsummary (it keeps reading the stored value, as on the reference arm).Tests
packages/objectql/src/summary-rollup.test.ts— a new top-leveldescribe(objectql: a multi-row insert does not accumulate earlier rows into a parent summary that a field-level parent. predicate reads #34466) on the file's memory driver, where the roll-up recompute runs for real: the one-by-one reference answer;insert(array)refuses withVALIDATION_FAILED/ 400 /description: requiredand writes nothing;insertManylands the first two and reports the third; a refused row is not counted; two headers in one batch count separately; CONTROLparent.statusanswers as before (draft admits, sent refuses onnote); the multi-row preview answers[true, true, false].packages/objectql/src/summary-batch-accumulation.test.ts—overlayRowmoves the summary on a copy; leaves an unbound header, another parent id, another object and a header not handed the summary as they were.Ablation (
node scripts/ablation-replace.mjs, one mutation):overlayRow'sreturn (patchRow(object, row) as R | undefined) ?? row;replaced withreturn row;(anchor x1 → x0, blob6d5e97b4ab77→e61da8f1f2ce). These suites import the engine from source, so no rebuild. Result:Tests 4 failed | 82 passed (86)— red:insert(array),insertMany, the preview, and theoverlayRowunit pin; green as predicted: one-by-one, refused-row, two-headers, CONTROL and the "leaves as it was" unit pin. Restore: blob6d5e97b4ab77== HEAD,git diff HEADempty.Acceptance notes
engine-insert.ts:git merge-tree --write-treeof this head against its headea224164is clean.multi: true) is not touched here; it follows in its own PR.Verification
Readings below were taken at
978472fc(the fix commit, beforeorigin/mainwas merged at3b8da3ef). The merge brings no change topackages/objectql; the full dogfood battery and the derived gate round are re-run on the final head and reported in theos-dev-reportcomment on #34466.Full dogfood battery (978472f)
pnpm --workspace-concurrency=2 --filter '@objectstack/dogfood^...' buildunderos-verify-lock.sh:VERDICT command-exit 0.bash scripts/pm/os-verify-lock.sh -c "pnpm --filter @objectstack/dogfood test"(no shard, no path):Test Files 478 passed | 3 skipped (481),Tests 4054 passed | 68 skipped (4122),VERDICT command-exit 0. No failure.Local runs (978472f)
pnpm --filter @objectstack/objectql test:Test Files 605 passed (605),Tests 13569 passed (13569).pnpm --filter @objectstack/objectql run typecheck: exit 0 (check:test-typecheckOK, ledger held).summary-rollup.test.ts+summary-batch-accumulation.test.ts:Tests 86 passed (86).node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack: 97 families, each run with its exit recorded; four first exited 3 (prerequisite not met: the teardown fixture commit,check:skill-examples,check:dual-build-cjs-loads, andcheck:type-check-debtqueued behind the battery) and were re-run aftergit fetchof the fixture and a fullpnpm build --concurrency=2(119/119 tasks): all exit 0.--ran:97 derived famil(ies) accounted for — 97 run, 0 NOT-MEASURED.pnpm lintand the rest of the farm: CI.Human Minimum
packages/specholds no runtime logic. (packages/specnot touched)pnpm lintis CI's run (not run locally).main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed. (not touched)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01ADHkmPgdzD1Rp6LuxSPNpk