Skip to content

fix(analytics): apply the effective date granularity to labels and drill ranges (#3588 follow-up) - #3673

Merged
os-zhuang merged 1 commit into
mainfrom
claude/analytics-query-builder-params-vi64vw
Jul 27, 2026
Merged

fix(analytics): apply the effective date granularity to labels and drill ranges (#3588 follow-up)#3673
os-zhuang merged 1 commit into
mainfrom
claude/analytics-query-builder-params-vi64vw

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Follow-up to #3652 (issue #3588). Found by browser-verifying that merge, not by the test suite — which passed throughout, because each site was correct in isolation.

What was wrong

selection.dateGranularity reached the GROUP BY, but two post-processing steps kept reading the dataset dimension's default: the bucket-label formatter and the drill-range inverter. So a query was grouped one way and described another.

Driving a real dashboard query against a dataset whose dimension declares dateGranularity: 'month':

selectionrows came back asshould be
yearcreated_at: "1970-01""2026"
dayten days collapsed to two duplicated month keysten distinct day keys
quartercorrect label, drillRanges: [{}, {}]quarter ranges
week / daydrillRanges: [{}, …]week / day ranges

The 1970-01 is the tell: a year bucket's key is "2026", which the month formatter re-read as 2026 milliseconds past the epoch.

The fix

Granularity precedence now lives in one exported function, resolveDimensionGranularity, called from all three sites that must agree — the query's GROUP BY, the label formatter, and the range inverter. The drift was possible only because each resolved it independently, so the fix is the shared resolver rather than three parallel patches.

Two things this surfaced, fixed here too:

Verification

Browser-driven against the showcase app, before and after. All five granularities now label correctly and every one carries its half-open drill range:

day → 2026-06-17, 2026-07-02, … (was: two duplicated month keys)
week → 2026-W28, 2026-W29, … drill ranges now present
month → 2026-06, 2026-07 (unchanged — the one case that worked)
quarter → 2026-Q2, 2026-Q3 drill ranges now present
year → 2026 (was: 1970 / 1970-01)

Tests: 11 new in dataset-granularity-postprocess.test.ts, pinning each broken case plus the precedence table; full @objectstack/service-analytics suite 219 passed.

The test service returns the bucket key the driver would actually produce for the granularity requested, so a query/post-processing mismatch reproduces exactly as it did in the browser — a mock that echoed a fixed key would have stayed green through the original bug.


Generated by Claude Code

…ill ranges (#3588 follow-up)
`selection.dateGranularity` reached the GROUP BY but not the post-processing:
the bucket-label formatter and the drill-range inverter both kept reading the
DATASET dimension's default, so a query was grouped one way and described
another. Found by driving the query in a browser, not by the unit tests — which
passed throughout, because each site was correct in isolation.
Against a dataset declaring `dateGranularity: 'month'`:
- selection `year` → row labelled "1970-01", a year bucket re-formatted with the
dataset's month granularity, its "2026" key re-read as 2026 milliseconds past
the epoch;
- selection `day` → day buckets re-labelled as months, collapsing ten distinct
days into two duplicated keys;
- selection `quarter`/`year`/`day`/`week` → `drillRanges` empty, silently
removing drill-through from every bucketed chart.
Granularity precedence now lives in one exported function,
`resolveDimensionGranularity`, called from all three sites that must agree: the
query's GROUP BY, the label formatter, and the range inverter. The drift was
possible only because each resolved it independently — so the fix is the shared
resolver, not three parallel patches.
Also fixes two things this surfaced:
- A dataset dimension declaring NO granularity but bucketed by the widget now
gets drill ranges. The sidecar keyed off the dataset's own `dateGranularity`,
so the case #3588 is actually about could never drill.
- `formatDateBucket` no longer mistakes a bare year key for an epoch timestamp.
"2026" is the only bucket key that collides with the pure-digit epoch
heuristic; "2026-Q2", "2026-07" and "2026-07-15" all fail it. Idempotence over
already-formatted keys is that function's stated contract — the year case just
never held.
Verified in a browser end to end: all five granularities now label correctly
(year "2026", not "1970") and every one carries its half-open drill range.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEZLBGyNoJMLvtGPqsMPRC
@vercel

vercelBot commented Jul 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
objectstackIgnoredIgnoredJul 27, 2026 1:55pm

Request Review

@github-actionsgithub-actionsBot added documentation Improvements or additions to documentation tests tooling labels Jul 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): packages/services.

6 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/automation/webhooks.mdx(via packages/services)
  • content/docs/kernel/runtime-services/audit-service.mdx(via packages/services)
  • content/docs/kernel/runtime-services/index.mdx(via packages/services)
  • content/docs/kernel/runtime-services/settings-service.mdx(via packages/services)
  • content/docs/plugins/packages.mdx(via packages/services)
  • content/docs/protocol/kernel/i18n-standard.mdx(via packages/services)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

@os-zhuang
os-zhuang marked this pull request as ready for review July 27, 2026 14:01
@os-zhuang
os-zhuang merged commit 7101ca2 into mainJul 27, 2026
16 checks passed
@os-zhuang
os-zhuang deleted the claude/analytics-query-builder-params-vi64vw branch July 27, 2026 14:01
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationImprovements or additions to documentationsize/mteststooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@os-zhuang@claude