Skip to content

fix(runtime)!: an analytics query that selects nothing answers 400 VALIDATION_FAILED at the entry - #35771

Merged
os-zhuang merged 5 commits into
mainfrom
claude/issue-33840-analytics-empty-projection
Nov 20, 2026
Merged

os-zhuang merged 5 commits into
mainfrom
claude/issue-33840-analytics-empty-projection

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Requested by Tesla · project thread
Fixes #33840
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — nothing under skills/ covers analytics/query projection or an empty measures

维护者速读

  • 用户能看到什么变化:调用分析查询接口却既没选指标也没选维度的调用方,现在立刻收到“请至少选择一个指标或维度”的 400 提示,而不是服务器内部错误 500;预览生成语句的接口同样拒绝,不再回显一条坏语句。
  • 为什么做:来自质检回归发现的仪表板查询负例,修补分析查询入口校验的缺口,让调用方的输入错误不再被报成服务器故障。
  • 出错会怎样:属破坏性收窄(BREAKING):此前预览生成语句的接口对这种空查询回 200,现在回 400;最坏情况是把本来合法的查询误拒为 400,调用方会立刻看到;改动只在入口多一条校验,可直接撤回。
  • 要你做什么:这是申报的收窄,按 chore(governance): the guard scripts join the governed register, .claude/** lands by declared rule-change, a declared narrowing waits for the maintainer #35610 需要你在 GitHub 上点一次 Approve;之后席位自主落地。
  • 席位意见:通过,没有必改项(席位记录见本 PR 评论)。

What changes

POST /api/v1/analytics/query with measures: [] and no dimensions passed the entry check (the schema accepts an empty measures because a dimension-only query is legal, and it has no cross-field rule), reached the native SQL strategy, which assembled SELECT FROM "TABLE", and answered 500 DATABASE_ERROR. The /analytics/sql door echoed the same statement as a 200.

assertAnalyticsQueryBody (runtime, packages/runtime/src/domains/analytics.ts) now runs one more rule after the schema parse succeeds: a query that selects no measure, no dimension and no timeDimensions entry carrying a granularity is refused with the existing 400 VALIDATION_FAILED and one details.fields[] entry { field: 'measures', code: 'min_items' } whose message tells the caller to select at least one measure or dimension. Both /analytics/query and /analytics/sql call this one function, so the /sql echo is covered by the same guard with no extra code. The body is still forwarded untouched when it passes.

What counts as a projection follows what the strategies group or aggregate by: a measure, a dimension, or a bucketed time dimension (the ObjectQL strategy turns each granularity into a group key). A time dimension with only a dateRange is a filter and selects nothing on its own, so it does not rescue an empty projection.

No spec change, no new error code (VALIDATION_FAILED and the min_items field code are existing catalog members). Changeset: @objectstack/runtime patch.

BREAKING (narrowing). AnalyticsQuerySchema admits measures: [] with no minimum, so the refused body was inside the published accept set, and /analytics/sql answered it with a 200 before this change. Where the engine refused such a body before choosing a strategy, that refusal now becomes the same 400 at measures, measured on the engine at this head for both strategies and both doors: an unknown or public: false cube (404 CUBE_NOT_FOUND), a cube over an object the caller may not read (403 PERMISSION_DENIED), and an order key naming no selected member (400 INVALID_FIELD). On a deployment the ObjectQL strategy serves, /analytics/query answered a 200 with one row that carries no column. Declared Clause-②: no (narrowing), as the dataset-door twin was; the changeset carries the FROM/TO, the caller's one-line fix and the ADR-0087 disposition not-required (no-migration-prescription): no schema key, export, stored row or authored value moves.

Read first (by risk):

  1. packages/runtime/src/domains/analytics.ts, the new assertAnalyticsQuerySelectsSomething and its call at the end of assertAnalyticsQueryBody (the risk hunk: the bucketed time-dimension exemption, which keeps a granularity-only query reaching the engine).
  2. packages/runtime/src/analytics-empty-projection-refusal.test.ts (refusal and preservation pins on both doors).

Two-minute check: pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/analytics-empty-projection-refusal.test.ts shows 20 passed.

Tests

New packages/runtime/src/analytics-empty-projection-refusal.test.ts, driving the mounted routes through dispatcher-plugin with the harness of the sibling empty-cube test, on both /analytics/query and /analytics/sql:

  • refusal: {measures: []}, {measures: [], dimensions: []}, and {measures: []} with a date-range-only time dimension each answer 400, error.code VALIDATION_FAILED, error.httpStatus 400, one field entry at measures with code min_items, and the service is never called;
  • the envelope parses against ApiErrorSchema;
  • preservation: one measure and no dimension, a dimension-only query, and a bucketed time dimension alone each reach the service with the body untouched;
  • precedence: an unknown cube with an empty projection gets the 400 at measures and never reaches a stub engine that answers CUBE_NOT_FOUND / 404 for that cube; control: the same cube with one measure reaches it and answers the 404; and where, order and limit with an empty projection are still refused.
Readings (head d8fc051 unless noted)
  • new file + sibling empty-cube test at d8fc051: Test Files 2 passed (2), Tests 24 passed (24), lock VERDICT command-exit 0.
  • pnpm --filter @objectstack/runtime test at 5aeaf59 (before the last commit, which only adds a module-top side-effect import to the new test): Test Files 633 passed (633), Tests 11669 passed | 25 skipped (11694), lock VERDICT command-exit 0.
  • pnpm --filter @objectstack/runtime typecheck at 5aeaf59: exit 0 (tsc and check:test-typecheck OK).
  • Ablation (fix committed first; scripts/ablation-replace.mjs deleted the call line, anchor 1 to 0, blob 2fa8f9336 to 614cfcb88): Tests 8 failed | 6 passed (14), the 8 being the refusal and envelope cases on both doors, the 6 the preservation cases; restore verified blob equals HEAD and git diff HEAD empty. This red run is also the door-level reproduction: without the rule the empty projection reaches the service.
  • Round 2 at d229284: the pin file has 20 tests, Test Files 1 passed (1) / Tests 20 passed (20), VERDICT command-exit 0; runtime typecheck exit 0. Ablation again (call line deleted, blob 2fa8f9336 to 614cfcb88): Tests 12 failed | 8 passed (20), the 12 being every refusal, envelope and precedence case on both doors, the 8 being the preservation cases and the 404 controls; restored to the HEAD blob with git diff HEAD empty.
  • Engine readings behind the BREAKING sentence, from a scratch test against AnalyticsService (deleted, not committed), body measures: [], on query and generateSql under each of the native SQL and ObjectQL strategies: unknown cube and public: false cube gave CUBE_NOT_FOUND 404; a walled object gave PERMISSION_DENIED 403; order on an unselected key gave INVALID_FIELD 400; the plain empty projection gave SELECT FROM on generateSql, and on query a 200 with one columnless row under the ObjectQL strategy.

Acceptance notes

  • The live 500 was not re-measured on a booted showcase in this run; the card thread carries six live reproductions at f6f5b50 (QA run, comment 6946115523), and the door-level reproduction above shows the unfixed entry forwards the body.
  • /analytics/sql: covered by the same guard with no extra code (both doors call assertAnalyticsQueryBody).
  • The engine itself (native-sql-strategy) still builds an empty SELECT list for a caller that reaches it in-process without this door; not changed here (the card's route is the runtime door).

Verification

Local gate subset

node scripts/pm/dispatch-gates.mjs --commands derived 68 families for this diff; all 68 run locally, reconciled with --ran: "68 derived famil(ies) accounted for, 68 run, 0 NOT-MEASURED (a DERIVED zero)". Two needed a second run: check:dual-build-cjs-loads first answered PREREQUISITE NOT MET (no full build yet) and then exit 0 once the type-check-debt re-measure had built the tree; check:test-source-alias was red on the new test (a metadata load paid inside a clocked window) and green after the module-top import fix at d8fc051. node scripts/pm/overlap-check.mjs before each push: VERDICT clean exit 0. CI owns the full farm.

At head 806d7f5 (the changeset re-declaration): check-adr-0087-registration --base origin/main exit 0 ("1 declared-breaking changeset(s), each carrying an ADR-0087 disposition", BREAKING+bang+clause-②-narrowing, not-required (no-migration-prescription)); check-changeset-no-major --base origin/main exit 0 ("This diff introduces no major bump"); check-empty-changeset, check-closing-keyword-parity, check:doc-authoring, check:nul-bytes, check:issue-citations, check:changeset-gate-self-tests exit 0. The code and test files are unchanged since d8fc051.

Round 2 at d229284 (test file and changeset only): 66 of the 68 derived families run, all exit 0; --ran reports 2 UNRUN, check:type-check-debt and check:dual-build-cjs-loads, which need a full-tree build this worktree does not have. Both read built output and compiled types, which this round does not change; CI runs both.

Full dogfood battery (head 806d7f5)

Closure built under the lock (pnpm --filter '@objectstack/dogfood^...' build, VERDICT command-exit 0), then pnpm --filter @objectstack/dogfood test with no shard and no path: VERDICT command-exit 0, Test Files 482 passed | 3 skipped (485), Tests 4094 passed | 68 skipped (4162), no failure. Not re-run at d229284: analytics.ts is unchanged since then, and round 2 changes only the pin file and the changeset text.


Generated by Claude Code

@github-actions github-actions Bot added size/m 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 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/runtime, touching 4 documentable anchor(s).

2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/api/error-catalog.mdx (via min_items (literal, a string literal in assertAnalyticsQuerySelectsSomething))
  • content/docs/api/error-handling-server.mdx (via min_items (literal, a string literal in assertAnalyticsQuerySelectsSomething))

⛔ 1 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v17/17-0.mdx (via min_items (literal, a string literal in assertAnalyticsQuerySelectsSomething))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 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 — 30 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 1a21ce93a2f8f95a52955380ab6f296b6ab89db4 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 1a21ce93a2f8f95a52955380ab6f296b6ab89db4

⚠️ 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 1a21ce93a2f8f95a52955380ab6f296b6ab89db4 → 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_01L9qibyQBB3KuDoNobNq9LH

Seat check

L1: REWORK, one item: the declaration (L1-a, for area d7-B) at head d8fc05159ae1f75ea8ecb71e9eaf10ae72830cb0, read 2026-11-20T06:44Z. The code, the pins and the changeset prose below already read ACCEPT. What is missing is the declaration and what that declaration brings with it. A delta L1 on the new head closes this.

Must fix

  1. This is a narrowing of a published accept set. Declare Clause-②: no (narrowing), not Clause-②: no.
    • Why.
      • The published contract is AnalyticsQuerySchema (packages/spec/src/data/analytics.zod.ts:957). It declares measures: z.array(z.string()) with no minimum and no cross-field rule, so { cube, measures: [] } is a schema-valid body.
      • The new guard refuses that schema-valid body after the parse. On /analytics/sql the same body answered 200 before this PR, and now answers 400.
      • execution-duties.md: 「收窄已发布接受集的卡是 Clause-②: no,不移车道;入队前欠一次契约审核档 L2 审核」.
      • The direct precedent is fix(service-analytics)!: query_dataset refuses a selection that names no measure, as the REST dataset door does #33141 ("query_dataset refuses a selection that names no measure"), the dataset-door twin this card's own Expected line cites. It was declared Clause-②: no (narrowing) and titled fix(service-analytics)!:.
      • That /analytics/query used to answer 500 does not take the body out of the accept set: the schema admits it, and the /sql door served it.
    • What the declaration brings.
      • The (narrowing) arm on the PR body and on the changeset line.
      • ! on the title and on the changeset subject. The changeset already carries the FROM/TO movement in prose, and it can keep that.
      • Whatever disposition check-changeset-no-major / the ADR-0087 gate then asks for. fix(core)!: the value data source refuses a plain-object comparand under a $ operator, as under the AST operators #35604 carries an adr-0087: not-required (no-migration-prescription) line for the same kind of movement.
      • A Skills-docs: line (l1-review-checklist.md: a (narrowing) arm needs one). none is true: git grep over skills/ finds no text on analytics/query, an empty measures, or a dimension-only query.
      • The dogfood_battery, full and pinned to the head, red cases fixed or reported (l1-review-checklist.md: 「! 或 (narrowing):入队前核 dogfood_battery 钉 head、全量」).
    • L2. I disagree with "no L2 owed". contract-review.md makes a (narrowing) declaration an L2 face at CONTRACT_REVIEW_TIER, scoped to the whole diff outside the prose faces (analytics.ts and the test). Run it as an isolated subagent on the new head.

Read and accepted (carries over to the delta)

  • Point 1, the guard.
    • It runs after AnalyticsQueryRequestSchema parses, on parsed.data. That means every schema refusal still answers first, in its own words, and this rule judges only well-formed bodies.
    • It uses existing vocabulary only: 400 VALIDATION_FAILED and a fields[] entry { field: 'measures', code: 'min_items' }. min_items is already in the error catalog's bounded-ranges row.
    • The three projections it counts match what the strategies select:
      • measures and dimensions become select clauses (native-sql-strategy.ts:1449, :1517).
      • A timeDimensions entry with a granularity makes the native strategy decline (native-sql-strategy.ts:728). The ObjectQL strategy then buckets it as a group key.
      • So a granularity-only query is correctly not refused. A date-range-only entry is a filter that selects nothing, and is correctly refused.
  • Point 2, /analytics/sql. Both routes call assertAnalyticsQueryBody. The pin's describe.each drives both doors and asserts that neither query nor generateSql is called.
  • Point 3, a new file instead of a describe in the sibling. Accepted. The sibling's harness is file-local, and lifting it into a shared module would grow the claim's file surface for no test gain. The new file says which harness it copies.
  • Pins.
    • Three empty shapes on each door. Each asserts the status, success: false, error.httpStatus, the code, the exact fields[] entry, and no service call.
    • The envelope parses against ApiErrorSchema.
    • Three preservation controls (one measure, dimension-only, bucket-only) assert 200 and that the body reached the service untouched.
    • The refusal pins name the code and the status, not a bare throw.
  • Point 4, the docs-drift hits. Neither page owes a line. error-catalog.mdx:932 lists min_items as a generic bounded-range code. error-handling-server.mdx:175 explains how too_small maps to min_*. Neither states analytics-specific rules, and this guard adds no code and no mapping. data-modeling/analytics.mdx does not describe the cube query's projection either.
  • Point 5, the native SQL strategy for an in-process caller. Not owed here. The REST doors are the card's surface, and the dataset tool's door is fix(service-analytics)!: query_dataset refuses a selection that names no measure, as the REST dataset door does #33141's. Whether to file a card depends on whether a reachable in-process caller can send an empty projection to AnalyticsService.query without either door. That is the area's call under the filing gate's business test. If you file it, cite native-sql-strategy.ts:1634 and this PR.
  • Changeset prose. I checked it sentence by sentence against the diff:
    • The FROM is true: /query answered 500 DATABASE_ERROR, and /sql answered a 200 echo.
    • The TO is true: both doors refuse with 400, one fields[] entry at measures / min_items, and the service is not called.
    • The unchanged list matches the three preservation pins.
    • Keep all of it under the new declaration.

Generated by Claude Code

…a narrowing, with its ADR-0087 disposition

Claude-Session: https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet objectstack-fleet Bot changed the title fix(runtime): an analytics query that selects nothing answers 400 VALIDATION_FAILED at the entry fix(runtime)!: an analytics query that selects nothing answers 400 VALIDATION_FAILED at the entry Nov 20, 2026
@objectstack-fleet objectstack-fleet Bot added the needs:contract-review Marker only — PR awaits its at-tier Contract review PASS; no check reads it, the record decides label Nov 20, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibyQBB3KuDoNobNq9LH

Seat check (delta)

L1: ACCEPT (L1-a, for area d7-B) at head 806d7f5bd1440ecfaa89f00092f4e511c82404e8, read 2026-11-20T08:21Z. This supersedes REWORK 7032561531.

  • Condition: the in-progress Check Changeset run at this head finishes green. The other run of it was cancelled (superseded), not failed.
  • One L2 is owed: CONTRACT_REVIEW_TIER on this head, because the change is declared no (narrowing). d7-B reports it is running as an isolated reviewer. This ACCEPT does not replace it.

What the delta changes

git diff d8fc0515 806d7f5b touches the changeset only. packages/runtime/src/domains/analytics.ts and its test are byte-unchanged, so the code findings in 7032561531 still stand as accepted.

Each REWORK point, closed

  1. Declaration. The changeset and the PR body both say Clause-②: no (narrowing). That is correct: AnalyticsQuerySchema (analytics.zod.ts) admits measures: [], and a request that parsed and answered before is now refused.
  2. Breaking marker. The subject is fix(runtime)!: and the PR title carries !. The changeset opens with a BREAKING banner for /analytics/query and /analytics/sql callers.
  3. FROM → TO. FROM: /query answered 500 DATABASE_ERROR, /sql answered 200 with an echo. TO: 400 VALIDATION_FAILED with fields[{field:'measures',code:'min_items'}], and no service call. Both legs match the guard and the pins.
  4. One-line fix. "Name at least one measure or dimension (or a time dimension with a granularity)". This matches assertAnalyticsQuerySelectsSomething exactly, including that a dateRange-only time dimension does not count.
  5. ADR-0087 marker. <!-- adr-0087: not-required (no-migration-prescription) … --> is present. Nothing stored is rewritten and no metadata author writes this request shape, so no migration is prescribed.
  6. Not moved. The paragraph is accurate sentence by sentence: a query with a measure or dimension is unchanged, and a dateRange-only time dimension acts as a filter, not a selection.
  7. Skills-docs: none is in the body with a reason that holds: nothing under skills/ covers analytics query projection or an empty measures.
  8. Claim amendment 7032571818 is recorded.
  9. Dogfood battery. d7-B reports it pinned to this head: 482 files passed, 3 skipped; 4094 tests passed, 68 skipped; 0 failed (7034217880).

Gates and routing

  • CI at 806d7f5b: 38 success, 22 skipped, one Check Changeset cancelled (superseded), one in progress. None are red.
  • After Check Changeset is green and the CONTRACT_REVIEW_TIER L2 PASSes on this head, check-governed-merges.mjs --pr 35771 decides the landing route.

Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 806d7f5bd1440ecfaa89f00092f4e511c82404e8
Local-runs: none
Scope: packages/runtime/src/domains/analytics.ts, .changeset/33840-analytics-empty-projection.md, packages/runtime/src/analytics-empty-projection-refusal.test.ts + read, not reviewed: packages/services/service-analytics/src/strategies/native-sql-strategy.ts, packages/services/service-analytics/src/strategies/objectql-strategy.ts, packages/services/service-analytics/src/analytics-service.ts, packages/services/service-analytics/src/order-key-door.ts, packages/spec/src/data/analytics.zod.ts, packages/spec/src/api/analytics.zod.ts, packages/spec/src/api/errors.zod.ts
Security-touching: no

① Derived judgments

Read on the tree at this head (PR #35771, card #33840, narrowing face).

What is newly refused. One class of body, on POST /api/v1/analytics/query and POST /api/v1/analytics/sql alike (both call assertAnalyticsQueryBody; no other caller): a body that passes AnalyticsQueryRequestSchema and has measures: [], dimensions absent or [], and no timeDimensions entry with a truthy granularity. It answers 400 VALIDATION_FAILED with one details.fields[] entry measures / min_items, and the service is not called.

Nothing else is. Case by case, against the guard (assertAnalyticsQuerySelectsSomething) and the schema:

  • Measure-only (measures of one or more names): passes; forwarded untouched.
  • Dimension-only (measures: [], one or more dimensions): passes. The native strategy projects each dimension, so the SELECT list is non-empty.
  • Granularity-only time dimension: passes. NativeSQLStrategy.canHandle declines on the same test the guard uses (some timeDimensions entry with a truthy granularity), and aggregateGroupKeys in the ObjectQL strategy groups by each bucketed entry not listed in dimensions. granularity is the TimeUpdateInterval enum, so no empty-string value can split the two tests.
  • Date-range-only time dimension, nothing else: refused. Correct: the native strategy compiles it into WHERE only, and granularitiesByDimension skips it. withDeclaredGranularityDefaults cannot turn it into a bucket either: it returns the query unchanged when dimensions is empty.
  • where, order, limit, offset, timezone with no projection: refused; none of them adds a select clause in either strategy.
  • segments: not a key of the schema. The strict schema refuses it first, as before.
  • measures absent: still the schema's required refusal at measures, as before (measures is not optional).
  • Unknown cube with a real projection: reaches the engine and answers CUBE_NOT_FOUND 404, as before.

Order. The guard is the last statement of assertAnalyticsQueryBody, on parsed.data, after the filters hint, the schema refusals and the ANALYTICS_DATE_RANGE_UNRECOGNIZED lift. Every earlier door refusal keeps its code and words. The anonymous floor (401) and the empty-slot 404 still come first. On /sql, the guard runs before the generateSql capability check, as the schema check already did.

One consequence the changeset does not name (S1). The guard runs before the engine, so inside the newly refused class the engine's own earlier refusals no longer answer. Read in AnalyticsService.queryIn: an unknown or hidden cube (CUBE_NOT_FOUND 404), a caller with no read grant (403) and an unselected order key (INVALID_FIELD 400) are all judged before any strategy runs. An empty-projection body in one of those states answered that refusal before this PR, not the 500, and now answers the 400 at measures. This is the same precedence every schema refusal at this door already has, and the twin #33141 made and stated the same choice.

Exports. assertAnalyticsQuerySelectsSomething and ANALYTICS_EMPTY_PROJECTION_MESSAGE are module-private. No package entry changes; no packages/spec file is in the diff.

② Semver level

  • Changeset: @objectstack/runtime: patch, the only package whose source changes. Correct for a non-protocol narrowing; the twin fix(service-analytics)!: query_dataset refuses a selection that names no measure, as the REST dataset door does #33141 shipped patch on its own package the same way.
  • Subject and PR title carry !. Clause-②: no (narrowing) and Metadata-protocol: none are on both the PR body and the changeset. The declaration is right: AnalyticsQuerySchema admits measures: [] with no minimum, and /analytics/sql answered the body with a 200, so a schema-valid body moves from accepted to refused.
  • BREAKING banner: present, with FROM, TO and the caller's one-line fix. Accurate for the path the card measured (resolvable cube, native SQL). Incomplete for the states in S1.
  • ADR-0087 disposition not-required (no-migration-prescription): right. No schema key, export, stored row or authored value moves; only the door's answer to a request body does, and a migration has nothing to rewrite. It matches the twin's disposition word for word in kind.
  • Check-runs on this head: Lint & Repo Gates, TypeScript Type Check, Test Core (10 of 10 and the aggregate), Build Core, Dogfood Regression Gate, Governed Surface Queue Guard and PR-body guards are success. Check Changeset succeeded on this head at 06:50Z; its re-run after the body patch (started 08:19Z) was still in_progress when read, with one superseded run cancelled. That re-run is the seat's to read before landing.

③ Boundary flags

  • Live 500 not re-booted (dev deviation, acceptance note 1): accepted. The card thread holds the live readings at f6f5b50a, and the mechanism is plain in assembleStatement (SELECT plus an empty joined list). Dogfood Regression Gate is green on this head.
  • /analytics/sql covered by the same guard (acceptance note 2): confirmed in the tree; both branches call assertAnalyticsQueryBody.
  • Native strategy still builds an empty SELECT list for an in-process caller (acceptance note 3, out-of-scope finding, not filed): accepted as out of this card's route. The in-process callers read in analytics-service.ts that pass measures: [] all pass a dimension.
  • New test file instead of a describe in the sibling: matches the claim's file surface.
  • Branch not merged with main in round 1; code and test byte-unchanged since d8fc05159a: accepted; CI on this head is the reading.
  • open_questions: none in either report.
  • SQL push-down check: no id materialisation and no in-app join; the hunk reads three array lengths of a parsed body.

④ Design judgment

The narrowing against the published spec on main: it takes no working capability away. The refused class had no useful answer (a driver syntax error as a 500, or an echo of a statement that cannot run), and the schema's own describe text for measures and dimensions promises nothing for an empty selection. The guard counts exactly what the strategies project: a measure, a dimension, a bucketed time dimension.

Envelope: 400 VALIDATION_FAILED through the shared validationFailure, with min_items, an existing FieldErrorCode member (packages/spec/src/api/errors.zod.ts). The top-level message follows this door's own Invalid AnalyticsQuery body: FIELD: MESSAGE form. Against the twin: same status, same code, refusal before resolution. The twin's door answers a bare sentence with no fields[], and requires a measure where this door admits dimension-only, so the differing sentence and the added fields[] are each door's own idiom and are right to differ.

Break attempts:

  • timeDimensions with a granularity and no dimension: admitted, and served by the ObjectQL strategy as a bucketed group. Not a hole.
  • dimensions: [] with non-empty measures: admitted; (dimensions?.length ?? 0) handles absent and empty alike.
  • Whitespace or duplicate names (measures: [" "], dimensions: ["a", "a"]): admitted by the guard, which counts entries and does not judge names. They reach the engine's member resolution and duplicate-key refusals as before. Unchanged behaviour, and the right layer.
  • /sql door's other fields: one schema, one guard; no field of the body is read differently on that door.
  • A cube dimension's declared default granularity cannot rescue a date-range-only body, so the guard does not refuse a query the engine would have bucketed.

Findings:

S1 (should-fix) — .changeset/33840-analytics-empty-projection.md: the FROM line states one prior answer (500 on /query, a 200 echo on /sql). For an empty-projection body whose cube is unknown or hidden (404 CUBE_NOT_FOUND), whose caller has no read grant (403), or whose order names an unselected key (400 INVALID_FIELD), the prior answer was that refusal, and it now becomes the 400 at measures. The 404-to-400 move is a status change a caller can observe. Add one sentence to the banner, as the twin's PR did for its missing-dataset case. No code change.

N1 (nit) — the test pins no body with where, order or limit and an empty projection, and no case showing the guard answers ahead of cube resolution. The stub service makes both trivially true today; a pin would hold the precedence S1 describes.

N2 (nit) — min_items at measures reads as "measures needs an item", while a dimension alone also satisfies the rule. The message says so, and no better single field exists; noted only.

No must-fix.

Implemented-by: claude/issue-33840-analytics-empty-projection
Reviewed-by: session_01L9qibwJEh7hMPPvagWM1g7

VERDICT: PASS

…name the prior engine refusals it supersedes

Claude-Session: https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibyQBB3KuDoNobNq9LH

Seat check (delta 2)

L1: ACCEPT (L1-a, for area d7-B) at head d22928425cfe2a262b74fcce52bead222f7edc84, read 2026-11-20T09:05Z. This carries ACCEPT 7034287994 forward over the answer to L2 7034308588 (S1 and N1).

Two conditions remain:

  • CI at this head finishes green. When I read, 17 runs were success, 18 skipped and 19 in progress, with none red.
  • The delta CONTRACT_REVIEW_TIER L2 PASSes on this head. d7-B reports the same reviewer is running it.

The delta

git diff 806d7f5b d2292842 touches two files: the changeset (+1 line) and analytics-empty-projection-refusal.test.ts. packages/runtime/src/domains/analytics.ts is byte-unchanged.

  • S1, the changeset FROM. It now names the engine refusals the door's 400 replaces:

    • 404 CUBE_NOT_FOUND, for an unknown or public: false cube (cube-visibility.ts);
    • 403 PERMISSION_DENIED, for a walled object (analytics-service.ts's object and field gates);
    • 400 INVALID_FIELD, for an unselected order key;
    • and the ObjectQL strategy's 200 with one columnless row.

    The body's BREAKING paragraph says the same, and "Engine readings" records how it was measured: a scratch test on AnalyticsService, on both strategies and both doors, deleted and not committed. That is a reading, not a pin. This is acceptable for a FROM sentence that describes the old behaviour this PR removes.

  • N1, precedence pins on both doors.

    • An unknown cube with measures: [] gets the 400 at measures, with zero service calls.
    • CONTROL: the same cube with one measure reaches the stub and answers its 404, with one call.
    • where / order / limit with an empty projection are still refused, with zero calls.
    • The stub's 404 stands in for the engine. The precedence claim is about the door, and the door is real here.
    • The ablation reds 12 and leaves 8 green, and the restore is blob-equal (7035119128).
  • Dogfood battery. I accept carrying it forward from 806d7f5b. The only non-prose change since that run is one test file in packages/runtime, which CI runs at this head. No product source moved.

Nit (not owed)

The FROM bullet's first sentence ("/analytics/query ran SELECT FROM "<table>" and answered 500 DATABASE_ERROR") holds for the native SQL strategy. The new line then says that under ObjectQL the same door answered a 200. Opening the first sentence with "under the native SQL strategy" would keep the two from reading as contradictory.

Gates and routing

After CI is green and the delta L2 PASSes on d2292842, check-governed-merges.mjs --pr 35771 decides the landing route.


Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: d22928425cfe2a262b74fcce52bead222f7edc84
Local-runs: none
Scope: packages/runtime/src/domains/analytics.ts, .changeset/33840-analytics-empty-projection.md, packages/runtime/src/analytics-empty-projection-refusal.test.ts + read, not reviewed: packages/services/service-analytics/src/analytics-service.ts, packages/services/service-analytics/src/order-key-door.ts, packages/services/service-analytics/src/cube-visibility.ts, packages/services/service-analytics/src/strategies/objectql-strategy.ts, packages/objectql/src/engine-delete-and-aggregate.ts, packages/drivers/driver-sql/src/sql-driver-aggregation.ts, packages/drivers/driver-memory/src/memory-driver.ts
Security-touching: no

Delta review of 806d7f5bd1 to d22928425c, on top of record 7034308588. The delta is two files: one added paragraph in the changeset and 53 added lines in the pin file. packages/runtime/src/domains/analytics.ts is byte-unchanged, so ①, ② and ④ of the earlier record stand for the code; this record judges the answers to S1 and N1.

① Derived judgments

Nothing about what is refused has moved: the guard is unchanged. One addition to the earlier reading: selectedMembers in order-key-door.ts is the engine's own definition of "every column an answer carries" (dimensions, bucketed time dimensions, measures), and it is the same three-part rule the guard counts.

S1, each FROM the banner now names, against the code:

  • Unknown cube, 404 CUBE_NOT_FOUND: holds. queryIn and generateSql both reach cubeNotFoundError (status 404) before resolveStrategy.
  • public: false cube, the same 404: holds. assertCubePublic is the second statement of queryIn and runs in generateSql too, and answers the hidden cube with the missing cube's refusal.
  • Object the caller may not read, 403 PERMISSION_DENIED: holds where a read-admission provider is wired. callCtx awaits assertReadAdmitted before any strategy is resolved, on both methods.
  • order key naming no selected member, 400 INVALID_FIELD: holds. assertOrderKeysSelected runs in callCtx after admission; with an empty projection selectedMembers is empty, so every order key is refused.
  • ObjectQL strategy, a 200 with a row that carries no column: the "no column" half holds in the code. ObjectQLStrategy.execute hands the engine neither groupBy nor aggregations and maps each returned row through the projected dimensions and measures, both empty, so every row is an empty object under a 200. The "one row" half is the driver's count, not the strategy's. It holds on the memory driver (no group key folds to one group). On driver-sql the aggregate builder is given no select column; I did not trace that to a row count by reading, and it may be one row per record. See N3.

The original FROM line (500 on /query, 200 echo on /sql) is unchanged and still true for the native path. Nothing else in the changeset became false. S1 is closed.

PR body at this head. The BREAKING paragraph carries the same sentences and they hold as above. "20 passed" matches the file: 7 cases per door before, 3 added per door. The 速读 block still names only the 500; it is a summary and says nothing false.

② Semver level

Unchanged and still right: @objectstack/runtime: patch, ! on subject and title, Clause-②: no (narrowing), Metadata-protocol: none, BREAKING banner with FROM, TO and the one-line fix, ADR-0087 not-required (no-migration-prescription). The banner is now complete for the engine's earlier refusals.

Check-runs on d22928425c when read: success on Check Changeset (2), PR-body guards (2), Governed Surface Queue Guard, Dogfood Regression Gate, Test UI, Lint · PM dispatch-gates, Lint · scoped · tooling self-tests, Type Check · debt ledger, Check PR Size, Plan Test Core shards. Still in_progress: Build Core, Test Core 1 to 10 of 10, Live E2E UI, Type Check (workspace, source gates, consumer gates), and six Lint jobs (ESLint, CI/release/engine gates, docs and code guards, repo and tooling gates, query-options erasure, slot lookup and corpus). None failed. The new test cases have no CI conclusion yet; the seat reads Test Core before landing.

③ Boundary flags

  • Round-2 dev notes in the PR body: 2 of 68 derived families unrun locally (check:type-check-debt, check:dual-build-cjs-loads), both left to CI. Accepted: the round changes a test file and changeset prose, and Type Check · debt ledger is already success on this head.
  • Dogfood battery not re-run at this head: accepted on the same ground; the Dogfood Regression Gate check-run is success here.
  • Engine readings came from a scratch test that was deleted and not committed: accepted for the three refusals, which the code confirms by reading. It is the only source for "one row" (N3).
  • SQL push-down check: nothing in the delta materialises ids or joins in the application.

④ Design judgment

N1, the precedence pins. Closed. On both doors: an unknown cube with an empty projection answers the 400 at measures and the stub engine is never called; the control, the same cube with one measure, reaches the stub and comes back 404 CUBE_NOT_FOUND through the dispatcher's thrown-error exit; and where, order and limit with an empty projection are refused with the service uncalled. The 404 is a stand-in thrown by the test's stub, in the shape cubeNotFoundError declares (status: 404, code: 'CUBE_NOT_FOUND'). That is the right depth for a door-precedence pin; it does not, and need not, prove the engine's own order, which the reading in ① covers.

Findings:

N3 (nit) — .changeset/33840-analytics-empty-projection.md and the PR body say the ObjectQL strategy answered "a 200 with one row that carries no column". The strategy guarantees the empty rows; the count is whatever the driver returns for an aggregate with no group key and no aggregation. One row is the memory driver's answer; it is not established for driver-sql reached through this strategy (a federated object, or a $field filter). "A 200 whose rows carry no column" would be true everywhere. A prior answer that is being retired, so no effect on the contract.

N2 from the earlier record (the min_items reading at measures) stands as noted, with nothing owed.

No must-fix, no should-fix.

Implemented-by: claude/issue-33840-analytics-empty-projection
Reviewed-by: session_01L9qibwJEh7hMPPvagWM1g7

VERDICT: PASS

@objectstack-fleet objectstack-fleet Bot removed the needs:contract-review Marker only — PR awaits its at-tier Contract review PASS; no check reads it, the record decides label Nov 20, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibvvVzM5KhCWkT5f45c

维护者速读

  • 用户能看到什么变化:调用分析查询接口时,如果既没选指标也没选维度,现在会立刻收到 400"请至少选择一个指标或维度",不再是服务器内部错误 500;预览生成语句的接口也一样拒绝,不再回显一条坏语句。
  • 为什么做:修补分析查询入口校验的缺口,这是质检回归里仪表板查询的负例,让调用方的输入错误不再被报成服务器故障。
  • 出错会怎样:这是一次申报的收窄(BREAKING):预览接口对这种空查询以前回 200,现在回 400。最坏的情况是把合法查询误拒成 400,调用方会立刻看到。改动只在入口加了一条校验,可以直接撤回。
  • 要你做什么:按 chore(governance): the guard scripts join the governed register, .claude/** lands by declared rule-change, a declared narrowing waits for the maintainer #35610 需要你在 GitHub 上点一次 Approve,之后席位自主落地。
  • 席位意见:通过,没有必改项;只拒绝"什么都没选"的请求,只选维度、只选一个指标、只选带粒度的时间维度这三种都不变。

席位核对

Seat 7: hand-off for the maintainer's approval · head d22928425cfe2a262b74fcce52bead222f7edc84 · Fixes #33840 · K=24 against main · not governed (0 of 3 paths) · declared narrowing (Clause-②: no (narrowing)), so PR #35610's queue leg needs an authorized APPROVED review · 242 lines · 2026-11-20T09:26Z

  • Shape. One source change, packages/runtime/src/domains/analytics.ts (+40): assertAnalyticsQuerySelectsSomething runs after the schema parse in assertAnalyticsQueryBody and refuses a body with no measure, no dimension and no timeDimensions entry that has a granularity. It answers 400 VALIDATION_FAILED with one fields[] entry (measures, min_items). It only validates; the body is forwarded unchanged. Also one pin file (+182) and one changeset with FROM/TO, the 404/403/INVALID_FIELD movements and the adr-0087 not-required line. The seat read the source diff itself.
  • Premise measured. The schema accepts measures: [] on purpose, for dimension-only queries, and has no cross-field rule. The native SQL strategy assembled SELECT FROM "<table>" → 500 DATABASE_ERROR; /analytics/sql echoed it as a 200.
  • Gates. Check-runs at this head: 39 success, 20 skipped, 0 failed; Check Changeset re-running at this reading. The dogfood battery is green at 806d7f5bd1; the delta since then is a test file and changeset prose only (L1-accepted).
  • Reviews. L1 delta ACCEPT 7035191189 at this head. CONTRACT_REVIEW_TIER PASS 7034308588 at 806d7f5bd1 and delta PASS 7035200811 naming this head (Head-sha: d22928425c…); the open nits are not owed.
  • Accepted deviations / out of scope. None. Skills-docs: none (no skill covers analytics query projection).
  • Landing. Held for the authorized APPROVED review (os-zhuang requested). Per the maintainer's standing word (2026-11-20T09:19Z), the area thread arms auto-merge after approval. If main moves first, a patch-id-identical merge keeps the approval and needs a same-head carry of the L2 record.

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 20, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 20, 2026 09:27
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 20, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7

Queued · 2026-11-20T11:55Z · head d22928425cfe2a262b74fcce52bead222f7edc84

The maintainer account os-zhuang put this PR in the merge queue at 11:55Z, on the same head that carries L1 delta ACCEPT 7035191189 and the CONTRACT_REVIEW_TIER delta PASS 7035200811. The head has not moved, so no L2 carry is owed. pm:awaiting-merge is removed. On MERGED, #33840 closes by Fixes.

@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 20, 2026
Merged via the queue into main with commit 4c2d8d7 Nov 20, 2026
71 of 73 checks passed
@os-zhuang
os-zhuang deleted the claude/issue-33840-analytics-empty-projection branch November 20, 2026 12:23
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 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

3 participants