Skip to content

fix(analytics): an empty or blank where key answers 400 INVALID_FIELD on all three analytics doors - #38218

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35543-analytics-empty-where-key
Nov 28, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35543-analytics-empty-where-key

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #35543

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:通过接口或 AI 助手做统计查询时,筛选条件里写了空的或只有空格的字段名,现在会直接得到「字段名无效」的明确提示,不再报服务器内部错误或无权限。
  • 为什么做:让统计查询对这种写错的请求和普通数据查询给出同一种答复,调用方能看懂错在哪里。
  • 出错会怎样:最坏情况是某个本来能用的统计筛选被误拒,调用方会看到明确的拒绝提示;改动只有一处检查,可以直接撤回。
  • 要你做什么:无。

What changes

An empty filter key ({"": "z"}) on POST /api/v1/analytics/query, as the dataset runtimeFilter on POST /api/v1/analytics/dataset/query, and through MCP query_dataset reached SQLite as WHERE = ? and answered 500 DATABASE_ERROR. A blank key (" ") answered 403 PERMISSION_DENIED from the field-read gate. Both now answer 400 INVALID_FIELD (field, param: 'where'), as /data answers the same body. The engine is never reached.

The mechanism: every analytics gate passes the empty key by. namedQueryFields skips member === '' outright, and resolveMemberSource answers source: null (a stand-down) for any spelling that is not a bare identifier. So nothing judged it before the strategy compiled it. The fix is one check, assertWhereMemberIsFieldName, at the top of the where source-field gate (assertWhereFields, #5669). That gate runs on every path out of ensureCube and on the dataset draft-preview path, so all three doors share it. The check needs no field probe. It runs before the gate's three probe stand-downs, because no object has a field with an empty name.

/data's validator (assertFilterFieldsExist, @objectstack/metadata-protocol) is not reused. It answers "is this a field of the object". The analytics question is "does this member resolve to a column", and the existing where gate already asks it in the analytics vocabulary (cube members, the cube qualifier, relationship paths). Taking a dependency on the protocol package for an emptiness check would add a second reader of the filter tree.

Deliberately narrow: only whitespace-only keys. A key that is text but no column reference (amount + 1, foo bar) keeps the #21156 member-shape gate's PERMISSION_DENIED / 403. That verdict is pinned "in every tier" by caller-member-column-reference-gate.test.ts, which this PR's first, wider draft turned red (8 cases). Changing that verdict is a contract question and is out of scope here.

Tests

src/__tests__/where-member-field-name-35543.test.ts uses the plugin-wired service (AnalyticsServicePlugin over an engine double), with all three doors called as their callers call them: service.query, service.queryDataset and datasetTools().queryDataset.

Ablation through scripts/ablation-replace.mjs, which deleted the gate's call line (anchor 1 to 0, restored blob == HEAD, git diff HEAD empty). 10 failed, 1 passed (the control). The red set was every refusal case on all three doors.

Live re-measure on the stock showcase (--fresh, admin), before at 7605e0c9c and after at c79abcb26:

body before after
/analytics/query where {"": "z"} 500 DATABASE_ERROR 400 INVALID_FIELD
/analytics/dataset/query runtimeFilter {"": "z"} 500 DATABASE_ERROR 400 INVALID_FIELD
MCP query_dataset runtimeFilter {"": "z"} isError DATABASE_ERROR / 500 isError INVALID_FIELD / 400
the same three with {" ": "z"} 403 PERMISSION_DENIED 400 INVALID_FIELD
CONTROL {"status": "paid"} on all three 200 200
/data/showcase_invoice/query where {"": "z"} 400 INVALID_FIELD 400 INVALID_FIELD
Package run at c79abcb

pnpm --filter @objectstack/service-analytics typecheck && … build && … test under the verify lock: VERDICT command-exit 0, Test Files 228 passed (228), Tests 5914 passed | 345 skipped (6259). tsc --listFiles includes the new test file.

Acceptance notes

Verification

Read first: assertWhereMemberIsFieldName and its call at the top of assertWhereFields (packages/services/service-analytics/src/analytics-service.ts). The risk hunk is the move of the three probe stand-downs below the member collection. The second file is the new test.

Two-minute check: pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/where-member-field-name-35543.test.ts. Expect 12 passed.

Gates at c79abcb26: dispatch-gates --ran accounts for 71 derived families. 69 ran with exit 0. 2 are NOT MEASURED (exit 3, prerequisite not met): check:dual-build-cjs-loads needs a full workspace build, and check:type-check-debt could not get a turn on the verify lock. CI runs both.


Generated by Claude Code

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/service-analytics, touching 5 documentable anchor(s).

42 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 e42520c67bcef027552f8db83655ff9b54d32cef.

⛔ 12 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: created_at (literal, 49 pages)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 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; 124 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 — 10 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 e42520c67bcef027552f8db83655ff9b54d32cef → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json e42520c67bcef027552f8db83655ff9b54d32cef

⚠️ 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 e42520c67bcef027552f8db83655ff9b54d32cef → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@github-actions github-actions Bot added 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 28, 2026
The changeset claimed every key that names no field (`foo bar` included)
now answers 400, and stated an identifier rule for every key. The tree
refuses only empty and whitespace-only keys; non-identifier text keeps
the #21156 403. Prose only.

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack#8 · sunhaolin · session_017xRBcSAaBEfQpU2yJexSJ8

L1: ACCEPT · head 45e72db154 · 2026-11-28T10:55Z · card #35543

Seat checks

  1. Shape: draft on main, mergeable_state clean, first line Fixes #35543 only, Clause-②: no · Metadata-protocol: none. Fixes is right. The card's Expected section asks for exactly "400 INVALID_FIELD at the analytics entry for an empty or blank filter key", and that is delivered.
  2. First L1 round (head c79abcb2) found one prose defect: the changeset claimed that "foo bar" now answers 400 and that "a key is a field name when it is an identifier…", while the code refuses only member.trim() === ''.
  3. Read by the seat: assertWhereMemberIsFieldName runs at the top of assertWhereFields, before its probe stand-downs. That gate is on every ensureCube path and on the dataset preview path, so all three doors share it.
  4. Gates at this head: 37 success · 16 expected skip · 0 failed · 0 pending; Lint & Repo Gates and TypeScript Type Check success. NOT governed. K = 10 < 15. L2 not owed: Clause-②: no, no schema or governed path, no narrowing arm. This is a 500 / 403 → 400 correction that refuses nothing a valid body sends.

Landing: non-governed, ≤3000 lines. The seat lands it through the ordinary queue.

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

2 participants