Skip to content

feat(objectql,service-analytics): refuse a raw aggregate over a record-mode quantity unless grouped by its unit field - #36060

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-dr6px1
Nov 21, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-dr6px1

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

repo:objectstack#7 · os-tesla · session_01L9qibvMi1U7R2kBd3JbTPu

Fixes #35491

A total over a quantity whose unit is stored per row (unitConfig: { unitMode: 'record', unitField }) is now refused unless it groups by that unit field. Before, 10 KGM plus 10 LBR answered 20 in the engine aggregate, a dataset or cube measure, and a summary roll-up. This is ADR-0158 U7 R1, built as a one-for-one mirror of the ADR-0144 D6 record-currency doors.

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:按单位逐行记录的数量(如一行 10 千克、一行 10 磅),在报表、数据集和汇总字段里不按单位分组直接求和、求平均、取最大最小时,会得到明确的拒绝提示,而不是一个错误的总数;按单位分组后照常出数。
  • 为什么做:属于“计量单位”第一期,直接相加不同单位的数量会得出看似合理却错误的数字,这里与多币种的同类保护保持一致。
  • 出错会怎样:目前还没有任何应用或示例使用这种按行记录单位的数量,影响面为零;如有问题,撤回这次合并即可恢复原样。
  • 要你做什么:无。

What changes

  • ObjectQL aggregate door (packages/objectql/src/record-unit-aggregate-door.ts, wired in ObjectQL.aggregate right after the record-currency door): sum / avg / min / max over a record-mode quantity answers INVALID_FIELD / 400 before any driver is asked, unless groupBy includes the quantity's unitField. The message names the quantity, its unit field and the grouping to add; the thrown error carries field, fields, object, param: 'aggregations' and unitField (in process only: the /data REST body keeps field and object and drops unitField, measured below).
  • summary registration (recordUnitSummaryRefusal, in SchemaRegistry.registerObject beside recordCurrencySummaryRefusal): a roll-up of sum / avg / min / max over such a child quantity answers INVALID_METADATA / 422 (RecordUnitSummaryRefusedError), judged at whichever registration completes the pair. Per ADR-0158 L3 every such roll-up is refused in R1 (no master_detail following), so the roll-up recompute gets no bypass channel: the currency door needs ROLLUP_AGGREGATE_OPTION only for its admitted roll-up, and units admit none.
  • Analytics cube measure door (packages/services/service-analytics/src/cube-record-unit-door.ts, asked right after the record-currency door at all four places that ask it: the inferred, augmented and declared ensureCube paths and the draft-preview branch of queryDataset): INVALID_FIELD / 400, the thrown error carrying member, param: 'measures', field, object and unitField (in process only: the analytics REST body is code and message), unless a dimension's column is the unit field on the same object. The plugin's sourceFieldMeta relays unitField only for a number under unitMode: 'record'. The dimension resolver both doors share moved into one private method (groupedColumnOf), with no change to what it answers.
  • The widening. AnalyticsServiceConfig.sourceFieldMeta may answer one more optional key, unitField: a number field's unitConfig.unitField, under unitMode: 'record' only. AnalyticsServicePlugin relays it for a number under unitMode: 'record' and for nothing else. A host that does not answer it gets no record-unit judgment from the cube door. The precedent is a35fc66, homeAmountField on the same answer. The errors' unitField member is not part of the widening: no REST envelope carries it.
  • Two ADR anchors (new files only) and a patch changeset for @objectstack/objectql and @objectstack/service-analytics.

