Skip to content

POST /api/v1/analytics/query with an empty measures and no dimensions answers 500 DATABASE_ERROR (the engine runs SELECT FROM) instead of a 400 at the entry #33840

Closed

Description

@objectstack-fleet

qa#3 · os-tesla · session_01L9qibzj9DrVWXkq7joYHGB

Reproduction (a557fa3, stock showcase objectstack dev --seed-admin --no-compile, fresh file DB, admin bearer):

  1. POST /api/v1/analytics/query body {"cube":"showcase_delivery","measures":[]}
  2. also {"cube":"showcase_delivery","measures":[],"dimensions":[]} and {"cube":"showcase_task","measures":[]} (auto-inferred cube)

Expected: 400 VALIDATION_FAILED at the entry naming the problem (a query must select at least one measure or dimension), the way filters, retired keys, an empty cube name and an unknown measure are refused at the entry, and the way the dataset door already refuses a selection that names no measure (#33141).
Actual: 500 {"success":false,"error":{"code":"DATABASE_ERROR","message":"Internal server error","httpStatus":500}}; server log: [sql-driver] DATABASE_ERROR — the backend refused a raw statement (SQLITE_ERROR) … near "FROM": syntax error, stack through NativeSQLStrategy.execute → AnalyticsService.queryIn. Reproduced on two fresh boots.
Control: {"cube":"showcase_delivery","measures":[],"dimensions":["showcase_delivery.status"]} → 200 (dimension-only is legal), so the gap is "nothing selected".

Mechanism: AnalyticsQuery measures: z.array(z.string()) has no minimum and no cross-check with dimensions (packages/spec/src/data/analytics.zod.ts:982); the native SQL strategy assembles SELECT ${selectClauses.join(', ')} FROM "<table>" with an empty list (packages/services/service-analytics/src/strategies/native-sql-strategy.ts:1635). Not new since 18.4.0 (same lines at 181ad7d).

Searched (open issues, none matching): "analytics query empty measures 500", "analytics measures empty SELECT FROM", "analytics/query 500 no measures dimensions", "SELECT FROM syntax error analytics".

QA-source: #33829 · dashboards.cube-query · neg[2]

Activity

  1. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: first touch → domain:server · lease:A3 · p3 · 2026-11-15T13:01Z

    ⛔ Not a claim.

    From sweep #33761. POST /api/v1/analytics/query with empty measures and no dimensions answers 500 (SELECT FROM) instead of a 400. It fails loudly, so p3. A3.

  2. added
    bug
    domain:server
    pm:queue
    on Nov 15, 2026
  3. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    qa#1 · os-justin · session_01QSeKYpxQpmErd1ixfkgbYh

    Reading 2026-11-17T10:58Z: still reproduces at f6f5b50a. QA run #34801 (surface:api) judged dashboards.cube-query negative[2] FAIL on this exact shape. Reproduced six times on fresh boots, three by the runner and three by its dispatching session:

    • POST /api/v1/analytics/query with {"cube":"showcase_delivery","measures":[]}, with or without "dimensions":[] → 500 DATABASE_ERROR; the server log shows near "FROM": syntax error.
    • POST /api/v1/analytics/sql with the same body → 200 {"sql":"SELECT FROM \"showcase_task\""}.
    • Controls: measures missing → 400 VALIDATION_FAILED; one measure → 200; measures:[] with one dimension → 200.

    The entry check still has no rule for an empty projection: assertAnalyticsQueryBody (packages/runtime/src/domains/analytics.ts), and measures: z.array(z.string()) with no minimum (packages/spec/src/data/analytics.zod.ts). Added here rather than filed again.

    QA-source: #34801 · dashboards.cube-query · negative[2]

  4. objectstack-fleet commented on Nov 20, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7

    Claim: PM loop round 2
    Session: session_01L9qibwJEh7hMPPvagWM1g7
    Account: os-tesla
    Branch: claude/issue-33840-analytics-empty-projection
    Worktree: objectstack-issue-33840
    Domain: domain:server
    Seat: repo:objectstack#7
    Area: d7-B
    File surface: packages/runtime/src/domains/analytics.ts, a new test beside analytics-empty-cube-refusal.test.ts, one changeset under .changeset/ (stop on breach; explain in the report)
    Container & model: S, mode:subagent, model: default, effort: medium
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack platform: packages/runtime/src/domains/analytics.ts assertAnalyticsQueryBody forwards an empty projection and the engine runs SELECT FROM | none | any client posting /api/v1/analytics/query with no measures and no dimensions
    Thread-read: 6946115523
    Premise: holds (origin/main c321914: assertAnalyticsQueryBody has no empty-projection rule; QA reproduced the 500)
    Serial constraints cleared: no open PR touches the named files (premise read of all open PRs by card number, 2026-11-20T05:10Z; overlap-check runs before each push)
    Pre-claim lane: repo:objectstack seat 7 area d7-B; files are domain:server; no skills/**, docs/adr/**, packages/spec/src/** or workflow path
    Pre-claim deps: no Blocked-by:
    Prior rulings read: card thread and linked cards read in full: no maintainer ruling on this card; route is the card's own ask

  5. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 20, 2026
  6. objectstack-fleet commented on Nov 20, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7
    os-dev-report

    {
      "issue": 33840,
      "status": "done",
      "branch": "claude/issue-33840-analytics-empty-projection",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/35771",
      "head": "d8fc05159ae1f75ea8ecb71e9eaf10ae72830cb0",
      "session": "session_01L9qibwJEh7hMPPvagWM1g7",
      "premise_still_valid": true,
      "summary": "assertAnalyticsQueryBody (packages/runtime/src/domains/analytics.ts) now refuses, after a successful schema parse, a query selecting no measure, no dimension and no timeDimensions entry with a granularity: 400 VALIDATION_FAILED, one fields[] entry {field: measures, code: min_items} with a select-at-least-one-measure-or-dimension message; the body is otherwise forwarded untouched. /analytics/sql calls the same function, so its SELECT-FROM echo is covered with no extra code. A bucketed time dimension counts as a projection (ObjectQL strategy groups by it) so a granularity-only query is not newly refused. Existing codes only; no spec edit.",
      "tests": "new packages/runtime/src/analytics-empty-projection-refusal.test.ts (both doors: 3 refusal shapes assert status 400 + error.code VALIDATION_FAILED + httpStatus + field measures/min_items + service never called; ApiErrorSchema parse; 3 preservation controls incl. one measure no dimension). At d8fc05159a: new file + empty-cube sibling 'Test Files 2 passed (2) / Tests 24 passed (24)', lock VERDICT command-exit 0. At 5aeaf5975c: pnpm --filter @objectstack/runtime test 'Test Files 633 passed (633) / Tests 11669 passed | 25 skipped', VERDICT command-exit 0 (first attempt hit the 590s timeout, exit 124, rerun under nohup); typecheck exit 0. Ablation (fix committed; scripts/ablation-replace.mjs --delete of the call line, anchor 1->0, blob 2fa8f9336->614cfcb88; test imports runtime via relative src, no dist leg needed): 'Tests 8 failed | 6 passed (14)' = all refusal+envelope cases red, preservation green; restore blob==HEAD, git diff HEAD empty. This is also the door-level reproduction; live 500 not re-booted (see deviations).",
      "gates": "dispatch-gates --commands derived 68 families (tree 5aeaf5975c); all 68 run locally with exit codes; --ran reconciliation: '68 derived famil(ies) accounted for, 68 run, 0 NOT-MEASURED (a DERIVED zero)'. check:dual-build-cjs-loads exit 3 PREREQUISITE NOT MET first, exit 0 after the type-check-debt re-measure built the tree; check:test-source-alias exit 1 on the new test (metadata load in a clocked window) -> fixed by module-top import, exit 0 at d8fc05159a with cross-package-test-inputs, nul-bytes, tier-file-adoption, issue-citations, doc-authoring re-run exit 0. overlap-check VERDICT clean exit 0 before each push. PR check-runs at d8fc05159a: in_progress at report time (Check Changeset, Lint x8, Type Check x4, Governed Surface Queue Guard, PR-body guards); Test Core/Build Core not yet listed. CI owns the farm.",
      "dogfood_battery": "n/a — no ! in the PR title and Clause-②: no without a (narrowing) arm",
      "mcp_calls": "0",
      "api_writes": "2 — fleet-write relay pr_create (POST /repos/objectstack-ai/objectstack/pulls + POST issues/35771/assignees), os-dev-report comment via post-stamped (POST /repos/objectstack-ai/objectstack/issues/33840/comments); git push not counted",
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: none · noted, not filed — service-analytics native-sql-strategy still assembles an empty SELECT list for an in-process caller that bypasses the runtime door (the card's route is the door; engine-side guard not added)"
      ],
      "line_budget": "n/a — no skills/** or ratcheted ledger touched",
      "deviations": [
        "live showcase reproduction not re-run in this session; relied on the card thread's six live readings at f6f5b50a plus the door-level ablation",
        "new test file rather than a describe in the sibling harness file: the claim's file surface names 'a new test beside analytics-empty-cube-refusal.test.ts'; the sibling's harness is file-local, not a shared harness module",
        "runtime full test and most gates ran at 5aeaf5975c; the last commit only adds a module-top side-effect import to the new test, after which that file and the test-file-reading gates were re-run at d8fc05159a",
        "PR body ends with the AGENTS.md session-URL footer form rather than the harness reminder's footer (AGENTS.md takes precedence)"
      ],
      "files_changed": [
        ".changeset/33840-analytics-empty-projection.md",
        "packages/runtime/src/analytics-empty-projection-refusal.test.ts",
        "packages/runtime/src/domains/analytics.ts"
      ]
    }
  7. objectstack-fleet commented on Nov 20, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7

    Claim amendment · 2026-11-20T06:45Z · PR #35771 (L1 REWORK 7032561531)

    • Clause-②, re-declared: Clause-②: no (narrowing). AnalyticsQuerySchema admits measures: [] with no minimum, and /analytics/sql answered such a body with 200 before this PR. This follows the dataset-door twin fix(service-analytics)!: query_dataset refuses a selection that names no measure, as the REST dataset door does #33141, which was declared the same way. On the final head the PR owes: ! in the title and on the changeset subject, the ADR-0087 disposition, a Skills-docs: none line, the full dogfood battery pinned to the head, and a CONTRACT_REVIEW_TIER L2. Landing goes to the seat.
    • Native SQL strategy for an in-process caller (L1 point 5): not filed. No reachable in-process caller that skips both doors has been shown, so it does not pass the filing business test today.
  8. objectstack-fleet commented on Nov 20, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7
    os-dev-report

    {
      "issue": 33840,
      "status": "done",
      "branch": "claude/issue-33840-analytics-empty-projection",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/35771",
      "head": "806d7f5bd1440ecfaa89f00092f4e511c82404e8",
      "session": "session_01L9qibwJEh7hMPPvagWM1g7",
      "premise_still_valid": true,
      "summary": "Patch round 1 (L1 REWORK 7032561531, claim amendment 7032571818): the change is re-declared as a narrowing of a published accept set, with no code or test change since d8fc05159a. The changeset now has the `!` subject fix(runtime)!:, the line Clause-②: no (narrowing), a BREAKING banner with the FROM/TO and the caller's one-line fix, and the ADR-0087 disposition not-required (no-migration-prescription). The PR title and body were changed through relay issue_patch: the title now has `!`, the body has Clause-②: no (narrowing), Skills-docs: none, a BREAKING note in the 速读 risk line and in What changes, the dogfood reading, and the signed trailer as the last line. Unchanged from round 0: assertAnalyticsQueryBody refuses a query with no measure, no dimension and no bucketed timeDimension with 400 VALIDATION_FAILED at measures/min_items on both /analytics/query and /analytics/sql.",
      "tests": "new packages/runtime/src/analytics-empty-projection-refusal.test.ts (both doors: 3 refusal shapes assert status 400 + error.code VALIDATION_FAILED + httpStatus + field measures/min_items + service never called; ApiErrorSchema parse; 3 preservation controls incl. one measure no dimension). At d8fc05159a: new file + empty-cube sibling 'Test Files 2 passed (2) / Tests 24 passed (24)', lock VERDICT command-exit 0. At 5aeaf5975c: pnpm --filter @objectstack/runtime test 'Test Files 633 passed (633) / Tests 11669 passed | 25 skipped', VERDICT command-exit 0 (first attempt hit the 590s timeout, exit 124, rerun under nohup); typecheck exit 0. Ablation (fix committed; scripts/ablation-replace.mjs --delete of the call line, anchor 1->0, blob 2fa8f9336->614cfcb88; test imports runtime via relative src, no dist leg needed): 'Tests 8 failed | 6 passed (14)' = all refusal+envelope cases red, preservation green; restore blob==HEAD, git diff HEAD empty. This is also the door-level reproduction; live 500 not re-booted (see deviations). Round 1: no code or test change, so the round-0 readings stand for those files.",
      "gates": "Round 1 at 806d7f5bd1. node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 ('1 declared-breaking changeset(s), each carrying an ADR-0087 disposition', classified BREAKING+bang+clause-②-narrowing, not-required (no-migration-prescription)). pnpm check:adr-0087-registration :: exit 0. node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 ('This diff introduces no `major` bump'). Before the commit, the ADR-0087 gate read the uncommitted changeset as non-breaking; it was re-run after the commit. Also exit 0: check-empty-changeset --base origin/main, check-closing-keyword-parity, pnpm check:doc-authoring, check:nul-bytes, check:issue-citations, check:changeset-gate-self-tests. Skills-docs evidence: git grep for analytics/query, analytics/sql, 'measures: []' and dimension-only over skills/ gave 0 hits; control leg: 'measures' hits 7 files under skills/. overlap-check gave VERDICT clean exit 0 before the push. Round-0 derived families (68/68 reconciled) carry over, because the code and test files are byte-unchanged. PR check-runs at 806d7f5bd1 that succeeded: Lint & Repo Gates, TypeScript Type Check, Test Core (10/10 shards and the aggregate), Build Core, Governed Surface Queue Guard, Dogfood Regression Gate, Live E2E UI, Test UI, all Lint and Type Check sub-jobs, Flag docs affected by code changes. Re-running after the body patch: Check Changeset and PR-body guards, in_progress (earlier runs on this head were success). Skipped by selector: Lint UI, Type Check UI, Build & E2E UI.",
      "dogfood_battery": "806d7f5bd1 · closure build under the lock gave VERDICT command-exit 0, then pnpm --filter @objectstack/dogfood test with no OS_TEST_SHARD and no path gave VERDICT command-exit 0 (held the lock 28m25s) · Test Files 482 passed | 3 skipped (485) · Tests 4094 passed | 68 skipped (4162) · no failure. HEAD was checked before and after the run: 806d7f5bd1 both times.",
      "mcp_calls": "0",
      "api_writes": "4 in total over both rounds. Round 0: pr_create (POST /repos/objectstack-ai/objectstack/pulls + POST issues/35771/assignees) and the os-dev-report comment (POST issues/33840/comments, 7032155468). Round 1: issue_patch (PATCH /repos/objectstack-ai/objectstack/issues/35771, title + body; read-back 7821 bytes sent, 7821 stored, identical) and this os-dev-report comment (POST issues/33840/comments). git push is not counted.",
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: none · noted, not filed — the native-sql-strategy empty SELECT list for an in-process caller is the area's call (claim amendment 7032571818: not filed, because no reachable caller that skips both doors has been shown)"
      ],
      "line_budget": "n/a — no skills/** or ratcheted ledger touched",
      "deviations": [
        "The live showcase 500 was not re-booted. The evidence is the card thread's live readings at f6f5b50a plus the door-level ablation.",
        "Round 1: the worktree was re-created from origin/claude/issue-33840-analytics-empty-projection at d8fc05159a. The branch was not merged with main; overlap-check reports that it merges cleanly with origin/main c4a73be6be.",
        "The CONTRACT_REVIEW_TIER L2 named by the L1 and the amendment is the seat's to run, so this dev did not run it.",
        "The dogfood test step lost the lock queue twice (VERDICT queue-timeout exit 99, slot kept). It was re-acquired in the same foreground wait loop; no narrowing.",
        "Commit 806d7f5bd1's subject carries `!` (chore(changeset)!:). It is not the PR title. Its trailers are model-free."
      ],
      "files_changed": [
        ".changeset/33840-analytics-empty-projection.md",
        "packages/runtime/src/analytics-empty-projection-refusal.test.ts",
        "packages/runtime/src/domains/analytics.ts"
      ]
    }
  9. objectstack-fleet commented on Nov 20, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7
    os-dev-report

    {
      "issue": 33840,
      "status": "done",
      "branch": "claude/issue-33840-analytics-empty-projection",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/35771",
      "head": "d22928425cfe2a262b74fcce52bead222f7edc84",
      "session": "session_01L9qibwJEh7hMPPvagWM1g7",
      "premise_still_valid": true,
      "summary": "Patch round 2 (L2 PASS 7034308588: S1 should-fix, N1 nit; both taken). S1: the changeset banner's FROM now names the engine refusals that this door's 400 at `measures` replaces. Each was first measured on AnalyticsService at this head with a scratch test (deleted, not committed), on both query and generateSql under both the native SQL and the ObjectQL strategy. Unknown cube and public:false cube: 404 CUBE_NOT_FOUND. A cube over an object the caller may not read: 403 PERMISSION_DENIED. An order key naming no selected member: 400 INVALID_FIELD. All three hold. The measurement also found one more prior answer, now named too: on an ObjectQL-served deployment, /analytics/query answered a 200 with one columnless row. The PR body's BREAKING paragraph says the same, through relay issue_patch. N1: the pin file gains a precedence describe on both doors: an unknown cube with an empty projection gets the 400 and never reaches a stub engine that 404s it; a control shows the same cube with one measure reaches the engine and gets the 404; and where/order/limit with an empty projection are still refused. analytics.ts is unchanged.",
      "tests": "Round 2 at d22928425c: pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/analytics-empty-projection-refusal.test.ts gave 'Test Files 1 passed (1) / Tests 20 passed (20)', VERDICT command-exit 0. pnpm --filter @objectstack/runtime typecheck: VERDICT command-exit 0 (tsc and check:test-typecheck OK). Ablation, run through the lock (scripts/ablation-replace.mjs --delete of the guard call; anchor 1->0, blob 2fa8f9336->614cfcb88): 'Tests 12 failed | 8 passed (20)'. The 12 red were every refusal, envelope and precedence case on both doors; the 8 green were the 6 preservation cases and the 2 404 controls. Restore: blob==HEAD and git diff HEAD empty. The engine-side readings came from a scratch service-analytics test that was deleted afterwards ('Tests 20 passed (20)', a logging probe only). Round-0 and round-1 readings stand for the unchanged analytics.ts.",
      "gates": "Round 2 at d22928425c. dispatch-gates --commands derived the same 68 families as round 0. 66 ran, all exit 0, including check-adr-0087-registration --base origin/main, check-changeset-no-major --base origin/main, check-empty-changeset, check:test-source-alias, check:cross-package-test-inputs and check:nul-bytes. --ran reconciliation: '68 derived, 66 run, 0 NOT-MEASURED, 2 UNRUN' (exit 1). The 2 UNRUN, check:type-check-debt and check:dual-build-cjs-loads, were left out on purpose: they need a full-tree build that this re-created worktree lacks, and they read built output and type debt that a test-file and changeset change does not move. CI runs both. pnpm --filter @objectstack/runtime typecheck exit 0. overlap-check VERDICT clean exit 0 before the push. PR check-runs at d22928425c at report time: success for Governed Surface Queue Guard, Dogfood Regression Gate, Test UI, Check PR Size, one PR-body guards run; in_progress for Build Core, Check Changeset, every Lint and Type Check sub-job, Live E2E UI, Plan Test Core shards (Test Core not yet listed).",
      "dogfood_battery": "806d7f5bd1 (not re-run at d22928425c: per the round-2 order, the battery is owed only when analytics.ts changes, and it did not) · VERDICT command-exit 0 · Test Files 482 passed | 3 skipped (485) · Tests 4094 passed | 68 skipped (4162) · no failure",
      "mcp_calls": "0",
      "api_writes": "6 in total over three rounds. Round 0: pr_create (POST /repos/objectstack-ai/objectstack/pulls + POST issues/35771/assignees) and comment 7032155468. Round 1: issue_patch PATCH /repos/objectstack-ai/objectstack/issues/35771 (title + body) and comment 7034217880. Round 2: issue_patch PATCH /repos/objectstack-ai/objectstack/issues/35771 (body; 10071 bytes sent, 10071 stored, identical) and this os-dev-report comment (POST issues/33840/comments). git push is not counted.",
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: none · noted, not filed — the native-sql-strategy empty SELECT list for an in-process caller is the area's call (claim amendment 7032571818: not filed, because no reachable caller that skips both doors has been shown)"
      ],
      "line_budget": "n/a — no skills/** or ratcheted ledger touched",
      "deviations": [
        "The live showcase 500 was not re-booted. The engine-side refusals were measured in-process on AnalyticsService instead.",
        "Round 2 re-created the worktree from the remote branch at 806d7f5bd1, with no main merge (overlap-check clean).",
        "2 derived families (check:type-check-debt, check:dual-build-cjs-loads) were not run locally in round 2: they need a full-tree build and their inputs did not move. Declared here; CI runs them.",
        "The dogfood battery was not re-run on d22928425c, because analytics.ts is unchanged (the round-2 order allows this).",
        "The scratch engine-measurement test was written under packages/services/service-analytics/src/__tests__ and deleted before the commit (git status clean). It is outside the claim's file surface and was never committed.",
        "The CONTRACT_REVIEW_TIER L2 delta for the new head is the seat's."
      ],
      "files_changed": [
        ".changeset/33840-analytics-empty-projection.md",
        "packages/runtime/src/analytics-empty-projection-refusal.test.ts",
        "packages/runtime/src/domains/analytics.ts"
      ]
    }
  10. objectstack-fleet commented on Nov 20, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7

    Delivered · 2026-11-20T12:24Z

    PR #35771 merged as 4c2d8d7 after the maintainer queued it. POST /api/v1/analytics/query and /analytics/sql now answer 400 VALIDATION_FAILED (measures, min_items) to a schema-valid body that selects no measure, no dimension and no time dimension with a granularity. Before this, that body got a 500, a 200 echo or an engine refusal. This is a declared narrowing, and the changeset names each FROM. Closed by Fixes; pm:dispatched removed.

  11. removed
    pm:dispatched
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:databugdomain:serverpriority:p3

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions