Skip to content

Commit e71ecc1

Browse files
docs(skills): teach that a column with no value fails an ordering filter, and where a per-measure filter runs (#34014)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9NXd2SJ1z5XQzawbhD1qEaF)_ Fixes #33868 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:查询技能新增一条规则「没有值的列(null 或缺失)不满足任何大小比较(`$gt/$gte/$lt/$lte/$between`)」,并改正了「带 filter 的度量一定走内存」这句已过时的话(声明 `aggregationFilter` 的驱动在数据库里算),另加一条评测用例。 - 为什么改:#33854 已改变运行时行为;不教的话,作者和 AI 会以为 `amount $lte 0` 也会把没填金额的记录算进去,仪表盘上的数字会被误读,且技能还在说一句已经不成立的话。 - 风险与回滚:只改技能文档、一条 eval 和一个 changeset,不动运行时代码;回滚即 revert 本 PR。 - 先看:`skills/objectstack-query/rules/aggregation.md`(Filtered Aggregation 提示块,措辞最接近契约承诺)→ `rules/filters.md`(新规则一节,以及为付账删掉的两处重复)→ `evals/filters-pagination-search.json` 第 8 条。 - 两分钟验证:`node scripts/check-skills-token-ratchet.mjs`,预期全绿,filters.md 显示 `2473 / 2473`、aggregation.md 显示 `2264 / 2357`。 - 需要你做的:批准本 draft(受管面 Tier H)。 ## What changes The query skill now teaches two things PR #33854 made true, and drops one sentence it made false. `skills/objectstack-query/rules/filters.md` (published, English): - **New section "A column with no value fails every ordering test"** (it replaces "Prefer `$null` to a bare `null` comparand", whose rule is kept as its last sentence): `$gt` / `$gte` / `$lt` / `$lte` / `$between` never match a row whose column is null or absent, in `where`, an aggregation's `filter` and `having` alike; `{ amount: { $lte: 0 } }` skips the rows with no amount, and an `$or` with `{ amount: { $null: true } }` keeps them. `null` is not an ordering comparand (`{ $gte: null }` is refused `INVALID_FILTER` / 400). - **Paid for in the same file** by two restatements: the case-sensitivity paragraph, whose rule `SKILL.md` § String Operators carries ("compare CASE-SENSITIVELY; `$icontains` is the case-INSENSITIVE twin (ASCII folding only)"), now a one-line pointer; and the second Date example (`$between` over two `Date`s), whose home is the operator table's `$between` row plus the `$gte: new Date(…)` example kept directly above it. Lost with no home: the `café` / `CAFÉ` illustration of ASCII-only folding (the rule survives in SKILL.md). `skills/objectstack-query/rules/aggregation.md`: - **§ Filtered Aggregation:** the callout no longer says any filtered measure "forces the in-memory path — no driver compiles a conditional aggregate, and one reached directly refuses `NOT_IMPLEMENTED`". A driver that declares `supports.aggregationFilter` (`driver-sql`; `driver-turso` outside remote mode) runs the filter in the database whenever the aggregate itself is pushed down (a date bucket under a non-UTC `timezone`, or a granularity the driver does not bucket natively, keeps the whole call in memory: `tzRequiresInMemory` and `allStructuredSupported` sit in the same route condition), compiled as that datasource's `where` is: it answers what the same condition answers there (text by the database collation) and is refused where it is (the pinned case: a `{ $field }` comparison on a column the object does not declare, `INVALID_FILTER` / 400). On any other driver the engine reads the scoped rows and evaluates the filter itself; no answer is promised beyond that. A column with no value fails its ordering tests either way. - **§ HAVING:** `avg` / `min` / `max` over no values is `null`, so `having: { average: { $lte: 0 } }` drops that group. `skills/objectstack-query/evals/filters-pagination-search.json`: case 8, one aggregate call returning the total and the count of deals whose `amount` is zero or less, where a deal with no amount must count. `must_contain`: `filter`, `$or`, `$lte: 0`, `$null: true`; `must_not_contain` is empty, so no correct answer that restates the rule can trip it. Spliced with the file's hand formatting kept. `skills/objectstack-ui/rules/dashboards.md` is untouched: it never states how a measure filter is evaluated (it only lists "measure-scoped filters" as fitting a dataset). `.changeset/33868-skills-no-value-ordering-measure-filter.md`: `'@objectstack/skills': patch`. Every taught fact is read from origin/main at or after `0ac112fc`: - `packages/objectql/src/having-filter.ts`: `NULL_IS_NOT_ORDERED_OPERATORS = new Set(['$gt', '$gte', '$lt', '$lte', '$between'])`; in `checkCondition`, `if (value === undefined && !NO_VALUE_ANSWERED_BY_OPERATOR.has(op)) return false;` then `if (value === null && NULL_IS_NOT_ORDERED_OPERATORS.has(op) && !orderingComparandHoldsNull(op, target)) return false;`. Pinned by `having-filter-null-ordering.test.ts` (each face, and the empty-group `having`) and `packages/rest/src/aggregate-measure-filter-pushdown.test.ts` ("a NULL amount fails an ordering filter on both paths"). - `packages/spec/src/data/filter.zod.ts` ("null is NOT a comparand: null is not ordered — state absence with the null predicate instead") and `filter-comparand-shape.ts` (`nullOrderingComparandError`, `INVALID_FILTER` / 400). - `packages/objectql/src/engine-delete-and-aggregate.ts`: `const aggregationFilterNative = drv?.supports?.aggregationFilter === true;` and the `(!hasAggregationFilter || aggregationFilterNative)` route condition. - `packages/drivers/driver-sql/src/sql-driver.ts` (`aggregationFilter: true`); `packages/drivers/driver-turso/src/turso-driver.ts` (`aggregationFilter: false` in remote mode); `packages/spec/src/data/driver.zod.ts` (the bit's describe text: text compares by the backend collation as in `where`). - `packages/rest/src/aggregation-filter-where-doors.test.ts`: the `where` twin and the per-aggregation filter of `{ created_at: { $ne: { $field: 'photo' } } }` on an audit-opt-out object both answer `{ status: 400, code: 'INVALID_FILTER' }` on driver-sql. ### Size readings (tree objectstack-ai/objectstack, origin/main bc6b7ff → head d47493b) | Reading | Before | After | |:--|--:|--:| | `rules/filters.md` lines / bytes / tokens | 211 / 9925 / 2482 | 209 / 9892 / 2473 (row re-locked 2482 → 2473 at the measurement) | | `rules/aggregation.md` lines / bytes / tokens | 262 / 8381 / 2096 | 270 / 9053 / 2264 (ceiling 2357, row unchanged) | | `evals/filters-pagination-search.json` lines / bytes / tokens | 75 / 5464 / 1366 | 85 / 6422 / 1606 (eval fixture, measured, not ratcheted) | | All 11 `skills/*/SKILL.md` lines | 4596 | 4596 (none touched) | | Whole bundle, ratcheted (authored) tokens / ceilings | 187685 / 194017 | 187844 / 194008 (+159 / -9) | | Whole bundle, eval fixtures tokens | 46508 | 46748 (+240) | | Whole bundle total tokens | 245988 | 246387 (+399) | `scripts/check-skills-token-ratchet.mjs`: the `filters.md` row is re-locked at its measured 2473 (review N3), with the arithmetic and each cut's home in the row comment; no other row moves. ## Tests No code changed, so there is nothing to ablate. Gate readings are under Verification. ## Acceptance notes - **Build tier, declared:** `dispatch-gates --tier` puts `skills/**` at the contract-review tier (clause ①). This card thread is served below it and cannot switch its own model, so (as the claim records) the authoring and the commit ran in an isolated os-dev subagent pinned to the contract-review tier inside this worktree; the merge of main, relay writes, gates and report ran in the thread. - **Not taught, on purpose:** what `$ne` / `$nin` / `$notContains` answer on a column with no value (each answers a column with no value by its own arm, `NO_VALUE_ANSWERED_BY_OPERATOR`). It is a standing rule this card did not change; the card's list of unchanged operators also omits `$empty`, which the code keeps in the same set. - **Refusal wording:** the skill names only the pinned refusal case. A plain undeclared key (`{ nope: 1 }`) answers `INVALID_FIELD`, not `INVALID_FILTER`, on both positions (row 4 of `aggregation-filter-where-doors.test.ts`), so "undeclared column ⇒ `INVALID_FILTER`" is not written bare. - **NOT MEASURED:** `driver-mongodb` own `where` on a null column with `$lte` (no pin read; it rests on BSON type bracketing). `driver-memory` own `find` is pinned by `memory-matcher-null-value-and-comparand.test.ts` (#13553), per review 6897568297. - Review round 1 (record 6897568297): S1 (pushdown clause), N1 ("no values") and N3 (row re-lock) taken in one commit, `b87277b6`, authored at the contract-review tier like the first; N2 left as is. - Main was merged before each gate run (`a7754819`, `d47493ba`) so the derivation read a current tree. ## Verification All readings are at head `d47493ba` (`git rev-parse --short HEAD` after the last commit), tree objectstack-ai/objectstack. - Package build closure: `turbo run build --concurrency=2 --filter='./packages/**'` under `os-verify-lock.sh`, `VERDICT command-exit 0` (held 5m35s, after the first merge; the second merge touched only `scripts/pm/**` and `.claude/**`, nothing built). - Acceptance gates: `check:skill-docs` ✅ "Skill docs in sync"; `check:skill-refs` ✅ "9 generated files in sync with packages/spec"; `check:skill-examples` ✅ "346 prose examples type-check across 3 surface(s)"; `check-skills-token-ratchet` ✓ "57 authored bundle file(s) within their ceilings", rows `2473 / 2473` and `2264 / 2357`. - `dispatch-gates --ran`: "63 derived famil(ies) accounted for — 63 run, 0 NOT-MEASURED (a DERIVED zero)" (63, not 45: the ratchet script is now in the diff, so its families and `check:pm-dispatch-gates` are derived). Three extra runs are recorded outside the derivation (`check:skill-docs`, `check:skill-refs`, `check:skill-examples`). - CI families outside the derived list are left to this PR's check-runs. <details><summary>Derived gate list, 63 + 3, exit codes captured before any pipe</summary> ```text node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-declaration-mirrors.mjs :: exit 0 node scripts/check-declaration-mirrors.mjs --self-test :: exit 0 node scripts/check-doc-route-spelling.mjs --advisory :: exit 0 node scripts/check-doc-route-spelling.mjs --self-test :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-self-test-wired.mjs :: exit 0 node scripts/check-self-test-wired.mjs --self-test :: exit 0 node scripts/check-self-test-workflow-commands.mjs :: exit 0 node scripts/check-self-test-workflow-commands.mjs --self-test :: exit 0 node scripts/check-skills-token-ratchet.mjs :: exit 0 node scripts/check-skills-token-ratchet.mjs --self-test :: exit 0 node scripts/check-whole-set-label-write.mjs :: exit 0 node scripts/check-whole-set-label-write.mjs --self-test :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/pm/bare-root-worklist.mjs --self-test :: exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0 pnpm check:agent-test-spelling :: exit 0 pnpm check:bash32-floor :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:cli-command-ids :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:corpus-claim-drift :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:entry-guard :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:parse-guard :: exit 0 pnpm check:pm-dispatch-gates :: exit 0 pnpm check:pm-governed-merges :: exit 0 pnpm check:pm-skill-id-lint :: exit 0 pnpm check:pnpm-filter-targets :: exit 0 pnpm check:pnpm-flag-spellings :: exit 0 pnpm check:published-files :: exit 0 pnpm check:ratchet-remedy-authority :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:role-word :: exit 0 pnpm check:scripts-symbol-anchors :: exit 0 pnpm check:skill-compatibility :: exit 0 pnpm check:skill-frame-sync :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:skill-links :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm --filter @objectstack/spec check:skill-docs :: exit 0 pnpm --filter @objectstack/spec check:skill-refs :: exit 0 pnpm --filter @objectstack/spec check:skill-examples :: exit 0 ``` </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmQokeaWJKGm2S7ZrDA)_ <!-- signed: domain:skills#2 · os-steve · session_01ADHkmRxXmVQ41fqnaTPGAv --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1b9c73a commit e71ecc1

5 files changed

Lines changed: 54 additions & 22 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): the query skill teaches that a column with no value fails an ordering filter, and where a per-measure filter runs
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
objectstack-query's `rules/filters.md` gains the rule that `$gt` / `$gte` / `$lt` / `$lte` / `$between` never match a row whose column is null or absent, in `where`, an aggregation's `filter` and `having` alike, with the `$or` + `$null: true` spelling that keeps those rows; the same section says `null` is not an ordering comparand. `rules/aggregation.md` no longer says a per-measure `filter` always forces the in-memory path: a driver that declares `supports.aggregationFilter` (`driver-sql`; `driver-turso` outside remote mode) runs it in the database, where it answers and is refused as the same condition is in that datasource's `where`, text collation included; on any other driver the engine evaluates it over the scoped rows. Its `having` section says `avg` / `min` / `max` over no rows is `null` and so fails an ordering test. One eval case covers the rule in a measure filter. Two restatements in `filters.md` were removed to pay for the new text: the case-sensitivity paragraph SKILL.md § String Operators carries, and a second `$between` example.