The raw-aggregate set, as built (ADR-0158 Open item 12, the aggregate half; carried to the ADR text by the weekly ADR revisions card #36086, whose row lands after this PR merges): sum, avg, min and max are raw. count reads no quantity and count_distinct adds nothing, so neither is judged. Grouping by the quantity's own unitField admits the aggregate. A fixed-mode quantity and a number field with no unitConfig pass unchanged. No new error code: INVALID_FIELD and INVALID_METADATA, as ADR-0144 assigned for currency.

Why

ADR-0158 U7 R1: "a build-time refusal of a raw aggregate over a record-mode quantity unless it groups by that quantity's unit field (mirrors ADR-0144 D6)". L3: "In R1, a summary over record-mode child quantities is therefore always refused, as every such currency roll-up was before ADR-0144's D6 amendment".

Tests

Read first (by risk):

  1. packages/objectql/src/engine-delete-and-aggregate.ts: the one new call, after the record-currency door.
  2. packages/objectql/src/registry-object-registration.ts: the summary refusal beside the currency one.
  3. packages/services/service-analytics/src/analytics-service.ts: the four call sites and the extracted groupedColumnOf.

Two-minute check: pnpm --filter @objectstack/objectql exec vitest run src/record-unit-aggregate-door.test.ts shows 8 passed; pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/record-unit-analytics.test.ts shows 23 passed.

  • packages/objectql/src/record-unit-aggregate-door.test.ts (8): ungrouped sum/avg/min/max refused with code, status, field, unit field and the remedy inside the first 500 characters; grouped by another field refused; grouped by the unit field answers KGM [15, 7.5, 5, 10], LBR [10, 10, 10, 10]; count 3, count_distinct 2, fixed-unit sum 11 and max 6, plain sum 6 and avg 2; the summary refused at both registration orders and over itself, naming roll-up, quantity and unit field; count over the quantity, sum over the fixed quantity and the plain number register in both orders and roll up 2, 9 and 5.
  • packages/services/service-analytics/src/__tests__/record-unit-analytics.test.ts (23, SqlDriver over better-sqlite3, both strategies): grouped values per unit; a totals grouping keeping the unit; refusals (another dimension only, each raw aggregate ungrouped, a grand total) with no read of the object; count, count_distinct, fixed-unit and plain measures served ungrouped with values; the cube face; the inferred cube refused and then served grouped; the draft preview refused and served grouped.
Before and after, measured on a real engine (ObjectQL over SqlDriver / better-sqlite3)

The four wiring files restored to origin/main for the before run; the probe is a throwaway file, not committed.

Probe Before After
aggregate sum(qty), rows 10 KGM and 10 LBR 20 INVALID_FIELD / 400
avg / min / max 10 / 10 / 10 INVALID_FIELD / 400 each
count(qty) 2 2
sum(qty) grouped by unit_code KGM 10, LBR 10 KGM 10, LBR 10
summary sum over child rows 10 KGM, 10 LBR registered, stored 20 INVALID_METADATA / 422 at registration
dataset total ungrouped 20 INVALID_FIELD / 400
dataset total by unit KGM 10, LBR 10 KGM 10, LBR 10
inferred cube qty_sum 20 INVALID_FIELD / 400
Ablation, one per door (committed first; scripts/ablation-replace.mjs; restore proven by blob equality)

The suites resolve @objectstack/objectql and the service to src (the service-analytics vitest alias), so no dist rebuild sits between mutation and run.

  • Aggregate door: delete the assertRecordUnitAggregatesGrouped(...) call in engine-delete-and-aggregate.ts: 2 failed / 6 passed (the two refusal pins); restored, blob 691b2595e09a == HEAD.
  • Summary door: delete if (recordUnitSummary) return { refusal: recordUnitSummary };: 3 failed / 5 passed (both orders and the self roll-up); restored, blob fa4c14cb923c == HEAD.
  • Cube door: make the unit arm skip every measure (if (unitField === undefined || unitField !== undefined) continue;): 17 failed / 6 passed (every refusal pin on both strategies, the cube face, the inferred cube and the draft preview); restored, blob dad0d024e94b == HEAD.

Acceptance notes

  • Dataset compile, mirrored as currency does it. Currency's DATASET_INVALID compile guards (measure-currency-coherence.ts) judge a measure's currency key and derived measures across currencies; a dataset that declares an ungrouped sum over a record-mode amount compiles, and the refusal rides each query selection through the cube door. Units mirror that: a dataset measure over a record-mode quantity compiles, and every selection that does not group by the unit field is refused INVALID_FIELD. A dataset measure has no unit key, so guard 1 has no unit twin. A derived measure combining a record-mode quantity with another quantity is not a raw aggregate and is not judged here (no ruling covers it).
  • Two-segment unitField. The object door refuses a dotted unitField, so no quantity follows a parent's unit and this door has no path arm (the currency door's MASTER_DETAIL.CODE arm has no twin).
  • Repo-wide sweep. No pin asserted a raw total over a record-mode quantity (grep of unitMode: 'record' repo-wide: no aggregate, summary or dataset measure over one outside this PR's own tests). No examples/**, packages/**/fixtures or packages/**/__fixtures__ file declares unitConfig, so no example build is broken by the refusal.
  • Declaration basis. unitConfig is not in any released CHANGELOG (packages/spec/CHANGELOG.md and packages/objectql/CHANGELOG.md at 18.6.0 carry no unitConfig; its changeset 35489-unit-config.md is pending), so the refusal narrows nothing published: Metadata-protocol: none. The one published-surface change is the optional sourceFieldMeta key above, so Clause-②: yes (widening).
  • unitField on the wire, measured. A throwaway probe in packages/rest (not committed) threw each door's real error into the real REST writers. /data (mapDataError): 400, body keys error, code, field, object; the INVALID_FIELD arm copies field and object only (packages/types/src/data-error-classification.ts lines 1308 and 1309). POST /analytics/dataset/query: 400, body keys code, message; the declared-4xx arm writes code, message and an optional userMessage only (packages/rest/src/analytics-routes.ts line 926). The same holds for the currency twin's member, field and object on the analytics door.
  • UI whole-set summary over a record-mode quantity: ui(grid): the whole-set footer and group aggregations send a raw sum over a record-mode quantity the engine now refuses (unit twin of #32334) #36082
  • Dataset compile guard (both families) and derived-measure twin: service-analytics: refuse at dataset compile a raw measure over a record-mode amount or quantity with no code/unit dimension, and the derived-measure unit twin (ADR-0144 "at build") #36083
  • ADR-0158 amendment with the raw-aggregate set (the card's last Done-when clause): row on ADR revisions, week of 2026-11-21: rolling checklist of ADR text out of step with main (one governed PR) #36086, prerequisite this PR merged.

Verification

Suites, typecheck and gate readings at head f01bd3db4e, on origin/main 8145424b53. Head 948f998319 adds a changeset-only commit (the widening declaration), re-checked below. Changed lines: 1043 (+1032 / -11, 11 files), measured by dispatch-gates.

Suites and typecheck
  • pnpm --filter @objectstack/objectql test: Test Files 625 passed (625), Tests 14223 passed (14223); exit 0.
  • pnpm --filter @objectstack/service-analytics test: Test Files 222 passed (222), Tests 5674 passed, 345 skipped (6019); exit 0.
  • pnpm --filter @objectstack/objectql run typecheck (tsc plus check:test-typecheck, OK, debt unchanged) and pnpm --filter @objectstack/service-analytics run typecheck: lock VERDICT command-exit 0. Both new test files are in the compiled program (--listFiles).
  • eslint over the eight changed source and test files: exit 0 (the repo-wide pnpm lint is CI's).
Derived gate families
  • node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack: 84 families, each run with its exit captured before any pipe. 83 exit 0 on the first pass; check:dual-build-cjs-loads exited 3 (PREREQUISITE NOT MET, no workspace dist). After turbo run build --filter='./packages/**' (81/81 tasks), its re-run exits 0: 124 entry points across 72 packages load.
  • --ran reconciliation over the re-run record: "84 derived, 84 run, 0 NOT-MEASURED, 0 UNRUN".
  • At 948f998319: node scripts/check-changeset-no-major.mjs --base origin/main --event (this body as the payload): exit 0, "clause-② yes (widening) and metadata-protocol none … a non-protocol change at patch"; check-empty-changeset and check-adr-0087-registration exit 0.
  • pnpm check:adr-anchors: exit 0 with the two new anchors.

CI carries the full farm, test:repo (Test Core) and the dogfood battery (no ! in the title and no (narrowing) arm, so no local full dogfood run is owed).

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic.
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes (CI).
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec not touched.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L9qibvMi1U7R2kBd3JbTPu

…d-mode quantity unless grouped by its unit field

ADR-0158 U7 R1, mirroring ADR-0144 D6: the ObjectQL aggregate door
(INVALID_FIELD / 400), summary registration (INVALID_METADATA / 422,
always refused in R1 per L3) and the analytics cube door (INVALID_FIELD /
400). sum, avg, min and max are raw; count and count_distinct are not
judged; a fixed-mode quantity and a plain number pass.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibvMi1U7R2kBd3JbTPu
@github-actions github-actions Bot added size/xl 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 Nov 21, 2026
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/objectql, @objectstack/service-analytics, touching 28 documentable anchor(s).

26 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 035a12cc248fe38610f2cb1e37d4aaeacae568c8.

⛔ 9 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: objectName (symbol, 59 pages)
  • 7 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 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 — 27 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 035a12cc248fe38610f2cb1e37d4aaeacae568c8 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 615f989f307ff96f1315ec58a318b22563da8b69 — the merge of head 948f9983194a829ab2c7f35d11a4fed941908431 into base 035a12cc248fe38610f2cb1e37d4aaeacae568c8, 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 615f989f307ff96f1315ec58a318b22563da8b69 && git checkout 615f989f307ff96f1315ec58a318b22563da8b69
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 035a12cc248fe38610f2cb1e37d4aaeacae568c8 948f9983194a829ab2c7f35d11a4fed941908431 && git checkout -B drift-repro 035a12cc248fe38610f2cb1e37d4aaeacae568c8 && git merge --no-ff 948f9983194a829ab2c7f35d11a4fed941908431

node scripts/docs-audit/affected-docs.mjs --json 035a12cc248fe38610f2cb1e37d4aaeacae568c8

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

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 035a12cc248fe38610f2cb1e37d4aaeacae568c8 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwRAQZtb2syxNdJ6zT

L1 · PR #36060 · head f01bd3db4e8ba25f7bc4e7b011a5e706bce7d4da · REWORK (declaration and filing only, no code change asked) · 2026-11-21T12:38Z

Card #35491 (p2, area d7-D). Requested by the area thread with this head as the final green head. Claim: 7061790933. Dev report: 7062353045. I read the full diff: 11 files, +1032/−11.

Face

  • l1-face.mjs --pr 36060 is CLEAN at f01bd3db4e: open draft on main, first line Fixes #35491, no closing keyword on another card, one changeset for @objectstack/objectql and @objectstack/service-analytics (patch), Lint & Repo Gates and TypeScript Type Check success, all check-runs 38 success / 0 failed / 0 pending, mergeable clean.
  • Files stay inside the claim's surface.

The code: sound, a faithful mirror

  • record-unit-aggregate-door.ts (ObjectQL).
    • It judges sum/avg/min/max (ADR-0144 Open item 10's set) over a number with unitConfig.unitMode: 'record'. groupBy admits the unit field as a name or as { field }. It throws INVALID_FIELD/400 before any driver is asked.
    • It sits after the currency door in DeleteAndAggregateFacet.
    • No roll-up channel is needed: L3 admits no roll-up over such a quantity.
  • recordUnitSummaryRefusal. It refuses INVALID_METADATA/422, whichever end registers second, a self roll-up included; count is admitted. The pins assert code and status (ADR-0112).
  • cube-record-unit-door.ts. It is line-for-line the currency door's judgment, minus the home-field remedy, which has no twin. It is wired at all four assertRecordCurrencyGrouped call sites: the draft preview at l.3244, the ad-hoc exit, the augmented cube and the declared cube.
  • groupedColumnOf. This is the currency door's dimension resolver moved verbatim into a shared private method; no currency behaviour moves.
  • Tests. Refusals are pinned per function, per strategy, for the cube face, the inferred cube, a totals grand total and the draft preview, each with a no-read check. Grouped answers are right per unit. count/count_distinct, a fixed-mode quantity and a plain number are served.
  • Evidence.
    • The dev's ablation per door turns 2, 3 and 17 tests red.
    • Package suites: objectql 14223, service-analytics 5674.
    • I did not re-run locally. The check-runs at this head (Test Core included) are the gate witness.

R1 (must fix): the declaration is Clause-②: yes (widening), not no

The claim's basis is that unitConfig has not shipped, so no published accept set narrows. That is true for the narrowing arm, but the diff also widens a published surface.

  • AnalyticsServiceConfig is a root type export of @objectstack/service-analytics (src/index.ts l.5). Its sourceFieldMeta answer gains one optional key, unitField, which AnalyticsServicePlugin now relays.
  • The exact precedent is a35fc66 in packages/services/service-analytics/CHANGELOG.md (l.415–423). It added homeAmountField to the same answer and declared Clause-②: yes (widening) / Metadata-protocol: none, with a The widening. bullet.
  • The thrown errors also gain a unitField property (both doors). Say whether that reaches the wire envelope; if it does, it is an answer member and belongs in the same bullet.
  • The test (execution-duties.md): does the card widen an accept set or the public surface. Yes.

Asked:

  • Clause-②: yes (widening) / Metadata-protocol: none in the PR body and in the changeset body. Patch stays right: a non-protocol widening ships patch (AGENTS.md Post-Task step 3).
  • A widening bullet in the changeset naming the key, and the error member if it reaches the wire.
  • A claim correction on Units of measure R1: refuse at build a raw total over a record-mode quantity unless it groups by the unit field #35491 carrying the line-initial Clause-②: yes. The Clause-② queue gate reads only the claim's line-initial key.
  • L2 follows. Clause-②: yes makes a contract review owed at TIER_DEFAULT (contract-review.md). L1-b runs it as an isolated subagent once the redeclared head is announced. A changeset-only fix moves the head on the prose face only.

R2 (must fix before ACCEPT): two out-of-scope findings need a filing-gate pass and a line in Acceptance notes

  1. The UI consumers of a whole-set aggregate (the unit twin of ui(grid): a column summary sum on a record-mode amount sends a raw aggregate the engine refuses, and the footer loses every whole-set total #32334).
    • Today useWholeSetSummary / compileWholeSetSummaryQuery (ui/packages/plugin-grid) send a column summary: 'sum' as one ungrouped aggregate over the whole filter.
    • recordCurrencyAggregates.ts (requiredCurrencyGrouping, honestGroupAggregations) and useColumnSummary skip only record-mode currency. No ui/** file reads unitConfig at all.
    • Once this refusal ships, a grid or list view summing a record-mode quantity column gets the whole query refused. Every other summarised column in that view then falls back to a page total under a whole-view label, and grouped views drop their group aggregates the same way. That is the ui(grid): a column summary sum on a record-mode amount sends a raw aggregate the engine refuses, and the footer loses every whole-set total #32334 defect, now on quantities. Read from code, not run.
    • The PR's repo-wide sweep grepped unitMode: 'record' declarations; it could not see these generic callers.
    • Landing: ui/packages/plugin-grid (domain:ui). It should land before unitConfig ships in a release, so both reach users together.
  2. Dataset build-time half and derived measures.
    • The card's Done-when says a dataset is "refused at build with a named code".
    • ADR-0144's dated note defines "at build" for a dataset measure as "at compile … DATASET_INVALID". That holds for both families, since ADR-0158 U7 R1 mirrors D6.
    • The PR mirrors what currency actually does on main: per selection, INVALID_FIELD at the cube door. That is the area's option A, and I accept it as a deviation for this PR: it is the built twin, every selection is judged, and nothing reads. It still leaves the ADR text and main apart for both families.
    • Protocol first (code to the ADR by default), so file one card for a DATASET_INVALID compile guard covering both families, plus the derived-measure twin of currency guard 2.
    • Note the asymmetry for whoever ranks it. Before unitConfig ships, the unit half is no narrowing. Once it ships, the unit half becomes a narrowing, as the currency half already is (ADR-0087 disposition).

The PR keeps Fixes #35491. The build-time dataset half moves to the card from item 2; the seat decides that routing. The remaining two Acceptance notes are fine as written: the two-segment unitField and the sweep.

Changeset sentences (read against the diff)

All five statements are true of the code: the before reading; the engine door with code, status and message contents; the summary at 422, whichever registers second, with count the remedy; analytics on every cube path, totals and the draft preview, with unitField relayed only under record on a number; and the not-judged list with no new error code. One sentence needs to change: the declaration line (R1). The widening bullet is to be added.

carrier

carrier: ADR-0158 Open item 12, the aggregate half resolved by this PR. After merge, the landing seat appends that line on the open "ADR revisions, week of …" card (execution-duties.md). It is not in this PR.

Next

Delta L1 on the redeclared head and the two filings (ids in the Acceptance notes), then the TIER_DEFAULT L2 from L1-b.

… in the changeset

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibvMi1U7R2kBd3JbTPu
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwRAQZtb2syxNdJ6zT

Delta L1 · PR #36060 · head 948f9983194a829ab2c7f35d11a4fed941908431 · ACCEPT · 2026-11-21T12:44Z

Previous verdict: REWORK 7062716121 @f01bd3db4e. The delta is one changeset-only commit (+3/−2). Code is unchanged from the head I read in full.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwRAQZtb2syxNdJ6zT

Contract-review-claim: session_01L9qibwRAQZtb2syxNdJ6zT · head 948f998 · 2026-11-21T12:44Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwRAQZtb2syxNdJ6zT

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 948f9983194a829ab2c7f35d11a4fed941908431
Local-runs: none

Rendered 2026-11-21T12:49Z by an isolated reviewer sub-agent at TIER_DEFAULT (brief in the next comment), adopted by the L1-b session.

Face: declaration (Clause-②: yes (widening), claim amendment 7062726625). The committed tree touches no packages/spec/src/** and no governed path (11 files: one changeset, two ADR anchors, four objectql and four service-analytics source and test files). Inputs read: card #35491 body and all five comments, PR #36060 body and file list, the net diff origin/main...pr/36060 (merge-base 8145424b53), and the head's check-runs. Author objectstack-fleet[bot], so no author note is owed.

① Derived judgments

  1. AnalyticsServiceConfig.sourceFieldMeta answer gains the optional key unitField?: string. AnalyticsServiceConfig is a root type export (export type { AnalyticsServiceConfig } in packages/services/service-analytics/src/index.ts; the package exports map has only .), and the key sits on a host-supplied callback's return type, so a host that omits it is unchanged: a published widening. Right, and it is the one published-surface change, as the PR body and changeset say.
  2. AnalyticsServicePlugin now relays unitField for a number under unitMode: 'record' with a non-empty string, and for nothing else (plugin.ts). Behaviour behind item 1, same shape as its homeAmountField relay. Right.
  3. ObjectQL.aggregate accept set: sum / avg / min / max over a number field with unitConfig.unitMode: 'record' is refused INVALID_FIELD / 400 unless groupBy (string or { field } entry) includes its unitField; asked right after the record-currency door, before any driver. This narrows only what a record-mode quantity accepts, and that declaration is unreleased: on origin/main 1c879568c4 packages/spec is 18.6.0, its CHANGELOG.md carries no unitConfig or unitMode, and .changeset/35489-unit-config.md is still pending. So no published accept set narrows. Right (no (narrowing) arm owed), on the condition the PR states: if a release ships unitConfig before this merges, the declaration must be redone as no (narrowing).
  4. SchemaRegistry registration accept set: a summary rolling up sum / avg / min / max of a record-mode child quantity is refused INVALID_METADATA / 422 (RecordUnitSummaryRefusedError), judged at whichever registration completes the pair, and over a self roll-up. Same unreleased basis as item 3, so Metadata-protocol: none holds. Right. It sits after the opts.bodyOnly return, exactly as its currency twin does.
  5. Analytics cube accept set: the same four aggregates over such a quantity are refused INVALID_FIELD / 400 unless a dimension's column is the unitField on the same object, at all four places that ask the currency door (inferred, augmented and declared ensureCube paths, the draft-preview branch). Same unreleased basis. Right. Stand-downs (no sourceFieldMeta, non-bare cube.sql, unresolvable member) are line for line the currency helper's.
  6. No new public symbol: recordUnitFieldOf, assertRecordUnitAggregatesGrouped, readsRecordUnitQuantity, RecordUnitSummaryRefusedError, RECORD_UNIT_SUMMARY_REFUSED_CODE and QUANTITY_AGGREGATES are not re-exported from objectql . or ./core (src/core.ts) or from service-analytics ., and judgeRegistrationDoors stays typed { refusal: Error }, so the new class is not reachable from an entry's type graph. Right.
  7. Wire: no new error code (INVALID_FIELD, INVALID_METADATA from the existing catalog). The thrown errors' unitField member is in process only; the PR's measured REST bodies (/data keeps field and object; analytics keeps code and message) show no envelope change. Right, not part of the widening.
  8. groupedColumnOf extraction in analytics-service.ts: the removed inline resolver and the new private method are textually identical; no accept-set change. Right.

② Semver level

.changeset/35491-unit-raw-aggregate.md: patch for @objectstack/objectql and @objectstack/service-analytics, the only two published packages the diff moves (scripts/adr-anchors/** publishes nothing). Both declaration lines are line-initial in the changeset body and in the PR body: Clause-②: yes (widening) and Metadata-protocol: none. AGENTS.md (Post-Task Checklist 3): a none kind takes patch, and a non-protocol widening ships patch. The level matches what the diff publishes; no skip-changeset. The Check Changeset check-runs on the head concluded success.

Clause-②: yes (widening) — right: item ① 1 is a widening of a root type export, and items ① 3 to 5 narrow only an unreleased declaration.

③ Boundary flags

  • open_questions 1 (dataset compile DATASET_INVALID for a raw measure with no unit-field dimension; card thread took A). Answered, accepted as a deviation, carried. The card's Done-when says a dataset is "refused at build", and ADR-0144's dated note puts a dataset measure's refusal "at compile" with DATASET_INVALID; this PR refuses per query selection (INVALID_FIELD), mirroring what main does for currency. The route is recorded on the card (7062776103) with the compile guard for both families moved to service-analytics: refuse at dataset compile a raw measure over a record-mode amount or quantity with no code/unit dimension, and the derived-measure unit twin (ADR-0144 "at build") #36083. Finding N1 below.
  • open_questions 2 (derived measure combining a record-mode quantity with another quantity; A). Answered: not a raw aggregate in U7 R1's words, no ruling covers it; carried by service-analytics: refuse at dataset compile a raw measure over a record-mode amount or quantity with no code/unit dimension, and the derived-measure unit twin (ADR-0144 "at build") #36083 per 7062776103. Accepted.
  • out_of_scope_findings 1 ("carrier: none · the ADR-0158 Open item 12 aggregate-half line goes to the weekly ADR revisions card after merge"). Escalated as finding S1 below.
  • out_of_scope_findings 2 (objectql pins of the two engine doors share one test file, as their currency twins do). Answered: test layout only, no contract effect.
  • Claim amendment 7062726625 (no to yes (widening)): the new value is the one item ① 1 derives; the narrowing basis still holds at origin/main 1c879568c4 (item ① 3).
  • mcp_calls: 0, api_writes: 0 by the dev, security_findings: none: nothing to answer.
  • SQL push-down (AGENTS.md, Prime Directive 5): no finding. Every door added is a pre-query metadata check over groupBy, aggregations, cube dimensions and registered schemas; no id is materialised and no join is done in app code. recordUnitSummaryRefusal's scan of registered objects reads metadata only, and only when the incoming body declares a record-mode quantity.
  • Check-runs on the head at 2026-11-21T12:47Z: pending, not green. 54 runs: 14 success, 18 skipped, 1 cancelled (one PR-body guards (claim · duplicate · Part-of · single-writer path) run; a second run of the same name concluded success), 21 in progress (Test Core 1/10 to 10/10, Build Core, the Type Check · and Lint · families, Live E2E UI). This PASS covers the contract alone and claims no green: landing still waits for every check to conclude green.

Findings:

Implemented-by: claude/issue-35491-unit-raw-aggregate
Reviewed-by: session_01L9qibwRAQZtb2syxNdJ6zT

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwRAQZtb2syxNdJ6zT

Brief handed to the isolated TIER_DEFAULT reviewer of the record above, posted 2026-11-21T12:49Z:

Contract review brief — PR #36060 @ 948f9983194a829ab2c7f35d11a4fed941908431 (card #35491)

You review at TIER_DEFAULT. Render ONE ## Contract review record on this head — its shape is
node scripts/pm/record-recognisers.mjs --template --face declaration — with a PASS or FAIL verdict, and post it as ONE comment
on the PR or its card.

Inputs — these and nothing else:
· card #35491: its body and EVERY comment (rulings and earlier records included)
· PR #36060: its body, its file list, and the net diff against main at 948f9983194a829ab2c7f35d11a4fed941908431
· the check-runs on 948f9983194a829ab2c7f35d11a4fed941908431: their conclusions ARE the gate verdicts
⛔ Not the dispatch order, ⛔ not the dispatching seat's own conclusions — this brief is adversarial by design.

⛔ READ-ONLY. No worktree, no checkout, no build, no test run, no gate re-run, no ablation: the check-runs
on the head already answered every derived gate family, and a local run costs more than it returns.
If ONE probe is unavoidable, the record's Local-runs: line says probe — REASON; otherwise none.
Scratch space is /tmp/claude-0/l1b/pr-36060/ alone; nothing there you did not write this round is read.

Judge, in the record's own sections:
① Derived judgments — every accept-set and public-surface change the diff implies, each named right or wrong.
② Semver level — the changeset (or skip-changeset) matches what the diff publishes, and the Clause-②: line.
③ Boundary flags — every dev flag and every open_questions entry answered, or escalated.
On every face, SQL push-down: a new id materialisation or in-app join where SQL could push down is a
finding unless a reason is given (AGENTS.md, Prime Directive 5: SQL first).
Sign Implemented-by: with the dev's branch and Reviewed-by: with your session id — the value is the FIRST
thing after each colon.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwRAQZtb2syxNdJ6zT

Delta record rendered 2026-11-21T12:52Z by the same isolated TIER_DEFAULT reviewer (brief 7062840212), adopted by the L1-b session.

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 948f9983194a829ab2c7f35d11a4fed941908431
Local-runs: none

① Derived judgments

No change since record 7062833476: the head is the same commit (gh api repos/objectstack-ai/objectstack/pulls/36060 reads 948f9983194a829ab2c7f35d11a4fed941908431), so the net diff and items 1 to 8 of that record stand. The only edit is to the PR body.

② Semver level

No change: .changeset/35491-unit-raw-aggregate.md still ships patch for @objectstack/objectql and @objectstack/service-analytics, and the PR body still carries line-initial Clause-②: yes (widening) and Metadata-protocol: none.

Clause-②: yes (widening) — right, as in record 7062833476.

③ Boundary flags

This is the delta read of S1 from record 7062833476. The head is unchanged; only the PR body was edited.

Implemented-by: claude/issue-35491-unit-raw-aggregate
Reviewed-by: session_01L9qibwRAQZtb2syxNdJ6zT

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibvMi1U7R2kBd3JbTPu

Landing #36060 at 948f9983194a829ab2c7f35d11a4fed941908431 · 2026-11-21T13:11Z

Probe Reading
CI at 948f998 pr-state.mjs --pr 36060: 40 success, 20 expected skip, 0 unexpected skip, 0 pending; mergeable_state clean (read twice). The one non-success is a PR-body guards run (job 136849407077) cancelled at 12:43Z by the body edit's re-trigger; the runs that replaced it (jobs 136849489575 and 136851439691) concluded success
check-governed-merges.mjs --pr 36060 (final list) NOT governed: 0 of 11 paths hit the register. 1,044 changed lines ≤ 3000, so an ordinary queue landing
landing-k.mjs --pr 36060 K = 4 < 15, no new locale pack under a label PR, no shared book moved under this PR's
Generated-artifact drift, re-measured now main since the merge base moves no merge=os-regen path, and the PR touches none, so no regen merge is owed
Declaration basis, re-read on origin/main now packages/spec/CHANGELOG.md carries no unitConfig; .changeset/35489-unit-config.md still pending, so the refusal narrows nothing published (Clause-②: yes (widening) for sourceFieldMeta's unitField alone)
Reviews L1 REWORK 7062716121 → delta ACCEPT 7062776145 · L2 at TIER_DEFAULT (declaration face) PASS 7062833476 (S1) → delta PASS 7062871169 (S1 closed) · claim 7061790933, amendment 7062726625 · route 7062776103

State change: ready for review, then auto-merge. Fixes #35491. Carried: #36082 (grid footer, area:ux, before unitConfig ships), #36083 (dataset compile guard for both families and the derived-measure twin), and the ADR-0158 Open item 12 aggregate-half row on #36086.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 21, 2026 13:11
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 21, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibvMi1U7R2kBd3JbTPu

Re-queue #36060 at 948f9983194a829ab2c7f35d11a4fed941908431, head unchanged · 2026-11-21T13:32Z

Dequeued 13:30Z (CI_FAILURE) by queue build run 44907697012, job 136856826164 Dogfood Regression Gate (2/3). Signature: test/wall-package-doors-refusal.dogfood.test.ts › "adopt-orphans: A adopting the environment's catalog orphans into another package is refused, and the orphan stays unbound" — Error: Test timed out in 5000ms (1 failed / 1300 passed in the shard). The same file has a queue-flake anchor, #32772 (closed 11-12).

  • First error is a timeout, not an assertion.
  • The test drives POST /packages and /packages/:id/adopt-orphans (ADR-0131 wall doors). This diff touches none of that: it adds refusals to ObjectQL.aggregate, summary registration over a record-mode quantity (only when a body declares unitConfig.unitMode: 'record', which no showcase object does), and the analytics cube door.
  • Re-run locally on this head (worktree at 948f998, dist built at the same code): vitest run test/wall-package-doors-refusal.dogfood.test.ts → Test Files 1 passed, Tests 23 passed, exit 0.

So it is not this PR's: re-queued once as is. If the same signature ejects it again, I stop and hand it on for diagnosis rather than re-queue.

@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⛔ merge queue 构建失败 — 先分诊,再决定要不要重排

队列构建 44907697012 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集),
所以失败的测试可能在本 PR 没碰过的包里 —— 那不是重排能修的。每次盲目重排都会让排在后面的所有 PR 重建一轮。

分类:failure —— 按下面的日志分诊。

失败的 job(日志抽取,best effort):

  • Dogfood Regression Gate (2/3) — 失败步骤: Boot example apps and exercise real user flows

    @objectstack/dogfood:test:  FAIL   isolated  test/wall-package-doors-refusal.dogfood.test.ts > [ADR-0131 D3 · #15204 W3] isolated: the /packages write doors refuse a tenant the operator's catalog item
      ↳ 失败原因: @objectstack/dogfood:test: Error: Test timed out in 5000ms.
    

↳ 失败原因 是判读的关键:超时(Test timed out in … / Hook timed out in …)多半是负载/时序,不是本 PR 的回归;
断言(AssertionError: …)才指向真实的行为改变。两者的 FAIL 行长得一模一样,只有这一行能区分。

⚠️ 断言这一侧有一类例外,判据是断言在测什么,不是它是不是 AssertionError。 断言的对象是产品行为(一个值、一个形状、一次拒收)⇒ 照上面读:真实的行为改变,去查,⛔ 不要重排掉;
断言的对象是这次实验自身的有效性前提(跑完的耗时、负载下的先后、任何只在时间预算内才成立的条件)⇒ 它跟超时是同一类,同样对负载敏感,重排一次是合法的判别手段。
识别是机械的:断言的消息或它比较的值本身点名了一段时长、一个时间戳、一个耗时计数。实测过的一对 —— AssertionError: SecurityPlugin.init() ran: expected false to be true 测的是产品行为(真回归);
AssertionError: this run took over a second, so second-precision stamps could have differed too: expected 1006 to be less than 1000 测的是实验前提:它守护的那条不变式当时是绿的,同一个 head 原样重排一次即成功。
穿着 AssertionError 外衣的时间测量,仍然是时间测量。(⛔ 这只改「怎么读一次红」,不改「哪些测试可以重排」——后者由别处管。)

跨 PR 相同签名(24h,按失败测试文件聚合):

  • test/wall-package-doors-refusal.dogfood.test.ts — 24h 窗口内只有本 PR 撞到过,暂不汇总(再有一个不同 PR 撞到就会自动开汇总 issue)。
  • ⚠️ 24h 评论账本没读完(超过 5 页仍未读到窗口尽头),所以上面的「不同 PR 数」是下界,不是全量。

历史信号:

  • 本 PR 过去 24h 无队列失败记录(首次)。
  • 过去 24h 队列共有 3 个失败构建(不含本次)。

分诊清单:

  1. 失败测试在本 PR 改动的包里 → 真回归,修 PR。
  2. 失败测试与本 PR 无关 → 看上面的「跨 PR 相同签名」;已有汇总 issue ⇒ flaky/环境问题实锤,去那张 issue 上谈,修好前重排只会再烧一轮全队列。
  3. 两者都不是 → 可能与同组 PR 语义冲突;等前面的 PR 落地或失败出队后再重排一次即可,不要连续重排。

Generated by Claude Code · merge-queue-triage workflow (#4859)

Merged via the queue into main with commit c59ee99 Nov 21, 2026
61 of 62 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-dr6px1 branch November 21, 2026 14:18
247257110 pushed a commit to 247257110/objectstack that referenced this pull request Nov 22, 2026
…keeps it in the recycle bin (objectstack-ai#36097)

repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7

Fixes objectstack-ai#35667

Clause-②: no
Metadata-protocol: none
Clause-② basis: no (the seat's reading, from L1 O1 7063276615). Under a
walled posture, a system-door delete of an org-less record is now
refused with `ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED`. That is not a
narrowed accept set. Every SQL store already refused that delete on the
bin's NOT NULL. The memory store accepted it only by writing a bin entry
no organization owns, which breaks the bin's own invariant (ADR-0148 D1,
ADR-0131 D1): no organization's listing or cascade reaches it. The fix
makes every store answer as D9 states, so it is a bug fix, not a
`(narrowing)`.

## 维护者速读

-
用户能看到什么变化:流程、钩子或管理工具以系统身份删除一条不归属任何组织的记录时,记录会进入回收站并可恢复,不再报数据库错误;多组织隔离模式下则明确拒绝并说明原因。
- 为什么做:回收站功能的修复,替以系统身份删除全局记录的流程和管理工具解决删除失败的问题。
- 出错会怎样:最坏情况是系统身份删除被拒绝而记录原样保留,不会丢数据;撤回本次改动即恢复原状。
- 要你做什么:无。

## What changes

A delete under `{ isSystem: true }` of a record that names no
organization (a record of a `tenancy: { enabled: false }` object) wrote
its recycle-bin entry with no organization. On SQL the delete failed
with `NOT NULL constraint failed: sys_recycle_bin.organization_id` and
the record stayed. On a store that enforces no NOT NULL, the delete
succeeded and left an entry that no organization owned.

The entry is a row of a tenant-column object (ADR-0148 D1). It now takes
the organization any system insert takes (ADR-0131 D9): the record's
own, else the context's, else the engine's one system-insert resolver.
Under `single` that resolver answers the Default Organization. Under a
wall it refuses with `ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED` before the
root row is removed.

Route B of the seat's routing call (claim amendment 7062354282, analysis
7062338699): `packages/objectql/src/engine.ts` gains no line and
`scripts/facade-delegation-registry.json` is untouched.

- `packages/objectql/src/engine-delete-and-aggregate.ts`: the delete
module already holds the engine and already reads a sibling facet's host
through it (`securityResolversHost.of(this.facade)`). It hands the
capture's `write()` a call to
`MiddlewareAndContextFacet.resolveSystemInsertOrganization` through
`middlewareAndContextHost.of(this.facade)`. That is the same body the
engine's insert calls, not a second spelling of it.
- `packages/objectql/src/recycle-bin/capture.ts`:
`write(resolveSystemInsertOrganization)` stamps the resolver's answer
when neither the record nor the context names an organization. A new
exported type `RecycleBinSystemInsertOrganization` states the contract
and why it arrives as an argument and not as a `RecycleBinCaptureHost`
member.
- Pins:
- `packages/runtime/src/recycle-bin-orgless-system-delete.test.ts`: a
real `ObjectQL` on a real `SqlDriver` (better-sqlite3), the bin as
platform-objects declares it, and the Default Organization.
- A top-level describe in
`packages/objectql/src/recycle-bin/capture.test.ts`, the shared capture
harness, for the store that enforces no NOT NULL.
- A `patch` changeset for `@objectstack/objectql`.

### Files to read first

1. `packages/objectql/src/recycle-bin/capture.ts`, the `write()` hunk:
the order is record, then context, then resolver, and a refusal throws
before `driver.create`.
2. `packages/objectql/src/engine-delete-and-aggregate.ts`, the
`bin?.write(...)` call: the cross-facet host read.
3. `packages/objectql/src/recycle-bin/capture.test.ts`, the `makeEngine`
Default Organization seed: fixture triage, see Acceptance notes.

### Two-minute check

Run `pnpm --filter @objectstack/runtime exec vitest run --project local
src/recycle-bin-orgless-system-delete.test.ts` after building objectql.
Expect 3 passed: under `single` the entry's `organization_id` is
`org_default` and restore brings the record back; a context-named
organization is kept; under `isolated` the delete is refused with
`ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED` and the record stays.

## Tests

All readings are on head 4bd70f0 unless noted.

<details><summary>Measurement before the fix (main 8145424, scratch
test, not committed)</summary>

- sqlite: the system-door delete threw `SQLITE_CONSTRAINT_NOTNULL`, `NOT
NULL constraint failed: sys_recycle_bin.organization_id`, and no entry
was written. A beforeDelete hook saw session `{ isSystem: true }` and no
`tenantId`.
- memory store: the delete answered `true`, and the bin held `{
object_name: mz_global, organization_id: null }`.
- Control on sqlite: a tenant-column record written by a system insert
was stamped `org_default` (D9), and its delete kept the entry under
`org_default`.

</details>

<details><summary>Gate before building (route B premises)</summary>

- `pnpm check:facade-delegation-only` exited 0 and printed
`packages/objectql/src/engine.ts: 6857 lines, ceiling 6857 (0 left;
ruling 7051956587)`. `wc -l packages/objectql/src/engine.ts` reads 6857.
- `pnpm --filter @objectstack/objectql typecheck` (`tsc --noEmit && pnpm
check:test-typecheck`) passed under lock VERDICT command-exit 0 with the
cross-facet call in place.

</details>

<details><summary>Pins, ablation and package suites</summary>

- Runtime pin (sqlite): Tests 3 passed (3).
- Capture harness: Tests 30 passed (30). The `src/recycle-bin/`
directory: Test Files 5 passed, Tests 178 passed.
- Ablation on head 4bd70f0:
- The mutation went through `scripts/ablation-replace.mjs`, replacing
the resolver call with `const derived: string | undefined = undefined;`.
Anchor count went 1 to 0, and the blob went d124655 to
79309b11f005.
- objectql was rebuilt, and `ablation-dist-preflight --absent` confirmed
the marker was absent from all 14 built files.
- Results with the mutation: the runtime pin had 2 failed and 1 passed
(the context control). The capture harness had 2 failed and 28 passed.
- Restore: `git checkout HEAD --`, then `git diff HEAD` was 0 bytes and
the hash matched d124655. objectql was rebuilt, the preflight found
the marker present in 2 built files, and the tree was clean.
- After the restore the runtime pin had 3 passed and the capture harness
30 passed.
- `pnpm --filter @objectstack/objectql test`: Test Files 624 passed
(624), Tests 14217 passed (14217). `pnpm --filter @objectstack/objectql
typecheck` passed. Lock VERDICT command-exit 0.
- Consumers that compose the bin and delete without a booted auth (`mcp`
stdio-data-bridge.recycle-bin, `cloud-connection`
connection-credential-ledger, `metadata-protocol` seed-tenancy-backfill,
`runtime` sandbox body-runner): 5, 11, 58 and 42 tests passed. Lock
VERDICT command-exit 0.
- Not run locally, left to CI: `pnpm --filter @objectstack/runtime
typecheck`, which needs the runtime dependency closure built, and
`test:repo`.

</details>

## Verification

<details><summary>Gate families</summary>

`node scripts/pm/dispatch-gates.mjs --commands` derived 66 families on
4bd70f0, and all 66 exited 0. `--ran` reconciliation: 66 derived, 66
run, 0 NOT-MEASURED, 0 UNRUN.

On the earlier head e95ae7d, `check:driver-memory-census` was red
because the first runtime pin imported `@objectstack/driver-memory`.
Head 4bd70f0 moved that leg into the capture harness, and the census
is green there.

`overlap-check` returned a clean verdict before each push: origin/main
merges cleanly, and so does objectstack-ai#36060, which shares
`engine-delete-and-aggregate.ts`.

</details>

## Acceptance notes

- **Deviation from the dispatch: the memory leg is not on
`@objectstack/driver-memory`.** A new test consumer of that driver is a
ruled disposition. `check:driver-memory-census` printed: "LEDGERED: …
binds @objectstack/driver-memory (import) and the ledger does not cover
it … Rule it, migrate it, or file it". So the store that enforces no NOT
NULL is pinned in the capture harness, which keeps rows the way
`driver-memory` does. That harness is the shared harness file for this
component.
- **Fixture triage (adds a missing declaration).** The capture harness
registered `sys_organization` but held no organization. Under `single`
that is the broken boot invariant D9 refuses. Ten existing capture tests
deleted org-less records with org-less contexts there and went red on
`ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED`. The harness now seeds the
Default Organization. The one test whose deletes all name their
organization (the organization-delete cascade) opts out, so it still
counts only its own two organizations.
- **Walled posture.** A system-door delete with no `tenantId` of a
tenancy-disabled record is refused with
`ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED` (500) and the record stays. The
seat accepted this as D9 as written. A caller that needs it threads
`tenantId` on the context.
- **MongoDB.** `MongoDBDriver` does not stamp the tenant column on
insert, by its own docblock
(`packages/drivers/driver-mongodb/src/mongodb-driver.ts`, the
single-tenant note). A tenant-column row it writes therefore carries no
`organization_id`. No test here reproduces that; this is a code read
only, and on the seat's word it is noted here and not filed. The capture
change covers the system-door delete of such a row under `single`.

---

_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7)_

<!-- signed: repo:objectstack#7 · os-tesla ·
session_01L9qibwJEh7hMPPvagWM1g7 -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…of 2026-11-21) (objectstack-ai#37045)

<!-- claude-projects-attribution: {"github_login":"huangyiirene"} -->
_Requested by **Irene** · [project
thread](https://claude.ai/code/project/chan_01TJXtQ1tVD26ecLDZxFS67x?thread=cmsg_01TJXtQ1tVD26ecLDZxFS67x8Be2AAcUBhodBsvnWLd3Xs)_

Fixes objectstack-ai#36086

Clause-②: no
Metadata-protocol: none

## 维护者速读
-
用户能看到什么变化:用户无感;十二份内部设计记录在与现行代码不一致的地方各加一条注明日期的补注,原决定文字不动,只有访客模型里一句已被裁决撤回的接口说明照裁决改掉。
- 为什么做:这是本周的设计记录修订合集;AI 席位改代码前会读这些记录,这十五处已与上线代码不一致,会把 AI 带偏。
- 出错会怎样:只改说明文字,不动代码和功能;补注若写错,读记录的 AI 和人会拿到错误说明,整个合并可以直接撤回。
- 要你做什么:审阅后批准一次(设计记录必须由你亲手批)。

## What changes

Seventeen append-only dated notes, for the 15 rows of this week's card
whose code is on `main`, in twelve records. Each note sits directly
under the passage it amends, says what `main` does now, and links its
card and its landing PR. One clause is rewritten, in ADR-0138, as its
row and the ruling on it ask. No other decision text is rewritten,
struck or reordered. Six records whose header indexes their amendments
gain a pointer entry there (ADR-0050, 0066, 0090, 0138, 0151, 0158).

| # | ADR · section | What it said | What `main` does | Landing PR |
Note location |
|:--|:--|:--|:--|:--|:--|
| 1 | ADR-0158 · Open item 12 | Which aggregates count as "raw" is left
to the aggregate card | `sum`, `avg`, `min` and `max` over a
`record`-mode quantity are refused unless the query groups by the
quantity's own `unitField`: ObjectQL aggregate `INVALID_FIELD` / 400,
`summary` field `INVALID_METADATA` / 422, cube measure `INVALID_FIELD` /
400 on each query. `count`, `count_distinct`, a `fixed`-mode quantity
and a plain number are not judged. No error code is added | objectstack-ai#36060 |
under Open item 12; status entry |
| 2 | ADR-0066 · D2 ⑧ | View All and Modify All are the bits that vote
on every field of an object | A set may carry `viewAllFields`: a read
vote, never an edit vote, on every field of the object. The set's own
`readable: false` row beats it. It grants no object access, no record
and no admin posture | objectstack-ai#36085 | under D2 ⑧, after the 2026-11-15 note;
status entry |
| 3 | ADR-0090 · D5 | The high-privilege list refused on an `everyone`
binding | The list gains `viewAllFields` on any object entry | objectstack-ai#36085 |
under D5; status entry |
| 4 | ADR-0090 · D12, condition (a) | No `viewAllRecords` or
`modifyAllRecords` on `'*'` | Condition (a) also refuses `viewAllFields`
on `'*'`; the bit on a named object stays inside the boundary | objectstack-ai#36085 |
under D12's 2026-10-17 amendment |
| 5 | ADR-0151 · D3 | The bits the agent ceiling removes | The clamp
also clears `viewAllFields` on every object entry; assigning a set that
carries it to an account is refused by name | objectstack-ai#36085 | under D3; header
entry |
| 6 | ADR-0050 · Decision 2, the 2026-10-20 note | "a per-list open
mode, if ever wanted, is the list's existing `navigation.mode`" | On an
object's list `navigation.mode` is deprecated and no longer picks how a
record opens: the name opens the full page, the hover icon the side
panel. `none` still means the rows open nothing. A page block still
honours every value | objectstack-ai#35910 | under Decision 2, after the 2026-10-20
note; status entry |
| 7 | ADR-0050 · the same note | The create form is chosen by convention
from the object's form views | The console's record create and edit
forms are the object's own, laid out by `fieldGroups`, less a
`showOnCreate: false` field on a create. An internal form view steers
nothing there. A public form and a named form an action opens keep their
own definition | objectstack-ai#36543 | second note under Decision 2 |
| 8 | ADR-0052 · section 5b, tier 1 | "Opt-in (like Feed Tracking) keeps
the stream from becoming change-noise" | Old and new values show by
default. Off per object with `enable.fieldHistory: false`, per field
with `fieldHistory: false`. An entry serves a field's values only to a
reader who is served that field | objectstack-ai#36399, objectstack-ai#36580, objectstack-ai#36613, objectstack-ai#36641, objectstack-ai#36661
| under tier 1 |
| 9 | ADR-0146 · D1 | Studio is where metadata is edited | A workspace
administrator also edits in the running app: the menu and the pinned
header actions in design mode, a dashboard on its page, a report on its
builder page, a view's settings on the view. Each save is one item's
draft and publish, and writes nothing over a pending draft | objectstack-ai#36397,
objectstack-ai#36437, objectstack-ai#36629, objectstack-ai#36405, objectstack-ai#36644, objectstack-ai#36411, objectstack-ai#36848 | end of D1, after the
2026-11-24 amendment's table |
| 10 | ADR-0146 · D5 (two card rows) | The bridge draws on the app
switcher row and the app bar entry | From 768 px up the entries are two
rows of the app-name menu. "Design layout" turns on design mode. "Edit
app" opens Studio, and reads "View in Studio" for a read-only package.
The page header draws neither | objectstack-ai#36437, objectstack-ai#36621, objectstack-ai#36789 | under D5 |
| 11 | ADR-0146 · D10, the 2026-11-22 note | An extension places only
what it brings; the base's arrangement stays the base's | The App's
paired `.custom` package may declare whole `fieldGroups` and
`relatedLists`. Each key it writes replaces the folded result whole. Any
other package is refused and prescribed `place` | objectstack-ai#36517 | under D10,
after the 2026-11-22 note |
| 12 | ADR-0146 · D10, the same note | (the same) | `actionLayout` is
the third such key. Only the paired `.custom` package writes it on an
extension. Each arm it writes replaces the served arm whole. The server
refuses the shape; the reference is refused by design mode's Save and by
the CLI rule only | objectstack-ai#36629 | second note under D10 |
| 13 | ADR-0138 · D2, the 2026-11-20 amendment | The restriction profile
is served on the unscoped route "and its environment-scoped twin" | Only
the unscoped route is mounted. A request to the twin gets the host's
ordinary not-found answer. A server that mounts the scoped base alone
serves no profile | objectstack-ai#36531 | the clause is rewritten in place; a dated
amendment under it; status entry |
| 14 | ADR-0149 · D3, rules 4 and 5 | Both rules apply to an unknown
word beside a grouping word; the record did not say which governs | Rule
4 governs the unknown word: the labelled fallback, nothing asked. Rule 5
is the rule for a question that names no number. Beside a fallback the
note ends with one conditional sentence | objectstack-ai#36509 | under D3, after the
2026-11-19 note |
| 15 | ADR-0027 · roadmap row M2 | "explicit, batched publish" | In
Studio's designers a person's Save writes the draft and publishes that
one item at once. Drafts and the package's batch publish remain for an
AI's changes | objectstack-ai#36597, objectstack-ai#36634, objectstack-ai#36652 | under the roadmap table |
| 16 | ADR-0037 · the product-boundaries amendment | "Publish remains
the single commit gate shared by every surface" | The publish is the
item's own, issued by the Save itself. The top bar's Publish is drawn
only while a draft is pending | objectstack-ai#36597, objectstack-ai#36634, objectstack-ai#36652 | under that
sentence |
| 17 | ADR-0085 · section 2 | `relatedLists` is "the one place" where
the re-arrange rejection yields | `actionLayout` is the second: a ruled
exception (the maintainer's ruling on objectstack-ai#36635), on the object, with a
`list` arm and a `record` arm | objectstack-ai#36629, objectstack-ai#36815 | under section 2, after
the 2026-11-22 note; dated 2026-11-23 |

The 15 card rows are the 17 lines above: the `viewAllFields` row is
lines 2 to 5, and the two ADR-0146 D5 rows are line 10.

**Rows not carried**

- ADR-0085, the `fieldGroups[].collapse` row: already on `main` through
objectstack-ai#36817. The record carries "Addendum (2026-11-22): on the synthesized
record page the reader folds every titled group", which says what the
row asks for. Nothing is added.

No `scripts/adr-anchors/**` entry moves. No `**Status**:` line changes
in the part the index projects, so `docs/adr/README.md` stays current.

## Why

AI seats read the ADRs before they change code in governed territory
(AGENTS.md Prime Directive objectstack-ai#13). These passages say something `main` no
longer does, so a seat that trusts them is steered wrong. This is the
week's rolling ADR revisions card: its rows land together as one
governed `docs/adr/**` PR and one approval, on the maintainer's word of
2026-11-20 (「adr接受你的建议」).

## Tests

Docs-only diff: no package, test or build input is touched, so no
package test or typecheck applies, and nothing a test pins changes.

## Acceptance notes

- Every row was read against the code on `main` at `a73edb3cd`, not
against PR state. Each landing commit is an ancestor of the branch, and
each note names the file or symbol that makes it true. `main` has moved
once since (`9c57bd283`); that commit touches no `docs/adr/**` file and
no file a note names.
- Where a row's claim is not what `main` does, the note states what
`main` does:
- **ADR-0052.** The row gives the per-field switch as `trackHistory:
false`. On `main` it is `fieldHistory: false`; `trackHistory: false`
reads as unset.
- **ADR-0146 D1.** Three sentences of the row are not written. "The fate
of Studio's Interfaces pillar is still open": the 2026-11-24 amendment
of D1, already on `main`, retires the pillars. "Studio is not changed by
this batch": the same amendment changes it. "Each of these writes the
same paired package": a report's save and a change to an existing view's
settings name no package, and the menu, the action arrangement and a
dashboard go to the item's own package when it is writable. The note
says where each save lands. It does not repeat what that amendment
already says about dashboards and reports opening in the app.
- **ADR-0146 D5.** Both card rows describe a state objectstack-ai#36789 has since
replaced: the row of objectstack-ai#36437 has the page header's button enter design
mode, and the row of objectstack-ai#36621 has the app-name menu's "Edit app" enter it.
On `main` the entry into design mode is "Design layout", and "Edit app"
opens Studio. The two rows are written as one note that states the end
of that sequence.
- **ADR-0027.** The row says later PRs will move the other Studio
editors. They have landed (objectstack-ai#36634, objectstack-ai#36652) and the note cites them. It
quotes the maintainer's own sentence on the epic, not the epic's summary
line.
- **ADR-0037.** The row says a pending draft now means an AI's draft.
Studio's generic item page still saves a person's drafts (its move is
declared by D1's amendment and not built), and the note says so.
- **ADR-0085.** The row says the row menu is queued and not built.
objectstack-ai#36815 built it, and it follows the `record` arm; the note says so. The
`list` arm still has one reader.
- Header entries: added where a record's header indexes its amendments
(ADR-0050, 0066, 0090, 0138, 0151, 0158). Not added to ADR-0146: its
status block lists only the maintainer's in-place amendments, its
2026-11-22 note under D10 has no entry there, and open PR objectstack-ai#36957 edits
that block. Not added to ADR-0027, 0037, 0052, 0085 and 0149, whose
headers hold no such list.
- Dates: every note is dated 2026-11-24, except ADR-0085's, dated
2026-11-23 as its row sets (that record dates its notes by ruling).
ADR-0138's amendment is dated 2026-11-24 and names the ruling's date,
2026-11-22.
- ADR-0151 is `Proposed`; its note follows the form of the dated notes
it already carries.
- The spec docblock sentence the ADR-0085 row mentions landed with
objectstack-ai#36629, so nothing outside `docs/adr/**` is owed.
- Noted, not filed (read-only observations, nothing was run to exercise
them):
- A report's save, and a change to an existing view's settings, from the
running app name no package. For an item of an installed package whose
stored rows are not bound to exactly one package, the server then
addresses the package-unbound row, not the paired `.custom` package
ADR-0146 D2 points customizations to. Whether a door refuses that write
was not measured.
- Two source comments still say design mode is entered from "Edit app"
(the page-actions module header and the design-mode module's gate
paragraph). Comments only.
- Landing tier: Tier H (`docs/adr/**`, governed; the maintainer
approves). The diff is +243 / -5 over 12 files.

## Verification

Read first, by risk:

1.
`docs/adr/0138-guest-model-anonymous-principal-doors-grants-and-organization.md`,
the D2 hunk: the one place earlier text is rewritten.
2.
`docs/adr/0146-studio-designs-setup-administers-one-editor-per-item-paired-customize-package.md`,
the note at the end of D1: the widest claim, where each in-app save
lands.
3. `docs/adr/0066-unified-authorization-model.md`, the note under D2 ⑧,
with its ADR-0090 D12 twin: permission semantics.

Two-minute check: `pnpm check:adr-symbol-anchors` prints a green line
that starts `check-adr-symbol-anchors: 3904 anchors across 160 records`,
and `git diff origin/main...HEAD --stat` shows 12 files, 243 insertions
and 5 deletions.

<details><summary>Gate readings on e5c60bf</summary>

`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived the same 21 families on `8c705bc2c`
and on `e5c60bff0`. The readings below are the second run, on
`e5c60bff0`, each exit captured before any pipe:

```text
node scripts/check-adr-links.mjs :: exit 0
node scripts/check-adr-links.mjs --self-test :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0
pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0
pnpm check:adr-anchors :: exit 0
pnpm check:adr-index :: exit 0
pnpm check:adr-symbol-anchors :: exit 0
pnpm check:ci-filter-parity :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:doc-authoring :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:pm-governed-merges :: exit 0
pnpm check:pm-prior-rulings :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:watch-hint-literal :: exit 0
```

On the first run `check:doc-formula-expressions` answered 3,
prerequisite not met, until `formula` and `lint` were built under
`os-verify-lock` (VERDICT command-exit 0, 5 of 5 tasks). `--ran`
reconciliation: 21 derived, 21 run, 0 NOT-MEASURED (a derived zero).
`node scripts/adr-index.mjs --check`: exit 0, the README is current.
`check-commit-card-trailers --range origin/main..HEAD`: exit 0, 2 commit
messages. `overlap-check`: `origin/main` and objectstack-ai#36957 both merge cleanly,
VERDICT clean exit 0. `check-governed-merges --branch`: GOVERNED, 12 of
12 paths on the register, Tier H. Control-byte scan of the twelve files:
0 hits.

</details>

## Human Minimum

- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(No schema touched.)
- [x] 2. Every name I added uses the casing for its kind. (No name
added.)
- [ ] 3. No formatter ran; `pnpm lint` passes. (No formatter ran. `pnpm
lint` was not run locally on this Markdown-only diff; CI judges it.)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset. (Publishes
nothing: `skip-changeset`.)
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (Not touched.)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [ ] The *Before Submitting* list in CONTRIBUTING.md is done. (Not
walked item by item; the derived gates above are what ran.)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01J8VVAoUbebHyRXKT4GxBTV

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Units of measure R1: refuse at build a raw total over a record-mode quantity unless it groups by the unit field

2 participants