Skip to content

fix(lint, service-analytics): a total over a formula field names the stored-number remedy, not a count - #24505

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-24426-measure-total-hint-stored-number
Oct 19, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-24426-measure-total-hint-stored-number

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #24426
Clause-②: no

What changed

A dataset measure (or an authored cube measure) that takes sum / avg / min / max over a formula field is still refused. Only the prescription changed. It used to name a count as the way out:

Either point "sum" at a field of an accepted type, or aggregate "leave_days" with one its formula type accepts: count, count_distinct.

A count read as a total is the plausible wrong number from objectstack-ai/cloud#2861: "Total Leave Days" showed 3 records against a true total of 10 days. The hint now gives the spec's remedy first and names the count only as a different question:

The field is computed on read and stores no value: store the value as a number field (kept by a hook) and aggregate that. count / count_distinct answer a different question: how many records.

One source

  • Home: @objectstack/spec/data, in aggregate-field-type-compatibility.ts (the table module). It exports VIRTUAL_FIELD_AGGREGATE_REMEDY (the sentence) and virtualFieldAggregateRemedy(aggregate, fieldType). The function returns the sentence for a REFUSED sum/avg/min/max over a type in SEARCH_VIRTUAL_TYPES (today formula, the drivers' storage rule). It returns undefined for every other pair. Like the predicate, it fails closed on non-string input. The class is not a new list: it reuses SEARCH_VIRTUAL_TYPES, and a spec test holds every member refused on all four value-reading rows.
  • Why there and not beside the semantic migration entry (the claim's expected spot). Both consumers already import that module (isAggregateCompatibleWithFieldType, AGGREGATE_FIELD_TYPE_COMPATIBILITY). Its TSDoc is where the module says formula is refused because it is virtual. An extra export in a migrations/entries/semantic/*.ts file would sit inside the generated-registry tree, which holds SemanticMigration entries only. Dependency direction checked: @objectstack/lint and @objectstack/service-analytics both list @objectstack/spec as workspace:*. Spec imports neither of them.
  • Readers:
    • lint measure-aggregate-field-type-refused hint (validate-dataset-measure-aggregates.ts, dataset and cube legs);
    • the dataset compile leg's REMEDY_BY_SOURCE_CLASS (dataset-compiler.ts), which now asks the spec first;
    • os explain measure-aggregate-field-type-refused (rule-explanations.ts, that entry only). This module imports nothing by design, so the entry writes the sentence out and a lint test holds it equal to the constant. I also dropped "(a computed column)" from the existing stored-numeric sentence, because a formula IS a computed column, so that wording pointed the reader the wrong way.
  • Unchanged: every other refused pair keeps its own words. That includes count_distinct over a JSON-stored type and over a multiple: true declaration ("… declaration accepts: count."), the temporal sentence, the min/max sort sentence, and the non-numeric sentence. No pair moved between accepted and refused.

Tests (at 3ecaba7595, after merging origin/main, which already contains #24474)

  • @objectstack/lint validate-dataset-measure-aggregates.test.ts. New describe block:
    • sum over a formula: hint === VIRTUAL_FIELD_AGGREGATE_REMEDY, contains "store the value as a number field", the remedy comes before the count mention, and no "accepts: count";
    • avg/min/max read the same sentence;
    • os explain contains the sentence verbatim;
    • controls: sum × text keeps "type accepts: count, count_distinct.", count_distinct × select multiple: true keeps "declaration accepts: count.", count_distinct × json keeps "type accepts: count.", and count × formula fires nothing.
    • The explain pin "STORED as a numeric field (a computed column)" is flipped to "STORED as a numeric field and aggregated as one" plus the remedy sentence. The suite's existing 200-character fix: line pin now covers the formula hint too.
  • @objectstack/service-analytics aggregate-nontemporal-measure-refusal.test.ts: sum/avg/min/max × formula gives DATASET_INVALID / 400 with no SQL emitted, and the message contains the spec sentence and neither the non-numeric nor the sort sentence. Control: sum × text keeps "For a non-numeric field".
  • @objectstack/spec aggregate-field-type-compatibility.test.ts: the four aggregates over formula return the sentence, undefined everywhere else (accepted pairs and stored classes), fail-closed shape cases, one line of at most 200 characters, and the virtual class refused on all four rows.

Package runs

  • At 3ecaba7595 (merged head): @objectstack/spec pnpm test, 699 files / 21281 passed; spec test:repo was run before the merge, 70 files / 1162 passed; the three targeted files above, 76 + 49 + 28 passed.
  • Before the merge (branch head b3a054b0af plus its changeset and regen commits): @objectstack/lint pnpm test, 145 files / 6870 passed; @objectstack/service-analytics pnpm test, 183 files / 4498 passed, 262 skipped; typecheck green for lint, service-analytics and spec.
  • Gates: node scripts/pm/dispatch-gates.mjs --commands at 3ecaba7595 derived 91 commands. All 91 were run, every one exited 0, and --ran reports 91 run, 0 NOT-MEASURED, 0 UNRUN. check:api-surface and check:export-origins went red on the new export as expected and were regenerated (gen:api-surface, gen:export-origins): two added names, nothing removed.

Reverse verification (fix committed first; scripts/ablation-replace.mjs, which restores to HEAD and checks git diff HEAD is empty)

  • Deleted the lint line virtualFieldAggregateRemedy(aggregate, fieldType) ?? (anchor 1 → 0, blob e0f84182c232 → cd6b974fa3a7). Two lint cases went red with Received "Either point "sum" at a field of an accepted type, or aggregate "measured" with one its formula type accepts: count, count_distinct." The explain-equality case stayed green, as expected: that text does not depend on the line. Restored: blob == HEAD.
  • Deleted the compile-leg line if (virtual !== undefined) return virtual; (blob 170605d63191 → 68caccc65865). The new compile case went red with the old "For a non-numeric field, count accepts every type …" remedy. Restored: blob == HEAD.
  • Both subjects are imported from src/ by relative path, so the ablations needed no dist/ rebuild.

Acceptance notes

  • Same family, other doors, not changed here (outside the claim's file surface). For a formula, these still name a count as the way out: the analytics door's cube-query refusal (service-analytics/src/cube-measure-field-type-door.ts, "… aggregate a field of one of those types, or count the rows with count.", 400 INVALID_FIELD) and the engine's aggregate door (objectql/src/aggregate-field-type-door.ts, the same clause). Both can read virtualFieldAggregateRemedy the same way. Reported for the seat to place; not measured over HTTP in this run.
  • The divergence sentence is still worded for a stored column. For a formula, the compile leg's divergence sentence still says "derives a NUMBER from the stored values, so over a formula column …". The lint message says the same thing ("the number would depend on the SQL dialect"). For a virtual field the real reason is that no column exists. The wording is inaccurate but not misdirecting, since the remedy line now names the fix. Noted only.
  • count_distinct × formula. The table accepts it, and the shared sentence names it as "a different question". Whether every backend can actually lower a count_distinct over a column that is never emitted is not measured here.

Generated by Claude Code

…tal over a formula field

The measure-aggregate-field-type-refused hint for sum/avg/min/max over a
formula steered the author to count / count_distinct. The spec now owns the
one prescription (virtualFieldAggregateRemedy): store the value as a number
field and aggregate that, with a count named only as a different question.
The lint hint, its os explain entry and the dataset compile leg all read it.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D6F9axfoPzR7t8G1J7Ytzz
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation protocol:data tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

5 anchor(s) derived from 3 changed package(s); no hand-written page names any of them. ⚠️ 2 changed file(s) yielded no anchor (packages/spec/api-surface/data.json, packages/spec/export-origins/data.json), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

What this run could not see
  • 2 changed file(s) yielded no anchor (packages/spec/api-surface/data.json, packages/spec/export-origins/data.json) — pages documenting those are invisible to this run
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 54 of 206 client-bound route-ledger rows — the other 152 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 152: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 97 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 — 143 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 7e58e0a27998194640c145344b7519f1ccc9fad4 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 89482353059d5d92f409a36095f3f9f959d5a0cb — the merge of head 3ecaba7595e05f1e303ecd7ce5af27a0174586ca into base 7e58e0a27998194640c145344b7519f1ccc9fad4, 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 89482353059d5d92f409a36095f3f9f959d5a0cb && git checkout 89482353059d5d92f409a36095f3f9f959d5a0cb
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 7e58e0a27998194640c145344b7519f1ccc9fad4 3ecaba7595e05f1e303ecd7ce5af27a0174586ca && git checkout -B drift-repro 7e58e0a27998194640c145344b7519f1ccc9fad4 && git merge --no-ff 3ecaba7595e05f1e303ecd7ce5af27a0174586ca

node scripts/docs-audit/affected-docs.mjs --json 7e58e0a27998194640c145344b7519f1ccc9fad4

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

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

Review: ACCEPT · PR #24505 @ 3ecaba7595e05f1e303ecd7ce5af27a0174586ca · domain:spec seat 3 · 2026-10-19T09:08Z

Session session_01D6F9axfoPzR7t8G1J7Ytzz · baozhoutao. Reviewer of record; checked against GitHub, not the report. Diff re-read three-dot and merge-tested against the CURRENT main tip (clean).

  • Shape: draft, Fixes #24426, Clause-②: no; +221/−7, 10 files; NOT governed.
  • One source: VIRTUAL_FIELD_AGGREGATE_REMEDY / virtualFieldAggregateRemedy(aggregate, fieldType) in @objectstack/spec/data, returning the stored-number sentence only for a REFUSED sum/avg/min/max over SEARCH_VIRTUAL_TYPES and undefined otherwise. The lint hint, its os explain entry (held equal by a test) and the dataset compile leg all print it. Nothing newly accepted or refused.
  • Landing spot: beside the aggregate × field-type table, not beside the semantic migration entry — both consumers already import the table module; the migration tree holds only entries. Accepted.
  • Pins bear load: two ablations (the lint line, the compile line) each turned their cases red with the OLD count-steering text, and green on restore.
  • Generated: api-surface / export-origins regenerated for the two new exports (0 removed). Patch changesets for spec, lint and service-analytics.
  • Out of scope, noted (not filed here): the cube-query door (cube-measure-field-type-door.ts) and the engine aggregate door (aggregate-field-type-door.ts) still name a count for a formula total; a follow-up can read the same helper.
  • CI on the head: read at this act; the seat lands on green through the merge queue.

Generated by Claude Code

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review October 19, 2026 09:09
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge October 19, 2026 09:09
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit 4ad3ce5 Oct 19, 2026
42 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-24426-measure-total-hint-stored-number branch October 19, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

2 participants