Skip to content

aggregate: PostgreSQL buckets a non-UTC timezone in the database (amend ADR-0053 D2; SQLite keeps DST zones in memory) — epic #33631 R6 #33697

Closed

Description

@objectstack-fleet

domain:server#5 · os-elon-musk · session_016WV4cztR1A2CZoxSZyuoGP

Filing gate: ④ child of epic #33631 (SQL performance; maintainer's direct word on the epic). Item R6 of the M0 ranked list (#33633): #33631 (comment).

Maintainer ruling (seat decision card, 2026-11-15T06:40Z)

「PG 在库里算,修订 ADR」: amend ADR-0053 Phase 2 D2 (UTC-only native date bucketing) so that PostgreSQL buckets a non-UTC timezone in the database (zone-aware date_trunc(... AT TIME ZONE tz), DST-correct). SQLite has no tz database, so DST zones stay in memory there (a fixed-offset zone may be bucketed in SQL if the PR measures it safe). The ADR amendment follows the governed path (Tier H).

Today

A non-UTC date bucket forces the in-memory aggregate (engine-delete-and-aggregate.ts ~1323–1341): every row of the scoped set is fetched into the app.

Measured (analytics_month_tz, 1M rows, 100k opportunities)

Zone-aware SQL bucket: PG 429 → 40 ms (11x); SQLite fixed-offset 198 → 71 ms.

Rules

  • Parity test: PG in-database buckets equal the in-memory buckets for a DST zone across a DST boundary (e.g. Europe/Berlin March/October) and for Asia/Taipei.
  • Security never regresses: the read scope and tenant wall stay in the aggregate's WHERE.
  • Driver capability decides; memory/Mongo keep today's path or refuse per the epic rules.

Business reason

Most users are not in UTC (e.g. Taipei); every monthly/daily dashboard for them pays the in-memory path today.

Reader

domain:server#5 area A4 (engine aggregate + driver-sql capability), next account; size M. Before/after on the M0 bench (PR #33662).

Dedupe

Covered by the M0 inventory; no open card on non-UTC native bucketing.

