Skip to content

fix(timezones): SUPPORTED_TIMEZONES order is not reproducible, so the contract step emits a 111 KB no-op migration - #728

Merged
Ardnived merged 5 commits into
mainfrom
claude/fix-timezone-order
Sep 7, 2026
Merged

Ardnived merged 5 commits into
mainfrom
claude/fix-timezone-order

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • SUPPORTED_TIMEZONES now sorts on rawOffsetInMinutes instead of inheriting getTimeZones()'s current-offset order, which moved at every DST boundary.
  • It also reads the static rawTimeZones, so membership no longer depends on the host's ICU version.
  • The list is pinned by digest in a unit spec, so a @vvo/tzdb bump or a clock change fails CI instead of surfacing as a migration diff.

Changes

  • src/lib/timezones/index.ts — impose the order, read the static export, rewrite the doc comment
  • tests/unit/timezone-options.spec.ts — pin the list; three new cases
  • src/migrations/AGENTS.md — trim the "false positive" section to the check that stays live
  • src/payload-types.ts, src/migrations/20260907_181403_reorder_timezone_enums.* — generated

Preview

Contract impact

src/payload-types.ts changes, and pnpm types:cms copies it into WeMeditateWeb. The change is a pure reorder of the SupportedTimezones union — the line multiset of the regenerated file is identical to the committed one, so no consumer loses a member. Nothing downstream depends on the order.

Migration

  • New migration: src/migrations/20260907_181403_reorder_timezone_enums.ts
  • Impact: five *_tz enum types (events, _events_v, app_cards, _app_cards_v, registrations) are dropped and recreated to reorder their members. No table, no column, no data change. Each column is cast to text and back with a USING clause, and the member set is unchanged, so no stored value can be orphaned.
  • Reversible: yes — down() mirrors up() and restores the previous order.

⚠ This is the one-time catch-up the fix makes necessary. The five ALTER COLUMN pairs rewrite those tables under an ACCESS EXCLUSIVE lock, and migrations apply in-process on boot.

Test results

  • Lean gate: ✓ pnpm lint, pnpm typecheck, pnpm typecheck:tests, pnpm test:unit (125 files, 1618 tests)
  • Targeted specs: ✓ 21 across events, session-reminders, registrations-fullness
  • Contract step: ✓ pnpm db:migrations:create --skip-empty now creates nothing on a clean tree — acceptance criterion 4
  • Build: N/A — Railway builds the preview

Every new assertion was confirmed failing first, at the site that causes it. Four defect classes, and each column is a different spec:

Defect reintroduced pin ordering input-order mock-wired no-ICU
the sort removed red pass red pass red
sorted on currentTimeOffsetInMinutes red red red red red
right key, but back on getTimeZones() pass pass red red red
the name tie-break removed red pass red pass red

Row 3 is why the last three cases exist — the first version of this PR passed it outright.

Manual verification

  1. Admin → Events → edit an event's schedule → the timezone picker still lists every zone and saves.
  2. Confirm an event created before this PR still shows its original timezone (the enum reorder must not disturb stored values).

Notes for reviewer

Detail

Review round 7abcb10. Both comments applied, and origin/main merged in after #727 landed. The docblock's #722 section is down from 24 lines to 7, and the sort comparator's note from 6 to 2 — every imperative kept, the narrative dropped to #722 and to this body. In src/migrations/AGENTS.md, the paragraphs describing the diagnosis while it was still open are gone, along with the "the snapshot is stale, commit it" case, which only ever described this PR's own catch-up. What stays is the check that outlives the fix: a widening still looks exactly like a reorder, so compare the member lists as sets. Its default on a reorder is now the safe one — do not commit until you know why the list moved.

The merge's one conflict was src/payload-types.ts itself. It was resolved by running pnpm generate:types, which reproduced this branch's file byte for byte — the property the PR adds, exercised against a moving base rather than asserted.

Root cause, confirmed rather than assumed. Pacific/Easter reports rawOffsetInMinutes: -360 and currentTimeOffsetInMinutes: -300 today, because Chile entered DST on 2026-09-06 — one day after the committed snapshot was written. getTimeZones() sorts on the latter, so regenerating moved exactly the three Chilean zones. The reorder is date-driven, not machine-driven, and would return at every DST boundary in any zone the list covers.

Why the tie-break does not call localeCompare. Collation depends on the host's ICU version, which is the same class of non-determinism the module already avoids by not using Intl.supportedValuesOf('timeZone'). IANA names are ASCII, so a code-unit compare is total: every (rawOffsetInMinutes, name) pair is unique, so no tie ever falls through to sort's own stability and the input order cannot leak.

