Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .changeset/16292-cron-timezone-iana-domain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
'@objectstack/spec': minor
---

fix(spec)!: `CronSchedule.timezone` is judged by the `iana_time_zone` membership predicate (#16292)

**BREAKING** — an accept-set narrowing on a published authoring key.
`CronScheduleSchema.timezone` was a bare `z.string().optional().default('UTC')`, so
`defineJob` and `JobSchema.parse` took `timezone: 'UTC+8'` at authoring and build time
and said nothing. It is now judged by `isValueDomainMember('iana_time_zone', …)` — the
predicate `@objectstack/spec/shared` already exports, and the same judge the four
`valueDomain: 'iana_time_zone'` columns (`sys_business_unit.timezone`,
`sys_organization.timezone`, `sys_job.timezone`, `sys_report_schedule.timezone`) are
written against. Shipped as `minor` under the repo's launch-window convention for
accept-set narrowings.

No job that ran yesterday stops running. The value was already carried unchanged to
`CronJobAdapter.schedule`, where croner — constructed with a callback — throws on a
non-member and `AppPlugin` records a per-job `FAILED TO SCHEDULE` at `error` level plus
a `jobScheduleFailuresTotal` increment: the job was declared and never ran. What moves
is WHEN its author is told, from the first environment that boots to `defineJob` /
`os build`. So a stack whose job carries a zone the platform cannot honour now stops
building instead of booting-and-not-running.

Membership is the `Intl.DateTimeFormat` probe rather than a checked-in list, so the
accepted set is the host's own tz database — deliberately, and identically to those four
columns, the settings door and `resolveAuthzContext`. It is what every `Intl`-based
consumer downstream accepts, so the parse-time answer and the schedule-time answer
cannot disagree on one host. `UTC`, the key's own declared default, is a member on every
conforming runtime, so an omitted key is untouched.

`interval` and `once` schedules carry no zone and are unaffected. The boundary type
`JobSchedule.timezone` on `@objectstack/spec/contracts` is a third, separate door and is
deliberately left out of this change.

Clause-②: yes (narrowing)

<!-- adr-0087: not-required (no-migration-prescription) No key, export, config field or stored shape is added, removed, renamed or re-spelled, and no metadata document has to be rewritten into a different one. The narrowing is value-level and undecidable in the upgrade direction: an offset spelling such as `UTC+8` names no zone at all, so nothing can derive whether its author meant `Asia/Shanghai`, `Asia/Singapore` or `Australia/Perth` — the answer is a fact about the deployment, never about the refused string. `objectstack migrate meta` therefore has nothing mechanical it could apply, and a ledger row would carry an empty mapping. The sibling column-tier narrowing of the same concept is already recorded as `platform-timezone-columns-iana-domain-refused`; this authoring-tier door is a different door and is deliberately not filed under that id. -->
6 changes: 3 additions & 3 deletions content/docs/references/system/job.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const result = CronScheduleSchema.parse(data);
| :--- | :--- | :--- | :--- |
| **type** | `'cron'` | ✅ | |
| **expression** | `string \| { dialect: 'cron'; source?: string; ast?: any; meta?: object }` | ✅ | Cron expression — cron`0 0 * * *` for daily at midnight. Build emits `{dialect:"cron",source}` envelope. |
| **timezone** | `string` | optional (default: `"UTC"`) | Timezone for cron execution (e.g., "America/New_York") |
| **timezone** | `string` | optional (default: `"UTC"`) | IANA time zone the cron expression is evaluated in (e.g., "America/New_York"). Refused at parse unless it is a member of `iana_time_zone` — the same closed domain and the same `Intl.DateTimeFormat` membership probe `sys_job.timezone` is written against; a UTC offset such as "UTC+8" is not one. |


---
Expand Down Expand Up @@ -75,7 +75,7 @@ const result = CronScheduleSchema.parse(data);
| :--- | :--- | :--- | :--- |
| **type** | `'cron'` | ✅ | |
| **expression** | `string \| { dialect: 'cron'; source?: string; ast?: any; meta?: object }` | ✅ | Cron expression — cron`0 0 * * *` for daily at midnight. Build emits `{dialect:"cron",source}` envelope. |
| **timezone** | `string` | optional (default: `"UTC"`) | Timezone for cron execution (e.g., "America/New_York") |
| **timezone** | `string` | optional (default: `"UTC"`) | IANA time zone the cron expression is evaluated in (e.g., "America/New_York"). Refused at parse unless it is a member of `iana_time_zone` — the same closed domain and the same `Intl.DateTimeFormat` membership probe `sys_job.timezone` is written against; a UTC offset such as "UTC+8" is not one. |

### Nested Shape: `Job.schedule[type='interval']`

Expand Down Expand Up @@ -178,7 +178,7 @@ This schema accepts one of the following structures:
| :--- | :--- | :--- | :--- |
| **type** | `'cron'` | ✅ | |
| **expression** | `string \| { dialect: 'cron'; source?: string; ast?: any; meta?: object }` | ✅ | Cron expression — cron`0 0 * * *` for daily at midnight. Build emits `{dialect:"cron",source}` envelope. |
| **timezone** | `string` | optional (default: `"UTC"`) | Timezone for cron execution (e.g., "America/New_York") |
| **timezone** | `string` | optional (default: `"UTC"`) | IANA time zone the cron expression is evaluated in (e.g., "America/New_York"). Refused at parse unless it is a member of `iana_time_zone` — the same closed domain and the same `Intl.DateTimeFormat` membership probe `sys_job.timezone` is written against; a UTC offset such as "UTC+8" is not one. |

---

Expand Down
23 changes: 21 additions & 2 deletions packages/spec/dropped-refinements.baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"description": "Shrink-only ledger of every PUBLISHED JSON Schema that is STILL WIDER than the Zod type it was generated from, because a rule written as `.refine()` reaches the runtime and not the file (#18670). `z.toJSONSchema()` has no arm for a `custom` check: a plain record, the same record with a `.refine()`, and the same record with an ABORTING `.refine()` all project byte-identically (measured on zod 4.4.3, the version packages/spec resolves). So a document one of these files ACCEPTS can still be refused at parse time, and an author -- or an AI -- validating against packages/spec/json-schema/** finds out a release later. Each `sites` path is a position under that schema at which a refinement is dropped; the same paths are written onto the artifact itself as `x-dropped-refinements`. Item 2 closed the first patterns: a refinement DECLARED through the closed list in src/shared/refinement-projection.ts is emitted into the published file, reads `projected` rather than `dropped`, and its row LEAVES this ledger in the same PR -- which is why the ledger shrinks and never grows on a repair. Every refinement outside that closed list stays here, and adding an arm to the list is a public-contract decision, not a refactor. Hand-edited on purpose and with no `gen:` script: a generator would let a new gap be admitted by running a command instead of by a decision, which is the silence this ledger exists to end. Adding, removing or moving a site fails packages/spec/scripts/build-schemas.ts until the line moves with it, and the failure prints the corrected entry in full. ⛔ Do not delete or weaken a refinement to shorten this file -- the runtime rule is correct; it is the projection that is silent, and the remedy is to teach the closed list a NAMED pattern, never to drop the rule.",
"measured": {
"zod": "4.4.3",
"publishedSchemasWithDroppedRefinements": 200,
"droppedRefinementSites": 551,
"publishedSchemasWithDroppedRefinements": 203,
"droppedRefinementSites": 558,
"refinementSitesThatDidProject": 357,
"refinementSitesWithNoJsonFormToCompare": 9
},
Expand Down Expand Up @@ -61,6 +61,7 @@
"manifest.flows.element",
"manifest.flows.element.errorHandling",
"manifest.flows.element.nodes.element.in.waitEventConfig",
"manifest.jobs.element.schedule.options[0].timezone",
"manifest.navigationContributions.element.items.element.lazy.options[0]",
"manifest.objectExtensions.element",
"manifest.objects.element",
Expand Down Expand Up @@ -152,6 +153,7 @@
"data.options[1].manifest.flows.element",
"data.options[1].manifest.flows.element.errorHandling",
"data.options[1].manifest.flows.element.nodes.element.in.waitEventConfig",
"data.options[1].manifest.jobs.element.schedule.options[0].timezone",
"data.options[1].manifest.objectExtensions.element",
"data.options[1].manifest.objects.element",
"data.options[1].manifest.objects.element.fieldGroups",
Expand Down Expand Up @@ -232,6 +234,7 @@
"options[1].manifest.flows.element",
"options[1].manifest.flows.element.errorHandling",
"options[1].manifest.flows.element.nodes.element.in.waitEventConfig",
"options[1].manifest.jobs.element.schedule.options[0].timezone",
"options[1].manifest.objectExtensions.element",
"options[1].manifest.objects.element",
"options[1].manifest.objects.element.fieldGroups",
Expand Down Expand Up @@ -273,6 +276,7 @@
"data.packages.element.options[1].manifest.flows.element",
"data.packages.element.options[1].manifest.flows.element.errorHandling",
"data.packages.element.options[1].manifest.flows.element.nodes.element.in.waitEventConfig",
"data.packages.element.options[1].manifest.jobs.element.schedule.options[0].timezone",
"data.packages.element.options[1].manifest.objectExtensions.element",
"data.packages.element.options[1].manifest.objects.element",
"data.packages.element.options[1].manifest.objects.element.fieldGroups",
Expand Down Expand Up @@ -974,6 +978,16 @@
"object.listViews.valueType.timeline.groupByField"
]
},
"system/CronSchedule": {
"sites": [
"timezone"
]
},
"system/Job": {
"sites": [
"schedule.options[0].timezone"
]
},
"system/LifecyclePolicyConfig": {
"sites": [
"rules.element"
Expand Down Expand Up @@ -1009,6 +1023,11 @@
"buckets.element.lifecyclePolicy.rules.element"
]
},
"system/Schedule": {
"sites": [
"options[0].timezone"
]
},
"system/ServerRateLimitConfig": {
"sites": [
""
Expand Down
79 changes: 79 additions & 0 deletions packages/spec/src/system/job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ScheduleSchema,
RetryPolicySchema,
JobSchema,
defineJob,
JobExecutionStatus,
JobExecutionSchema,
type Schedule,
Expand All @@ -16,6 +17,7 @@ import {
type Job,
type JobExecution,
} from './job.zod';
import { isValueDomainMember } from '../shared/value-domain.zod';

describe('CronScheduleSchema', () => {
it('should accept valid cron schedule', () => {
Expand Down Expand Up @@ -63,6 +65,83 @@ describe('CronScheduleSchema', () => {
});
});

/**
* `CronSchedule.timezone` is judged by the package's own `iana_time_zone`
* membership predicate (#16292) — the authoring door for the value the
* scheduler actually honours, which the `sys_job.timezone` column cannot judge
* because it is a write-only mirror.
*
* ⚠️ **No pinned zone list here, deliberately.** Membership is the
* `Intl.DateTimeFormat` probe, so the accept set is a function of the host's
* ICU. A test enumerating zones would be a verdict about this container's tz
* database; the invariant that actually belongs to this schema is that its
* verdict EQUALS `isValueDomainMember('iana_time_zone', …)` for every input, on
* whatever host runs it. The zone-by-zone traps (`UTC` and `Asia/Kolkata` are
* members although `Intl.supportedValuesOf` omits both, `Europe/Munich` is not)
* are pinned once, where the predicate lives:
* `packages/spec/src/shared/value-domain.test.ts`.
*
* The two ends asserted absolutely are the two this contract cannot survive
* without, and both are ICU-independent: `'UTC'` — the schema's own declared
* default, which ECMA-402 requires every runtime to carry, so the narrowing can
* never refuse an omitted key — and `'UTC+8'`, an offset that names no zone.
*/
describe('CronScheduleSchema.timezone — iana_time_zone membership (#16292)', () => {
const parseTz = (timezone: string) =>
CronScheduleSchema.safeParse({ type: 'cron', expression: '0 0 * * *', timezone });

/** Shapes an author plausibly writes, both sides of the line. */
const CORPUS = [
'UTC', 'Asia/Shanghai', 'America/New_York', 'Asia/Kolkata', 'Europe/Kyiv',
'US/Eastern', 'GMT', 'America/Argentina/Buenos_Aires', 'europe/zurich',
'UTC+8', 'GMT+8', 'Europe/Munich', 'Mars/Olympus', 'China Standard Time',
'+08:00', 'Asia/Shanghai ', '', 'not a zone',
];

it('agrees with the shared predicate on every input — the schema adds no second definition', () => {
for (const value of CORPUS) {
expect(parseTz(value).success, value).toBe(isValueDomainMember('iana_time_zone', value));
}
});

it('admits `UTC`, so the declared default still parses and an omitted key is untouched', () => {
expect(parseTz('UTC').success).toBe(true);
expect(CronScheduleSchema.parse({ type: 'cron', expression: '0 0 * * *' }).timezone).toBe('UTC');
});

it('refuses `UTC+8` with a located issue instead of carrying it to the scheduler', () => {
const result = parseTz('UTC+8');
expect(result.success).toBe(false);
if (result.success) return;
const issue = result.error.issues.find((i) => i.path.join('.') === 'timezone');
expect(issue, 'the refusal must be located on `timezone`, not on the object').toBeDefined();
expect(issue?.code).toBe('custom');
// Not a wording pin: the refusal is an author's only prescription here, and a
// message that names neither the standard nor the offending value leaves them
// with "invalid input" for a value that looks like a time zone.
expect(issue?.message).toContain('IANA');
expect(issue?.message).toContain('UTC+8');
});

it('refuses through `defineJob`, located at `schedule.timezone`', () => {
const config = {
name: 'sync_metadata_nightly',
schedule: { type: 'cron' as const, expression: '0 0 * * *', timezone: 'UTC+8' },
handler: 'syncMetadata',
};
expect(() => defineJob(config)).toThrow();
const result = JobSchema.safeParse(config);
expect(result.success).toBe(false);
if (result.success) return;
expect(result.error.issues.some((i) => i.path.join('.') === 'schedule.timezone')).toBe(true);
});

it('leaves the zoneless branches alone — only the cron variant carries a timezone', () => {
expect(ScheduleSchema.safeParse({ type: 'interval', intervalMs: 60000 }).success).toBe(true);
expect(ScheduleSchema.safeParse({ type: 'once', at: '2026-01-01T00:00:00Z' }).success).toBe(true);
});
});

describe('IntervalScheduleSchema', () => {
it('should accept valid interval schedule', () => {
const schedule: IntervalSchedule = {
Expand Down
42 changes: 41 additions & 1 deletion packages/spec/src/system/job.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,51 @@ import { CronExpressionInputSchema } from '../shared/expression.zod';
import { lazySchema } from '../shared/lazy-schema';
import { strictObject } from '../shared/strict-object';
import { retiredKey } from '../shared/retired-key';
import { isValueDomainMember } from '../shared/value-domain.zod';
import { MetadataProtectionFields } from '../kernel/metadata-protection.zod';

/**
* The cron zone's authoring door — `iana_time_zone` membership, judged by the
* package's own shared predicate (#16292).
*
* The same concept is judged by the same predicate at four columns already
* (`sys_business_unit.timezone`, `sys_organization.timezone`, `sys_job.timezone`,
* `sys_report_schedule.timezone`, all via `valueDomain: 'iana_time_zone'`), and
* `sys_job.timezone` is a WRITE-ONLY mirror — `DbJobAdapter.upsertJobRow` writes
* it and nothing reads it back — so that column never judges the value the
* scheduler actually honours. This is the separate, earlier door: the value an
* author writes here is the one `toBoundaryJobSchedule` carries to
* `CronJobAdapter.schedule`, where croner (constructed with a callback) throws on
* a non-member and `AppPlugin` logs a per-job FAILED TO SCHEDULE at `error`. The
* job is then declared and never runs. Refusing at parse moves that discovery
* from "whichever environment boots first" to `defineJob` / `os build`.
*
* ⚠️ Membership is the runtime's ICU answer, not a checked-in list — the
* `Intl.DateTimeFormat` probe the module header of `shared/value-domain.zod.ts`
* argues for at length (the `Intl.supportedValuesOf('timeZone')` enumeration
* omits `UTC`, this platform's own default). That is deliberate and is the SAME
* exposure the four columns, the settings door and `resolveAuthzContext` already
* carry: the accept set here is exactly what every `Intl`-based consumer
* downstream accepts, so parse-time and schedule-time cannot disagree on one
* host. ⛔ Do not substitute a pattern or a pinned zone list — both re-admit
* `Europe/Munich`, a shape-valid zone that does not exist.
*/
const CronTimezoneSchema = z.string().refine(
(value) => isValueDomainMember('iana_time_zone', value),
{
error: (issue) =>
`'${String(issue.input)}' is not an IANA time zone identifier. `
+ `Write a zone the platform can honour — 'UTC', 'Asia/Shanghai', 'America/New_York' — `
+ `not a UTC offset ('UTC+8'), a Windows zone name ('China Standard Time') or a `
+ `zone that does not exist ('Europe/Munich'). Membership is the Intl.DateTimeFormat `
+ `probe, the same judge as valueDomain: 'iana_time_zone' on sys_job.timezone.`,
},
);

export const CronScheduleSchema = lazySchema(() => z.object({
type: z.literal('cron'),
expression: CronExpressionInputSchema.describe('Cron expression — cron`0 0 * * *` for daily at midnight. Build emits {dialect:"cron",source} envelope.'),
timezone: z.string().optional().default('UTC').describe('Timezone for cron execution (e.g., "America/New_York")'),
timezone: CronTimezoneSchema.optional().default('UTC').describe('IANA time zone the cron expression is evaluated in (e.g., "America/New_York"). Refused at parse unless it is a member of `iana_time_zone` — the same closed domain and the same `Intl.DateTimeFormat` membership probe `sys_job.timezone` is written against; a UTC offset such as "UTC+8" is not one.'),
}));

/**
Expand Down
Loading