You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1617b7f
Browse filesBrowse the repository at this point in the historyBrowse files
fix(lint,metadata-protocol,rest,runtime): refuse a sum/avg roll-up the engine cannot recompute, and answer a landed child write's success (#28781)
domain:server#5 · os-project-manager · session_01FEkQ5oc56xChD6Wrc4cGSt
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X8dNy8r76WjFsVdvaSJbXXR)_Fixes#28661
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — `skills/objectstack-data/rules/relationships.md` and
`rules/field-types.md` teach `summaryOperations` only with `sum` over a
numeric `amount` and `count`; no file under `skills/**` teaches a
`sum`/`avg` over a text field, and every taught example stays admitted.
## 维护者速读
- 问题:已发布的汇总字段对文本子字段做 `sum`/`avg` 时,子记录每次增改删都答 500,但写入其实已落库;客户端重试 create
会产生重复记录。
- 前半:汇总规则从只在 `os lint` 里跑,搬进作者规则注册表(gating),`os validate`、`os build`、`os
lint` 和运行时保存/发布门都会拒绝;草稿的 `_diagnostics` 也报出来。
- 子对象不存在(`qsf_nope`)没有拒绝:全量 dogfood 测到 unmanaged install
会先写父对象、后写它汇总的子对象,拒绝会打断这种安装;按派单第 2 条放行,列为待决问题。
- 后半:写入已落库、只是父记录汇总重算失败时,REST 和运行时分发器的 POST/PATCH/DELETE
答写入本身的成功响应(201/200,与正常成功同一个 body,不加新字段、不加新错误码);汇总列过期这件事按字段只在日志里以 error
说一次。
- protocol 的 `createData`/`updateData`/`deleteData` 仍抛
`ERR_SUMMARY_RECOMPUTE`(带 `written`),导入和种子加载的契约不变;未改 `packages/spec/**`。
- 需要你看:子对象不存在要不要以别的方式处理(见 Acceptance notes);表单提交、批量写、clone、MCP 等其它写入门未在本
PR 处理。
## What changes
**Half 1 — the doors refuse a roll-up the engine refuses at every
recompute.**
- `packages/lint`: the roll-up rule (`lintSummaryRollups`,
`data-model-rules.ts`) leaves `lintDataModel` and becomes a gating entry
of the authoring-rule registry (`authoring-rules.ts`), on all three
commands and at the runtime object door (`runtimeTypes: ['object']`). It
judges:
- `sum`/`avg` over a child field outside the aggregate × field-type
table (`isAggregateCompatibleWithFieldType`, `@objectstack/spec`'s
`AGGREGATE_FIELD_TYPE_COMPATIBILITY` — the predicate the engine's
aggregate door already refuses with) → `rollup/non-numeric-aggregand` at
`objects.<parent>.fields.<field>.summaryOperations.field`, naming the
accepted child types and `count`;
- `min`/`max` (the arm `os lint` already reported, same message and fix)
— now also gating at `os validate` and `os build`;
- a `summaryOperations.object` naming no object the pass holds stays
SILENT at every door — see Acceptance notes for the measured reason.
- `os explain rollup/non-numeric-aggregand` now covers `sum`/`avg`.
- The draft read already folds the publish verdict into `_diagnostics`
(#26707), so a draft carrying such a roll-up now reads `valid: false`
with the same entry publish refuses with.
**Half 2 — a child write that landed answers its success.**
- `packages/metadata-protocol`: `createData`, `updateData` and
`deleteData` build the answer the write earned when the engine throws
`ERR_SUMMARY_RECOMPUTE` ("the triggering records WERE written"), attach
it to the refusal under a non-enumerable symbol, and rethrow — so every
existing caller (import runner, seed loader) reads the refusal exactly
as before. The carrier lives in `@objectstack/types`
(`summary-recompute-answer.ts`), the one package the protocol, `rest`
and `runtime` all depend on (`rest` has the protocol as a dev dependency
only).
- `packages/rest` (`crud-routes.ts`, `stale-summary-answer.ts`) and
`packages/runtime` (`domains/data.ts`): `POST`, `PATCH`, `DELETE
/data/:object[/:id]` answer that earned body with the write's own
success status (201/200), plus the dropped-fields header the success
path sets. No member, header or code is added; the body is the one the
same write answers when every roll-up recomputes.
- The stale summary column is logged at `error`, once per child object
and summary field, with the consequence and the fix (AGENTS.md
degradation-log rule); the engine's own `warn` per failure is unchanged.
**Gate fallout.** `check:engine-double-contract`'s by-id seam scan now
also reads a receipt returned through a same-function `const answer = {
… }` (the `const opts = { where: { id } }` reading it already makes,
applied to the answer), with an A/B self-test pair; its ledger learns
the new test file's engine double. Four docs transcripts move from 59 to
60 author-time rules (main's #28775 had already moved them from 58 to
59).
## Tests
All red on the merge base `2678600d` and green on the head.
- `packages/lint` — `data-model-rules.summary-rollup.test.ts`:
`sum`/`avg` over text refused with the exact message, path and fix;
table parity over every `FieldType` for both functions; `sum` over
`percent` refused, `avg` admitted; `sum` over a number admitted; a
missing child raises nothing; `lintDataModel` no longer reports it; `os
explain` facts. `runtime-gate.object-writes.test.ts`: the door refuses
`sum`/`avg` over text at
`objects.qsf_parent.fields.probe_sf.summaryOperations.field`, admits
`sum(amount)`, admits a parent whose child does not exist yet (with and
without a closure), refuses the CHILD write that turns a summed field
into text, does not charge a write for a stored parent already in
violation; roster pins list the rule.
`data-model-rules.fix-lines.test.ts`: one-line fix.
- `packages/metadata-protocol` —
`protocol.summary-rollup-publish-gate.test.ts` (9): active save 422
`INVALID_METADATA` for `sum` and `avg`; the draft saves, reads
`_diagnostics.valid: false` with `rollup/non-numeric-aggregand`, and
both `publishMetaItem` and `publishPackageDrafts` refuse; `sum(amount)`
admitted; missing child admitted by save and publish; a draft child in
the same package publish is judged with its parent (numeric admitted,
text refused). Base: 5 red / 4 green (the controls).
- `packages/rest` — `data-write-summary-recompute-refused.test.ts` (5,
real `SqlDriver` on better-sqlite3): POST 201 with the created record,
persisted once, `child_sum` 295 / `child_count` 3; PATCH 200,
`child_sum` 230; DELETE 200 `{object,id,success:true}`, `child_sum` 95 /
`child_count` 2; one `error` line naming `qsf_parent.probe_sf`; the
protocol's `createData` still throws `ERR_SUMMARY_RECOMPUTE` with
`written`. Base: POST/PATCH/DELETE answered 500.
- `packages/runtime` —
`domains/data-write-summary-recompute-refused.test.ts` (4): the
dispatcher's `/data` door answers the same 201/200 bodies, persists
once, recomputes the valid roll-ups, and logs once through the host
logger. Base: 4/4 red.
- Ablations (each mutation landed on disk, restored to the HEAD blob,
`git diff HEAD` empty): sum/avg arm off → lint 6 red; registry
`runtimeTypes` emptied → lint 4 red; earned-answer symbol detached (dist
rebuilt) → REST 4 red; REST POST relay disabled → REST 1 red; runtime
`data.ts` at base → runtime 4 red.
- Suites: `@objectstack/lint` 7730/7730, `@objectstack/rest` 7203 passed
(352 skipped), `@objectstack/runtime` 9194 passed (19 skipped),
`@objectstack/metadata-protocol` 21958 passed (26 skipped; 4 reds in two
ssl-redaction files from `main` were a stale post-merge dist and went
green after rebuilding `spec`), `@objectstack/types` 846/846.
- Full dogfood on the head `fe13d22d` (after merging `main` at
`5493b884`, closure rebuilt): Test Files 374 passed, 3 skipped (377);
Tests 3034 passed, 28 skipped (3062). On the same head:
`@objectstack/lint` 7775/7775, and the three new door files 9 / 5 / 4
passed.
## Acceptance notes
- **The narrowing is already denied by published text.**
`@objectstack/spec`'s `AGGREGATE_FIELD_TYPE_COMPATIBILITY` (the
aggregate × field-type table) does not admit `sum`/`avg` over `text`,
and the engine's aggregate door refuses the pair with its own message
("sums 'memo', a declared text field, which the engine does not sum") —
on a roll-up after the write committed, every time. The lint rule's
published message for `rollup/non-numeric-aggregand` already refused the
`min`/`max` arm on `os lint`. No roll-up the engine could recompute is
newly refused.
- **The missing-child half is admitted (open question).** The first full
dogfood on this branch refused it and turned 9 cases of
`install-local-unmanaged-mode.dogfood.test.ts` red: the unmanaged
install saves `crm_opportunity` (`line_total =
sum(crm_opportunity_line_item.amount)`) one active save before the child
exists. Per the order, the arm was removed and the case is left open; a
missing child keeps reading 0 / null, and nothing fails.
- **Census.** `examples/app-showcase` (24 objects, 9 roll-ups),
`examples/app-crm` (6, 1), `examples/app-todo` (1, 0) through the built
rule: 0 findings. `examples/app-multi-package` declares no summary
field. `hotcrm`'s one roll-up is `sum` over a `currency` field:
admitted.
- **Doors not changed.** Form submit (`form-routes.ts`), the batch and
`*ManyData` routes, `cloneData`, the MCP `create_record` bridge and
`callData`'s ObjectQL fallback (no protocol registered) still surface
`ERR_SUMMARY_RECOMPUTE` as before. Only the card's three data doors, on
both transports, answer the earned body.
- No `packages/spec/**` edit.
## Verification
Live probe on a stock showcase boot, card steps 2–4. Sign in as the
seeded admin, install a scratch package, author `qsf_parent` (`child_sum
= sum(amount)`, `child_count = count`) and `qsf_child` (`memo` text,
`amount` number, `parent` master_detail), publish, then seed P and two
children:
```
pnpm dev -- --fresh -p <port>
curl -X POST /api/v1/auth/sign-in/email -d '{"email":"admin@objectos.ai","password":"admin123"}'
curl -X POST /api/v1/packages -d '{"manifest":{"id":"app.qsf","name":"QSF","version":"0.1.0","type":"app","namespace":"qsf"},"enableOnInstall":true}'
curl -X PUT '/api/v1/meta/object/qsf_parent?mode=draft&package=app.qsf' -d '<parent + probe_sf = {object:qsf_child, function:sum, field:memo}>' # step 2
curl '/api/v1/meta/object/qsf_parent?state=draft&package=app.qsf' # _diagnostics
curl -X POST /api/v1/packages/app.qsf/publish-drafts -d '{}' # step 3
curl -X PATCH /api/v1/data/qsf_child/qsfc1 -d '{"amount":31}' # step 4
curl -X POST /api/v1/data/qsf_child -d '{"id":"qsfy1","name":"y1","amount":60,"parent":"qsfp1"}'
curl -X DELETE /api/v1/data/qsf_child/qsfy1
```
| | base (`lint`/`metadata-protocol`/`rest`/`runtime` at `2678600d`) |
head |
|---|---|---|
| step 2 `_diagnostics` | `{"valid":true}` | `valid:false`,
`rollup/non-numeric-aggregand` (sum and avg) |
| step 3 publish | `published` | `refused`,
`rollup/non-numeric-aggregand` at `…probe_sf.summaryOperations.field` |
| step 4 PATCH / POST / DELETE | 500 / 500 / 500 `INTERNAL_ERROR` (row
persisted, `child_sum` 91 → 151 → 91) | 200 / 201 / 200 (row persisted
once, `child_sum` 168 → 228 → 168), one `[REST]` error line for
`qsf_parent.probe_sf` |
| `probe_nope` (missing child) | published | published (admitted) |
Step 4 on head was taken on a boot with only `@objectstack/lint` at
base, because the head gate no longer lets the bad roll-up be stored.
Gates: `node scripts/pm/dispatch-gates.mjs --commands` derived 112
commands on the head `fe13d22d`; all 112 exit 0, and `--ran` reconciles
112 derived, 112 run, 0 NOT-MEASURED. Scoped `pnpm lint` over the 17
changed `.ts`/`.mjs` files: exit 0. `pnpm check:nul-bytes`: exit 0.
Typecheck (`tsc --noEmit`) of `lint`, `metadata-protocol`, `rest`,
`runtime` and `types`: exit 0 each.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5kV6ptpTnU6Hjb2mE4)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(lint,metadata-protocol,rest,runtime,types): a roll-up the engine refuses at every recompute is refused at save and publish, and a child write that landed answers its success (#28661)
10
+
11
+
Clause-②: no (narrowing)
12
+
Metadata-protocol: narrowed
13
+
Skills-docs: none — `skills/objectstack-data/rules/relationships.md` and `rules/field-types.md` teach `summaryOperations` only with `sum` over a numeric `amount` and `count`; no file under `skills/**` teaches a `sum`/`avg` over a text field, and every taught example stays admitted.
14
+
15
+
**BREAKING** (narrowing) for a `summary` field whose `sum` or `avg` names a child field the engine does not aggregate (and, on `os validate`, `os build` and the runtime object save/publish door, a `min` / `max` whose answer is not a number, which `os lint` already refused).
16
+
17
+
-**Before.** A published `summary` field with `sum` or `avg` over a child `text` field published as valid (`publish-drafts`, the draft's `_diagnostics: { valid: true }`, `os validate`, `os build`). Every later create, update and delete of a child then answered `500 INTERNAL_ERROR`, though the write had landed and the parent's valid roll-ups had recomputed: the recompute's aggregate refuses the pair after the commit. A client that retried a create made a duplicate.
18
+
-**Now, at the doors.** The roll-up rule moves from `os lint` alone into the authoring-rule registry (`lintSummaryRollups`, gating, on `os validate`, `os build`, `os lint` and the runtime object save/publish door). A `sum` or `avg` over a child field outside the aggregate × field-type table (`AGGREGATE_FIELD_TYPE_COMPATIBILITY`, the table the engine's aggregate door reads) is refused under `rollup/non-numeric-aggregand`, at `objects.<parent>.fields.<field>.summaryOperations.field`, with the accepted child types and `count` as the fix. The `min`/`max` arm `os lint` already reported keeps its message and now also gates `os validate`, `os build` and the runtime object save/publish door. A child staged as a draft in the same publish batch is judged with it. `os lint` no longer reports the rule a second time.
19
+
-**Now, after a write.** When a parent's roll-up cannot be recomputed after a child write — a roll-up stored before this gate, or any other recompute failure — `POST`, `PATCH` and `DELETE /api/v1/data/:object[/:id]` answer the write's own success (`201`/`200`, the same body the write answers when every roll-up recomputes), on both `RestServer` and the runtime dispatcher. The stale summary column is logged at `error`, with the fix, once per field per process (the memory is never cleared; a restart reports it again). The protocol's `createData`/`updateData`/`deleteData` still throw `ERR_SUMMARY_RECOMPUTE` carrying `written`, so the import runner and seed loader read it as before. The recogniser and the earned-answer carrier (`isSummaryRecomputeRefusal`, `earnedAnswerOf`, `staleSummaryAnswerLines`) are new exports of `@objectstack/types`, the one package the protocol, `rest` and `runtime` all depend on.
20
+
-**Not refused.** A `summaryOperations.object` naming no object (the card's `qsf_nope`) is still admitted: an unmanaged install (`install-local --unmanaged`) saves a package's parent before the child its roll-up reads, so a door refusing a missing child would refuse that install.
21
+
-**Who moves.** No `examples/**` or `hotcrm` roll-up is refused: every `sum`/`avg`/`min`/`max` there aggregates a `number` or `currency` child field.
22
+
23
+
<!-- adr-0087: not-required (no-migration-prescription) the diff registers no retirement and no key changes shape: a roll-up summing or averaging a non-numeric child field never answered a value, and the fix is an authoring choice (a numeric child field, or count) that no mechanical rewrite can make -->
0 commit comments