Why rawTimeZones costs nothing. getTimeZones() is rawTimeZones plus per-zone Intl resolution, and it silently drops any zone the host cannot format — so it decided membership, not just order. The builder reads only the four fields present on the raw records, so switching produced a byte-identical payload-types.ts and left the pinned digest unmoved. It adds no migration of its own, and is invisible on a current runtime, where 0 of 315 zones drop.

Ordering is only asserted where it is imposed. UTC and Payload's curated defaultTimezones are seeded ahead of the tzdb loop to keep their friendlier labels, so the monotonic case excludes them rather than asserting them out of order. The Etc/GMT* range is appended last and is not in the tzdb map at all.

Closes #722

🤖 Written by the sydevs autonomous loop — see what this is

🤖 Generated with Claude Code

https://claude.ai/code/session_011WhkKoQTCGvJymk1XySE9r

…nt one

`@vvo/tzdb`'s `getTimeZones()` returns its zones sorted by
`currentTimeOffsetInMinutes`, and `SUPPORTED_TIMEZONES` inherited that order.
That value moves at every DST boundary in any zone the list covers, so the
order of five Postgres enums was a function of the date the migration was
generated: a clean checkout of `main` produced a 111 KB migration that dropped
and recreated all five `*_tz` types with no schema change (#722).

Confirmed rather than assumed. `Pacific/Easter` reports
`rawOffsetInMinutes: -360` and `currentTimeOffsetInMinutes: -300` today,
because Chile entered DST on 2026-09-06 — one day after the committed snapshot
was written. Regenerating moved exactly the three Chilean zones.

`rawOffsetInMinutes` is fixed for a zone, so sorting on it is stable on any
machine and on any date. It also agrees with the label: we render
`zone.rawFormat`, so before this fix `Pacific/Easter` read `(-06:00)` while
sitting in the `-05:00` group for half the year.

The tie-break compares code units rather than calling `localeCompare`.
Collation depends on the host's ICU version, which is the same class of
non-determinism this module already avoids by not using
`Intl.supportedValuesOf('timeZone')`.

The list is now pinned by digest in `tests/unit/timezone-options.spec.ts`, so a
`@vvo/tzdb` bump or a clock change fails a unit test instead of surfacing as a
migration diff nobody reads. Three assertions, each confirmed failing at the
site that causes it and each for its own reason:

- the sort removed entirely -> all three red
- sorted, but on `currentTimeOffsetInMinutes` -> digest and ordering red, the
  input-order case green, since that defect is order-independent but wrong

`src/migrations/AGENTS.md` recorded this as an undiagnosed false positive. The
set-comparison rule there still stands, because a widening still looks like a
reorder, but a reorder now means a red spec first.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011WhkKoQTCGvJymk1XySE9r
The one-time cost of the fix in the previous commit. Generated by the contract
step, not written by hand.

`src/payload-types.ts` and the five enum types are a pure reorder: the line
multiset of the regenerated file is identical to the committed one, so no
member is added or removed. Each column is cast to `text` and back with a
`USING` clause, and `down()` mirrors `up()`, so every stored value survives.

Re-running `pnpm db:migrations:create --skip-empty` after this commit creates
nothing, which is the acceptance criterion this migration exists to satisfy.

Deployment note: the five `ALTER COLUMN ... SET DATA TYPE` pairs rewrite
`events`, `_events_v`, `app_cards`, `_app_cards_v` and `registrations` under an
ACCESS EXCLUSIVE lock. Migrations apply in-process on boot.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011WhkKoQTCGvJymk1XySE9r
…ost ICU

Adversarial review found the order was only half the problem. `getTimeZones()`
resolves every zone through `Intl` and silently drops any the host cannot
format — `dist/getTimeZones.js` returns the accumulator unchanged when the
offset lookup throws. So the enum's MEMBERSHIP was a function of the runtime's
ICU version, which is precisely the dependency this module's own doc comment
disclaims. An older runtime would have generated a shorter enum.

`rawTimeZones` is the static export behind that call and carries all four
fields used here (`name`, `group`, `rawFormat`, `rawOffsetInMinutes`), so this
costs nothing: `pnpm generate:types` produces a byte-identical
`src/payload-types.ts`, the pinned digest does not move, and no extra migration
is needed. It is invisible on this box, where 0 of 315 zones drop.

Three specs cover it, each confirmed failing at its own site. The matrix now
separates four defect classes:

| reintroduced          | pin | ordering | input-order | mock-wired | no-ICU |
| --------------------- | --- | -------- | ----------- | ---------- | ------ |
| no sort               | red | pass     | red         | pass       | red    |
| sorted on current off | red | red      | red         | red        | red    |
| right key, ICU source | ok  | pass     | red         | red        | red    |
| tie-break removed     | red | pass     | red         | pass       | red    |

Row 3 is why the new cases exist: the previous specs passed it outright.

Also from review: the reversal case could have gone vacuous if the mock ever
stopped applying, so a second case proves the stub is wired by truncating it.
The comparator moves to a named `byName` helper, which puts the sort back
under Prettier's 100-column width — the branch was failing `prettier --check`,
which neither `pnpm lint` nor CI would have caught.

`src/migrations/AGENTS.md` said a green spec beside a reorder migration means
the pin was edited. That is not exhaustive, and this PR is the counter-example:
a stale committed snapshot produces the same pair and must be committed. Both
cases are now named, with how to tell them apart.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011WhkKoQTCGvJymk1XySE9r
@railway-app

railway-app Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-728 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Sep 7, 2026 at 7:14 pm UTC
1 service not affected by this PR
  • mailpit

Comment thread src/migrations/AGENTS.md Resolved
Comment thread src/lib/timezones/index.ts Resolved
@github-project-automation github-project-automation Bot moved this from In progress to Changes requested in SYDevelopers Technical Roadmap Sep 7, 2026
@Ardnived Ardnived removed the awaiting label Sep 7, 2026
Brings #727 onto this branch after its squash-merge.

The one conflict was `src/payload-types.ts`, the generated file this PR exists
to stabilize. Resolved by regenerating with `pnpm generate:types` rather than by
hand — which reproduced this branch's version byte for byte, the property the PR
adds.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XmzSzbuPBtmPwBnsFuaoPk
Review asked for both. Neither changes behaviour — the unit lane is unchanged
at 1618 passing.

`src/lib/timezones/index.ts` — the docblock's 24-line #722 section becomes 7,
and the sort comparator's 6-line note becomes 2. Every imperative survives:
sort on `rawOffsetInMinutes`, read the static `rawTimeZones`, compare code
units rather than `localeCompare`, and the pointer to the spec that pins both
membership and order. What went was the narrative — the 111 KB migration, the
`Pacific/Easter` label example, and the walk through `getTimeZones.js`'s
accumulator. That story is on #722 and in the PR body.

`src/migrations/AGENTS.md` — the "read the DDL first" section described a
diagnosis that was open when it was written. With the cause fixed, the two
paragraphs about telling an ambiguous reorder from a real change are stale, and
the "commit it, the snapshot is stale" case describes only this PR's own
one-time catch-up. Cut to the check that stays live: a widening still looks
exactly like a reorder, so compare the member lists as sets. The surviving
default on a reorder is now the safe one — do not commit it until you know why
the list moved.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XmzSzbuPBtmPwBnsFuaoPk
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-728 September 7, 2026 19:12 Destroyed
@sydevs-bot
sydevs-bot requested a review from Ardnived September 7, 2026 19:13
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Both comments applied in 7abcb10, and main merged in after #727 landed.

The merge's one conflict was src/payload-types.ts itself. Resolved by running pnpm generate:types, which reproduced this branch's file byte for byte — the PR's own property, exercised against a moving base.

Lean gate green (1618 unit tests). Threads resolved, re-requested.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@Ardnived Ardnived removed the awaiting label Sep 7, 2026
@Ardnived
Ardnived merged commit e7ccc7e into main Sep 7, 2026
5 of 6 checks passed
@github-project-automation github-project-automation Bot moved this from Changes requested to Done in SYDevelopers Technical Roadmap Sep 7, 2026
@Ardnived
Ardnived deleted the claude/fix-timezone-order branch September 7, 2026 19:20
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

CI is red on the e2e lane only, and the cause is not this PR.

All 8 failures are tests/e2e/*, each the same error: POST /api/managers/login returns 404 from sahajcloud-sahajcloud-pr-728.up.railway.app. Lint, the unit lane and the integration lane all passed.

A 404 is not the credential case the assertion's message suggests. A wrong password returns 401. The whole preview host 404s, / included.

Probe Result
GET pr-728…up.railway.app/ 404
GET pr-714…up.railway.app/ 404
GET cloud.sydevelopers.com/api/managers/me 200

#714 carries an unrelated diff. Its run failed at 19:22 and its preview host 404s the same way. Production answers. Railway's own commit status for 7abcb10 reports success at 19:14:53, before the specs ran.

No re-run spent — it fails identically while the host 404s. Re-run the job once previews serve again. The other three checks are green.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-728 — 7abcb10f Deployed Sep 7, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(timezones): SUPPORTED_TIMEZONES order is not reproducible, so the contract step emits a 111 KB no-op migration

3 participants