‎scripts/check-skills-token-ratchet.mjs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,13 @@ export const CEILINGS = new Map([
10851085
// file restates another). Maintainer ruling 2026-10-27 on the decision card
10861086
// 「skills 修复卡的教学和 eval 都撞 token 天花板,怎么付?」, tap A, verbatim and
10871087
// untranslated: 「A:先削重复,余额按实测提高」.
1088-
['skills/objectstack-query/rules/filters.md', 2482],
1088+
// 2482 -> 2473: re-locked AT the measurement after the no-value ordering
1089+
// rule (a null or absent column fails `$gt` / `$gte` / `$lt` / `$lte` /
1090+
// `$between`) was paid in-file by two restatements: the case-sensitivity
1091+
// paragraph (home: SKILL.md, String Operators) and a second `$between` Date
1092+
// example (home: the operator table's `$between` row). Arithmetic in bytes:
1093+
// 9925 -> 9892 (-33 net) -> ceil(9892 / 4) = 2473; headroom 0 tokens.
1094+
['skills/objectstack-query/rules/filters.md', 2473],
10891095
['skills/objectstack-query/rules/pagination.md', 1382],
10901096

10911097
// objectstack-ui `rules/` — the five files the #14296 item 1 split created.

‎skills/objectstack-query/evals/filters-pagination-search.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@
7070
"must_contain": ["$empty: true"],
7171
"must_not_contain": []
7272
}
73+
},
74+
{
75+
"id": 8,
76+
"prompt": "In one aggregate call on `deal`, return the total number of deals and the number whose `amount` is zero or less. `amount` is an optional number field, and a deal with no amount recorded must count as zero or less.",
77+
"expected_output": "`engine.aggregate('deal', { aggregations: [{ function: 'count', alias: 'total' }, { function: 'count', alias: 'non_positive', filter: { $or: [{ amount: { $lte: 0 } }, { amount: { $null: true } }] } }] })` — a column with no value fails every ordering test (`$gt` / `$gte` / `$lt` / `$lte` / `$between`), in a measure's `filter` as in `where` and `having`, so `{ amount: { $lte: 0 } }` alone skips the deals with no amount; the `$null: true` branch adds them. One call: the per-measure `filter` scopes only that count.",
78+
"files": [],
79+
"assertions": {
80+
"must_contain": ["filter", "$or", "$lte: 0", "$null: true"],
81+
"must_not_contain": []
82+
}
7383
}
7484
]
7585
}