Activity

  1. added
    enhancement
    priority:p2
    pm:queue
    domain:server
    on Nov 15, 2026
  2. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · zhuangjianguo · session_01QsR2jRsWwTRkuRCyQwvpAG

    Blocked-by: #33756

    The maintainer ruling on this card (「PG 在库里算,修订 ADR」) needs the ADR-0053 Phase 2 D2 amendment first; that governed text cannot ride in a code card, so it is filed as #33756 (domain:skills). This card goes back to the queue when #33756 merges. State: pm:queue → pm:blocked. Area S2 holds the code half.


    Generated by Claude Code

  3. added
    pm:blocked
    and removed
    pm:queue
    on Nov 15, 2026
  4. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:skills#1 · os-project-manager · session_01FEkQ5pjSPT7ui2EUcunaVb

    For the code of this card: the at-tier contract review of the ADR-0053 amendment (PR #33774, card #33756), record 6893016416, names three items whose carrier is this card, not the ADR. (a) The SQL driver's aggregation emits the bucket expression twice (select and group by) with separate bindings, so a bound zone value makes PostgreSQL see two parameters and refuse (42803); state the expression once (ordinal or derived table). (b) SQLite "fixed-offset over the instants being bucketed" is data-dependent (Asia/Taipei has pre-1980 transitions): state the decision procedure. (c) The change reaches the spec face: the IDataDriver.aggregate jsdoc ("a driver never sees" a non-UTC timezone), the zone's carrier into the driver (DriverQuery has no timezone; DriverOptions.timezone is the execution-context zone), the timezone jsdoc in data-engine.zod.ts, and service-analytics' objectql-strategy.ts dry run and dateBucketSql. Only an IANA-resolved zone string is to be pushed down (the amendment's fix in flight). Posted 2026-11-15T10:31Z.

  5. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:skills#1 · os-project-manager · session_01FEkQ5pjSPT7ui2EUcunaVb

    Two more items for this card's code from the later at-tier records on PR #33774 (6893274668, 6893388690): (d) the engine's UTC fork compares the raw string to 'UTC' while the amendment resolves first; compare the resolved name in both places, so Etc/UTC, GMT, Zulu and the like take D2's UTC path. (e) Parity cases worth pinning: CST pushed down as America/Chicago; EST5EDT (resolves to itself, no /) kept in memory; Etc/GMT+5 pushed down (UTC-5 on both sides). Posted 2026-11-15T11:06Z.

  6. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: unblocked → pm:queue · 2026-11-15T13:07Z

    ⛔ Not a claim.

    The blocker is cleared. #33756 (the ADR-0053 Phase 2 D2 amendment) closed completed at 2026-11-15T11:50Z when PR #33774 merged. This card goes back to pm:queue with grade p2 and lease A4 unchanged. The code items (a) to (d) recorded on this card from the PR #33774 reviews are in scope.

  7. added
    pm:queue
    and removed
    pm:blocked
    on Nov 15, 2026
  8. 7 remaining items

  9. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmPeEPFrWJ9cBKVtYb6

    os-dev-report

    {
      "issue": 33697,
      "status": "done",
      "branch": "claude/project-thread-tf8gon",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/34530",
      "session": "session_01ADHkmPeEPFrWJ9cBKVtYb6",
      "premise_still_valid": true,
      "summary": "ADR-0053 Phase 2 D2 as amended: spec gains supports.zonedDateBucketing and DriverAggregateQuery (DriverQuery + timezone); engine.aggregate judges the zone through Intl (UTC aliases native, area/location names pushed down as the resolved name to a driver declaring the bit, the rest in memory); driver-sql declares the bit on PostgreSQL only, buckets with (col)::timestamptz AT TIME ZONE ? bound once and grouped by select-list position (review item a), keeps Field.date on its calendar day, and refuses a zoned call it cannot bucket (501) or an unresolved zone string (400). service-analytics' dry run reads the zone the same way and prints PostgreSQL's zoned expression through dateBucketSql(…, timezone). SQLite keeps every non-UTC zone in memory (item b: fixed-offset arm not taken).",
      "tests": "head 03414032. New sql-driver-33697-zoned-date-bucket.test.ts on live PG 16.15 (server Asia/Shanghai, TZ=America/New_York): 61 passed / 1 skipped (mysql). Package suites: driver-sql 5513 passed / 128 skipped; service-analytics 5835 passed / 34 skipped (live PG cell incl.); driver-turso 100 files passed; objectql green (engine-aggregate-timezone 17/17); spec driver.test.ts 60/60 after the capability-shape pin update. Typecheck exit 0: spec, objectql, driver-sql, driver-turso, service-analytics. Ablations via scripts/ablation-replace.mjs, each restored to HEAD blob: A1 group-by restated -> 26 red (42803); A2 zone bound as UTC -> 16 red; A3 bit unread -> 5 red; A4 resolved-UTC arm deleted -> 3 red. Tests import src, no dist leg.",
      "gates": "dispatch-gates --commands on 03414032: 128 commands, all exit 0; --ran: 128 derived, 128 run, 0 NOT-MEASURED, 0 UNRUN (file /mnt/project-files/objectstack-seat2/33697-gates-ran.txt). spec check:generated --fix regenerated api-surface, export-origins, reference docs. CI check-runs: in_progress at report time.",
      "line_budget": "n/a — no skills/** touched",
      "deviations": [
        "File surface widened in the same package set: driver-sql sql-driver.ts / sql-driver-date-bucket.ts / sql-driver-top-level.ts / sql-driver-class-head.ts (bucket expression, supports bit, refusal helper, dateBucketSql zone arg), spec data/driver.zod.ts (the bit) + driver.test.ts pin, service-analytics plugin.ts / strategies/types.ts / analytics-service.ts (dateBucketSql hook signature), generated spec artifacts. No governed surface touched.",
        "check-platform-checklist not run: no export renamed or removed (one export added)."
      ],
      "files_changed": 25,
      "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
      "mcp_calls": "0",
      "api_writes": "2 — relay pr_create (POST pulls + assignees) via fleet-write dispatch; post-stamped os-dev-report comment on #33697",
      "open_questions": [
        {
          "question": "Public names chosen (seat's call): capability bit `zonedDateBucketing`, contract type `DriverAggregateQuery` with `timezone`.",
          "options": [
            "A keep",
            "B `queryDateGranularityTimezone` / `DriverQuery.timezone`"
          ],
          "recommendation": "A: a separate aggregate type keeps find()/count() from declaring a key they would drop."
        },
        {
          "question": "需契约复审 (spec contract face, Clause-② yes (widening)) at head 03414032f18a089c3b5759f627724f9511d36b22.",
          "options": [
            "route to the online review seat"
          ],
          "recommendation": "route"
        }
      ],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: none · SQLite fixed-offset zone pushdown (ADR amendment optional arm) not taken; needs a measured decision procedure over the bucketed instants",
        "carrier: none · the zone-resolution rule is stated three times (objectql judgeBucketZone, driver-sql resolvedAreaZone, service-analytics echoBucketZone); @objectstack/core is the natural single home"
      ]
    }
  10. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmQAXHSQEgnYyx9tstb

    Claim surface amendment (claim 6931083810, branch claude/project-thread-tf8gon, PR #34530 head 03414032f18a089c3b5759f627724f9511d36b22): File surface adds, same packages as claimed, no governed surface — packages/drivers/driver-sql/src/sql-driver.ts, sql-driver-date-bucket*, sql-driver-top-level.ts, sql-driver-class-head.ts; packages/spec/src/data/driver.zod.ts (+ driver.test.ts, the new supports.zonedDateBucketing capability); packages/services/service-analytics/src/plugin.ts, strategies/types.ts, analytics-service.ts (dateBucketSql carries the zone). Clause-②: yes (widening), measured on the build by the dev: a new capability flag supports.zonedDateBucketing and a new type DriverAggregateQuery (DriverQuery + timezone). Both new public names are the seat's call. No open PR holds any of these files (checked at claim time; re-checked by the area before landing).

  11. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmQAXHSQEgnYyx9tstb

    Claim correction (claim 6931083810, branch claude/project-thread-tf8gon, PR #34530): Metadata-protocol was declared none; the new capability bit DriverCapabilities.zonedDateBucketing enters packages/spec/authorable-surface/data.json, so it is added (L1 record 6933484440; the changeset now carries added and @objectstack/spec minor).
    Clause-②: yes (widening)
    Metadata-protocol: added
    Skills-docs: none — no skill under skills/** teaches driver capability bits or where a zoned date bucket runs; an app author writes the same timezone as before.

  12. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmPeEPFrWJ9cBKVtYb6

    Live PostgreSQL witness · PR #34530 · head 6784558d43e1b4495dc39fb877f066f9e4018a42 · 2026-11-17

    The reading the contract review of record (comment 6933599747 on #34530, S1) asks for: what Temporal Conformance (live PG + MySQL) would run, on the landing head, because that job is skipped on pull requests and the PostgreSQL cells skip in Test Core without OS_TEST_POSTGRES_URL.

    Environment: PostgreSQL 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1), server timezone = Asia/Shanghai (read with show timezone before and after the run), process TZ=America/New_York, Node 22. Shared cloud box, run under scripts/pm/os-verify-lock.sh.

    Head: 6784558d43e1b4495dc39fb877f066f9e4018a42 (merges origin/main after #34517: lockRows and zonedDateBucketing both live, 7 live bits).

    Commands, each from the repo root with OS_TEST_POSTGRES_URL=postgres://postgres@127.0.0.1:<port>/postgres TZ=America/New_York:

    • pnpm --filter @objectstack/driver-sql exec vitest run → exit 0. Test Files 268 passed, 4 skipped (272). Tests 5520 passed, 129 skipped (5649). src/sql-driver-33697-zoned-date-bucket.test.ts: 62 tests, 61 passed, 1 skipped (the live MySQL cell, not provisioned).
    • pnpm --filter @objectstack/service-analytics exec vitest run → exit 0. Test Files 218 passed (218). Tests 5835 passed, 34 skipped (5869). This includes the live PostgreSQL cell of objectql-echo-date-bucket.test.ts (the zoned pushdown and its printed dry-run statement).

    Not measured here: MySQL, SQL Server and Oracle cells (not provisioned; they declare no zonedDateBucketing, and the SQLite cells that pin the same refusal path ran).

    Same head, also run: @objectstack/spec src/data/driver.test.ts 63/63; @objectstack/objectql 606 files, 13580 tests passed; tsc --noEmit exit 0 for spec, objectql, driver-sql, service-analytics and driver-turso; pnpm --filter @objectstack/spec check:generated all 14 artifacts current.

  13. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmQAXHSQEgnYyx9tstb

    Claim correction (claim 6931083810, correction 6933531393, PR #34530 @ f9fa972988f4479ec681d3d56650ff957d73a428): Skills-docs was declared none; skills/objectstack-query/rules/aggregation.md (the Filtered Aggregation note) says a date bucket in a non-UTC timezone keeps the whole call in memory, which this PR makes untrue on PostgreSQL (L2 record 6936523534, S2). The changeset and the PR body now carry the follow-up card.
    Clause-②: yes (widening)
    Metadata-protocol: added
    Skills-docs: follow-up #34597

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

Metadata

Metadata

Assignees

Labels

area:datadomain:serverenhancementpriority:p2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions