Skip to content

fix(service-analytics): a compareTo dataset answer fills the time buckets empty in both windows - #27213

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-1g97l3
Oct 28, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-1g97l3

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread

Fixes #27111

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:带 compareTo(同比/环比)的数据集查询,现在也会补上“两个时间段都没有数据”的时间桶:计数和求和读 0(本期列和 __compare 对照列都是),平均/最小/最大不写这个键。生产代码只删了一处:timeBucketFillPlan 里对 compareTo 的提前返回,补零沿用 Time-series charts drop empty date buckets and draw straight through them (a month with 0 revenue disappears from a 12-month trend) #26893 的同一套规则。
  • 为什么改:Time-series charts drop empty date buckets and draw straight through them (a month with 0 revenue disappears from a 12-month trend) #26893 只给普通序列补了零,compareTo 被刻意跳过。同比趋势图里,两年都空的月份仍然缺失,图表把它两边的月份画成相邻。
  • 风险与回滚:低。只在带 compareTo 的查询上生效;任一窗口有数据的桶、limit/offset、按度量或 __compare 列排序、2,000 行上限等守卫都不变,普通序列逐字节不变。回滚即 revert。
  • 先看:packages/services/service-analytics/src/dataset-executor.ts(timeBucketFillPlan 的一行与其文档注释);packages/services/service-analytics/src/__tests__/dataset-time-bucket-zero-fill.test.ts(新的两个 [#27111] describe 块)。
  • 两分钟验证:pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/dataset-time-bucket-zero-fill.test.ts,预期 27/27 通过;把那一处提前返回加回去,同一文件 5 条失败(两边都空的月份消失),2 条对照仍绿。
  • 需要你做的:无,席位落地。

What changes

DatasetExecutor.timeBucketFillPlan returned no plan when selection.compareTo was set, the deliberate skip #26893 (PR #27109) left for this card. The skip is lifted; nothing else in the production path changes.

  • One fill rule. A compareTo answer gets the same TimeBucketFillPlan and the same fillEmptyTimeBuckets walk a plain series gets. No second walker, no new helper.
  • The primary window decides the buckets. The plan reads the axis's own timeDimensions[].dateRange, never the shifted one. It runs after the comparison merge, where alignedCompareBucketKey has already restated the comparison rows in primary bucket keys (when the axis is the anchor), so a bucket either window holds is already a row and keeps the merge's values. What the fill adds is only a bucket empty in both windows.
  • The __compare columns. Measured, not changed: fillColumns already lists MEASURE__compare beside each base measure (dataset-executor.ts L1364), and fillEmptyGroups runs after the bucket fill. So an added row reads 0 for count/sum in both the measure and its __compare, and avg/min/max are absent keys on both sides (pinned in the tests and seen live below). Derived measures are evaluated after the fill, as before.
  • Guards unchanged for compareTo. limit/offset, an order on a non-dimension key (a measure, a __compare column, a derived measure), more than one bucketed axis, and MAX_ZERO_FILLED_GRID_ROWS.
  • An axis with no dateRange of its own (the comparison anchored on another, window-only date dimension) gets its interior gaps filled and no edges, the same one-bound rule a plain series follows. That is the only "unbounded" compareTo shape that exists: compareTo refuses an anchor without a two-bound dateRange (resolveCompareDimension, explicitDateRangeWindow).
  • The timeBucketFillPlan docblock now states the compareTo reading instead of "a separate question".

Tests

packages/services/service-analytics/src/__tests__/dataset-time-bucket-zero-fill.test.ts (the real AnalyticsServicePlugin over a real ObjectQL engine and a real SQLite driver, as in #26893):

  • The Time-series charts drop empty date buckets and draw straight through them (a month with 0 revenue disappears from a 12-month trend) #26893 compareTo keeps its shape control pinned the skip, so it is replaced by the card's own case: May–August 2026 vs the previous year (2025-05..08 empty) answers 2026-05, 06, 07, 08, with total_amount [0, 70, 80, 0], every __compare 0, opp_count/opp_count__compare toBe(0) on May and August, and avg_amount / avg_amount__compare absent keys.
  • A new fixture (stage cmp_probe), one month in each state: both windows, primary only, compare only, neither. Cases:
    • the full sequence 2026-03|1|1, 04|1|0, 05|0|1, 06|0|0, 07|1|0, 08|0|0 (count, count __compare) plus the sums: the three one-window months and the both-window month keep the merge's values, June and August are added;
    • the primary columns of the compareTo answer equal the plain series' answer for the same window (one fill rule);
    • previousPeriod (June–August vs March–May, ordinal alignment): 06|0|1, 07|1|1, 08|0|0;
    • an axis with no dateRange (anchor closed_at, window-only): every month between the first and last bucket the grid holds (2025-03 … 2026-07), none before or after;
    • controls: limit with compareTo, and an order on opp_count__compare, are not filled (4 rows, the base answer).
  • Fixture fallout, one file: dataset-compare-bucket-alignment.test.ts day uses a window (1–4 March) wider than its rows (2–3 March), so 1 and 4 March now come back at 0 / 0. The expected rows are updated with exact values; the alignment it pins (03-02 ↔ 5, 03-03 ↔ 6) is unchanged.
Ablation: restoring the compareTo early return

node scripts/ablation-replace.mjs on dataset-executor.ts, anchor if (selection.limit != null || selection.offset != null) return undefined; → if (selection.compareTo || selection.limit != null || selection.offset != null) return undefined; (anchor x1 → x0, replacement x0 → x1, blob 201a3ec3 → 0fe9ae21). The suite imports the executor from src/, so no build sits between the mutation and the run.

× May–August vs the previous year: May and August come back, with 0 in the measure and in its __compare
× a bucket either window holds keeps the merge's values; June and August are added at 0 / 0
× the primary columns are the plain series' answer: one fill rule
× previousPeriod aligns by ordinal and fills the same way
× an axis with no dateRange of its own (a window-only anchor) fills interior gaps only, no edges
Tests  5 failed | 22 passed (27)

The base answer for the fixture case was 2026-03|1|1, 04|1|0, 05|0|1, 07|1|0: the one-window months are the same rows with the same values. Restore: blob after restore 201a3ec3 = HEAD, git diff HEAD empty.

Live red/green through the REST door (app-crm, opportunity_metrics)

pnpm dev:crm -- --fresh -p PORT after a full pnpm build, signed in as the dev admin, POST /api/v1/analytics/dataset/query with datasetName: opportunity_metrics, runtimeFilter: { stage: 'closed_won' }, timeDimensions: [{ dimension: 'close_date', dateRange: ['2026-06-01', '2026-10-31'] }], measures opp_count, total_amount, avg_amount. The seed's closed-won deals sit in 2026-07, 2026-10, 2025-09 and 2025-10. Red = the base blob of dataset-executor.ts (55592517) written over the file and @objectstack/service-analytics rebuilt (dist marker selection.compareTo || selection.limit: 1 hit each in index.js / index.cjs); green = HEAD rebuilt (0 hits). Restore proven by the blob hash equal to HEAD's and git diff HEAD empty. Columns: count / count __compare, sum / sum __compare, avg.

A  compareTo previousYear
RED    200  rows 3
  2026-07 opp 2 / 0 amt 170000 / 0      avg=85000  avgc-absent
  2026-09 opp 0 / 1 amt 0 / 210000      avg-absent avgc=210000
  2026-10 opp 3 / 1 amt 235000 / 75000  avg=78333.33 avgc=75000
GREEN  200  rows 5
  2026-06 opp 0 / 0 amt 0 / 0           avg-absent avgc-absent
  2026-07 opp 2 / 0 amt 170000 / 0      avg=85000  avgc-absent
  2026-08 opp 0 / 0 amt 0 / 0           avg-absent avgc-absent
  2026-09 opp 0 / 1 amt 0 / 210000      avg-absent avgc=210000
  2026-10 opp 3 / 1 amt 235000 / 75000  avg=78333.33 avgc=75000

B  same + limit 10 (control): RED and GREEN both 3 rows, identical to RED A
C  plain series, same window (control): RED and GREEN both 5 rows, identical

Acceptance notes

Verification

All on head 93470eef (this branch with origin/main b322b5da merged in), after pnpm install --frozen-lockfile && pnpm build:

  • pnpm --filter @objectstack/service-analytics test: 194 files, 4698 passed, 282 skipped. typecheck: exit 0. build: exit 0.
  • pnpm --filter @objectstack/spec check:generated: exit 0 (spec moved on main; untouched here).
  • @objectstack/rest analytics suites (vitest run src/analytics-, reading the rebuilt @objectstack/service-analytics dist): 23 files, 298 passed, 22 skipped.
  • pnpm exec eslint --no-inline-config packages/services/service-analytics: exit 0.
  • node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack: 59 derived families, all run, all exit 0. --ran reconciliation: 59 derived, 59 run, 0 NOT-MEASURED, 0 UNRUN. (check-plugin-teardown-shape --self-test after the documented git fetch --depth=1 of its fixture commit.)
  • Ablation and the live REST red/green are under Tests above; both were taken on 1083b988, before the merge, whose incoming commits do not touch dataset-executor.ts or the two test files.

Generated by Claude Code

…kets empty in both windows

Lift timeBucketFillPlan's compareTo early return so a compareTo answer gets
the same zero-fill plan a plain series gets, over the primary window. The
__compare columns were already in the empty-group fill, so a filled row reads
0 for count/sum and leaves avg/min/max unset on both sides.

Claude-Session: https://claude.ai/code/session_01FEkQ5mEZzWjC6chaa9yue6
Co-authored-by: Claude <noreply@anthropic.com>
… days the fill now adds; changeset

Claude-Session: https://claude.ai/code/session_01FEkQ5mEZzWjC6chaa9yue6
Co-authored-by: Claude <noreply@anthropic.com>
@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 Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

2 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • the SDK route bridge reached 56 of 208 client-bound route-ledger rows — the other 152 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 152: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 97 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 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 9dacccf96127755bd196e1844ce5c4cd61717d57 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 3795b2ef00fe43abf7a173bddef132985f2515ca — the merge of head 48871d4f71f4250a903fed0d873a3872915afeea into base 9dacccf96127755bd196e1844ce5c4cd61717d57, 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 3795b2ef00fe43abf7a173bddef132985f2515ca && git checkout 3795b2ef00fe43abf7a173bddef132985f2515ca
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 9dacccf96127755bd196e1844ce5c4cd61717d57 48871d4f71f4250a903fed0d873a3872915afeea && git checkout -B drift-repro 9dacccf96127755bd196e1844ce5c4cd61717d57 && git merge --no-ff 48871d4f71f4250a903fed0d873a3872915afeea

node scripts/docs-audit/affected-docs.mjs --json 9dacccf96127755bd196e1844ce5c4cd61717d57

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

…reTo as unfilled

Claude-Session: https://claude.ai/code/session_01FEkQ5mEZzWjC6chaa9yue6
Co-authored-by: Claude <noreply@anthropic.com>
…angeset states that it supersedes its compareTo line

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

Copy link
Copy Markdown
Contributor Author

席位核对

ACCEPT · domain:server seat 2 · os-project-manager · session_0186vfjHHMsRXC9EUT9hTFMo · 2026-10-28T11:19Z · head 48871d4f · #27111

The maintainer's standing authorisation for landing reviewed PRs, verbatim: 「按照 pm-dispatch 规则复核过的都授权」.

  1. Shape:
    • A draft against main, assignee os-project-manager.
    • Fixes #27111, Clause-②: no and Metadata-protocol: none are line-initial.
    • The changeset is a patch on @objectstack/service-analytics.
    • check-governed-merges --pr 27213 reads NOT governed, 199 changed lines.
    • The claim (6464937895, amendments 6467071389 and 6467147455) names this PR's branch.
  2. Against the order and triage 6462769566:
    • The one production change lifts timeBucketFillPlan's compareTo early return. There is no second walker and no new helper.
    • The plan reads the primary axis's own dateRange and runs after the comparison merge, so only a bucket empty in both windows is added.
    • The __compare columns were already in fillColumns. This was measured, not changed: count/sum read 0 on both sides, and avg is absent on both.
    • Every other guard stays (limit/offset, a non-dimension order including a __compare column, two bucketed axes, MAX_ZERO_FILLED_GRID_ROWS), and each is pinned by a control.
    • Ablation: restoring the early return reds 5 cases, and the 2 controls stay green.
    • Live app-crm REST red/green: 3 rows become 5 (06 and 08 read 0 / 0). The limit and plain-series controls are identical before and after.
    • The one fixture fallout is the day alignment case, which gains 1 and 4 March at 0 / 0 with the alignment it pins unchanged.
  3. Contract review: not owed. The face has no packages/spec/src/** path and no governed path, and it declares Clause-②: no, so neither a narrowing nor a widening arm applies. An answer gains rows only when compareTo is set, and no input is refused or newly accepted.
  4. Changeset: the pending Time-series charts drop empty date buckets and draw straight through them (a month with 0 revenue disappears from a 12-month trend) #26893 note is at its base bytes. The required foreign-changeset gate (finding: random changeset filenames collide silently across parallel agents — a round overwrote a sibling PR's minor changeset and every gate stayed green #17712) refuses any edit to it. This PR's own changeset carries the sentence that supersedes that note's compareTo mention for the same release.
  5. Gates:
    • Locally, 59 of 59 derived families exit 0, with 0 NOT-MEASURED. The service-analytics suite passed 4,698 tests, and the rest analytics suites passed 298.
    • CI on head 48871d4f: 36 success, 15 skipped, 0 red. The state is clean.
  6. Overlap: git merge-tree reports no conflict against main cdec7473.

Generated by Claude Code

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review October 28, 2026 11:20
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit 835b2d1 Oct 28, 2026
52 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-1g97l3 branch October 28, 2026 11:39
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

Development

Successfully merging this pull request may close these issues.

analytics: a dataset query with compareTo still drops a time bucket that is empty in both windows, so a period-over-period trend keeps the #26893 gap

2 participants