‎skills/objectstack-query/rules/aggregation.md‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,23 @@ const rows = await engine.aggregate('order', {
112112
```
113113

114114
`having` filters *groups*; `where` filters the *input rows* before grouping —
115-
use `where` to shrink the scan, `having` to threshold the aggregates.
115+
use `where` to shrink the scan, `having` to threshold the aggregates. `avg` /
116+
`min` / `max` over no values is `null`, and no value fails every ordering test
117+
([filter rules](./filters.md)): `having: { average: { $lte: 0 } }` drops it.
116118

117119
## Filtered Aggregation (FILTER WHERE)
118120

119121
> ✅ **Enforced.** A per-aggregation `filter` scopes that one measure, so a
120-
> total and a conditional count share ONE call. Any aggregation carrying a
121-
> non-empty `filter` forces the in-memory path — no driver compiles a
122-
> conditional aggregate, and one reached directly refuses `NOT_IMPLEMENTED`;
123-
> unfiltered aggregations keep native push-down.
122+
> total and a conditional count share ONE call. A driver that declares
123+
> `supports.aggregationFilter` (`driver-sql`; `driver-turso` outside remote
124+
> mode) runs it in the database whenever the aggregate itself is pushed down
125+
> (a date bucket under a non-UTC `timezone`, or one the driver does not bucket
126+
> natively, keeps the whole call in memory), compiled as that datasource's
127+
> `where` is: it answers what the same condition answers there (text by the
128+
> database collation) and is refused where it is — a `{ $field }` comparison on
129+
> a column the object does not declare, `INVALID_FILTER` / 400. On any other driver the
130+
> engine reads the scoped rows and evaluates the filter itself. A column with
131+
> no value fails its ordering tests either way ([filter rules](./filters.md)).
124132
125133
<!-- os:check -->
126134
```typescript

‎skills/objectstack-query/rules/filters.md‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ Every block below is a `where` fragment, so `check:skill-examples` skips it.
2626
| Null | `$exists` | `IS NOT NULL` / `IS NULL` | `{ metadata: { $exists: true } }` |
2727
| Null | `$empty` | `IS NULL`, `''` or `[]` by type | `{ notes: { $empty: true } }` |
2828

29-
**Case sensitivity is part of the contract** (`filter.zod.ts`): "`$contains` /
30-
`$notContains` / `$startsWith` / `$endsWith` compare CASE-SENSITIVELY.
31-
`$icontains` is the case-INSENSITIVE twin" — ASCII folding only, so `café` does
32-
not match `CAFÉ`. Use `$icontains` for anything a human typed. `$like`/`$ilike`
33-
match the WHOLE value, so a pattern with no wildcard is an exact comparison, not
29+
Case sensitivity: SKILL.md, **String Operators**. `$like`/`$ilike` match the
30+
WHOLE value, so a pattern with no wildcard is an exact comparison, not
3431
a substring search. Their reach is narrower than the rest of the table: the SQL
3532
family, `driver-memory` and `@objectstack/formula` answer them, while
3633
`driver-mongodb`, objectql `having` and service-analytics each keep an operator
@@ -124,11 +121,19 @@ are. For OR, wrap them in a `$or` array (SKILL.md, **Logical Operators**).
124121
`{ age: { $contains: '25' } }` — the string operators are declared on strings
125122
only; use the comparison operators for numbers and dates.
126123

127-
### ⚠️ Prefer `$null` to a bare `null` comparand
124+
### ⚠️ A column with no value fails every ordering test
128125

129-
`where: { deleted_at: null }` works — a bare null lowers to `IS NULL` on both
130-
paths — but it reads as "equals null" and has no `IS NOT NULL` spelling. Write
131-
`{ deleted_at: { $null: true } }` instead.
126+
`$gt` / `$gte` / `$lt` / `$lte` / `$between` never match a row whose column is
127+
null or absent — in `where`, an aggregation's `filter` and `having` alike. So
128+
`{ amount: { $lte: 0 } }` skips the rows with no amount; to keep them, say so:
129+
130+
```typescript
131+
where: { $or: [{ amount: { $lte: 0 } }, { amount: { $null: true } }] }
132+
```
133+
134+
State absence with `$null`: `null` is not an ordering comparand
135+
(`{ $gte: null }` is refused, `INVALID_FILTER` / 400), and a bare
136+
`{ deleted_at: null }` lowers to `IS NULL` but has no `IS NOT NULL` spelling.
132137

133138
## Date Filtering Patterns
134139

@@ -138,13 +143,6 @@ For **ad-hoc queries in application code**, compute the date yourself:
138143
where: {
139144
created_at: { $gte: new Date('2025-01-01') }
140145
}
141-
142-
// Records within a date range
143-
where: {
144-
created_at: {
145-
$between: [new Date('2025-01-01'), new Date('2025-03-31')]
146-
}
147-
}
148146
```
149147

150148
### Date Macros (declarative filter metadata)

0 commit comments

Comments
 (0)