Skip to content
This repository was archived by the owner on Oct 21, 2026. It is now read-only.
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
5 changes: 5 additions & 0 deletions apps/server/src/automation/AutomationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ describe("AutomationService", () => {
Option.map(snapshot, (value) => value.automations.map((entry) => entry.name)),
Option.some(["Weekly review"]),
);
// Clients show schedule times in the zone the server evaluates them in.
assert.deepStrictEqual(
Option.map(snapshot, (value) => value.timeZone),
Option.some(Intl.DateTimeFormat().resolvedOptions().timeZone),
);
}),
),
);
Expand Down
6 changes: 5 additions & 1 deletion apps/server/src/automation/AutomationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ function toPublic(stored: StoredAutomation): Automation {
}

function toSnapshot(file: AutomationsFile): AutomationsSnapshot {
return { automations: file.automations.map(toPublic) };
return {
automations: file.automations.map(toPublic),
// Schedules run in the host's local zone, which is what `latestTriggerAt` defaults to.
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
};
}

function githubItemMatches(event: AutomationGitHubEvent, item: GitHubItem): boolean {
Expand Down
37 changes: 32 additions & 5 deletions apps/web/src/components/automations/AutomationsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,15 @@ function AutomationEditor({
const primaryEnvironmentId = usePrimaryEnvironmentId();
const connectedEnvironments = useConnectedEnvironments();
const projects = useProjects();
const { timeZones } = useAutomations();
// A new draft runs on this device's server until the user picks another environment.
const environmentId =
draft.environmentId ??
connectedEnvironments.find((environment) => environment.environmentId === primaryEnvironmentId)
?.environmentId ??
connectedEnvironments[0]?.environmentId ??
null;
const timeZone = environmentId ? timeZones.get(environmentId) : undefined;

const patch = (next: Partial<AutomationDraft>) =>
setDraft((current) => ({ ...current, ...next }));
Expand Down Expand Up @@ -702,6 +704,7 @@ function AutomationEditor({
// oxlint-disable-next-line react/no-array-index-key -- triggers have no identity of their own
key={index}
trigger={trigger}
timeZone={timeZone}
onChange={(next) =>
patch({
triggers: draft.triggers.map((entry, i) => (i === index ? next : entry)),
Expand All @@ -716,6 +719,13 @@ function AutomationEditor({
<p className="text-xs text-muted-foreground">
Without a trigger, the automation only runs when you press Run now.
</p>
) : draft.triggers.some((trigger) => trigger.type !== "github") ? (
<p className="text-xs text-muted-foreground">
{timeZone ? `Times use ${timeZone}. ` : null}
{draft.catchUpMinutes === 0
? "Missed runs are skipped."
: `Missed runs are skipped after ${formatCatchUpWindow(draft.catchUpMinutes)}.`}
</p>
) : null}
</EditorSection>

Expand Down Expand Up @@ -897,6 +907,11 @@ function OptionSelect<T extends string>({
);
}

function formatCatchUpWindow(minutes: number): string {
if (minutes % 60 === 0) return minutes === 60 ? "1 hour" : `${minutes / 60} hours`;
return minutes === 1 ? "1 minute" : `${minutes} minutes`;
}

const CADENCE_LABELS: Record<AutomationScheduleCadence, string> = {
hourly: "Hourly",
daily: "Daily",
Expand All @@ -911,10 +926,12 @@ const MINUTE_OPTIONS = Array.from({ length: 12 }, (_, index) => {

function TriggerRow({
trigger,
timeZone,
onChange,
onRemove,
}: {
trigger: AutomationTrigger;
timeZone: string | undefined;
onChange: (trigger: AutomationTrigger) => void;
onRemove: () => void;
}) {
Expand All @@ -927,7 +944,7 @@ function TriggerRow({
<span className="text-muted-foreground"> on the project's GitHub repository</span>
</span>
) : trigger.type === "cron" ? (
<CronTriggerFields trigger={trigger} onChange={onChange} />
<CronTriggerFields trigger={trigger} timeZone={timeZone} onChange={onChange} />
) : (
<>
<CadenceSelect
Expand Down Expand Up @@ -971,7 +988,7 @@ function TriggerRow({
}}
/>
)}
<NextRunLabel trigger={trigger} />
<NextRunLabel trigger={trigger} timeZone={timeZone} />
</>
)}
<Button
Expand Down Expand Up @@ -1011,9 +1028,11 @@ function CadenceSelect({

function CronTriggerFields({
trigger,
timeZone,
onChange,
}: {
trigger: AutomationCronTrigger;
timeZone: string | undefined;
onChange: (trigger: AutomationTrigger) => void;
}) {
const label = describeCronExpression(trigger.expression);
Expand Down Expand Up @@ -1044,17 +1063,24 @@ function CronTriggerFields({
) : (
<>
<span className="text-xs">{label}</span>
<NextRunLabel trigger={trigger} />
<NextRunLabel trigger={trigger} timeZone={timeZone} />
</>
)}
</>
);
}

function NextRunLabel({ trigger }: { trigger: AutomationTimedTrigger }) {
/** The next run in the server's zone, which can differ from this device's for a remote server. */
function NextRunLabel({
trigger,
timeZone,
}: {
trigger: AutomationTimedTrigger;
timeZone: string | undefined;
}) {
// Read once on mount: the label only needs to be right while the user is editing the row.
const [now] = useState(Date.now);
const next = nextTriggerAt(trigger, now);
const next = nextTriggerAt(trigger, now, timeZone);
if (next === null) return null;
return (
<span className="text-xs text-muted-foreground">
Expand All @@ -1063,6 +1089,7 @@ function NextRunLabel({ trigger }: { trigger: AutomationTimedTrigger }) {
weekday: "short",
hour: "2-digit",
minute: "2-digit",
...(timeZone ? { timeZone } : {}),
})}
</span>
);
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/state/automations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ export const runAutomationNow = createEnvironmentRpcCommand(connectionAtomRuntim

interface AutomationsView {
readonly automations: readonly EnvironmentAutomation[];
/** The zone each environment reads schedules in, when it reports one. */
readonly timeZones: ReadonlyMap<EnvironmentId, string>;
/** True while a reachable environment has not answered yet. */
readonly isPending: boolean;
}

const allAutomationsAtom = Atom.make((get): AutomationsView => {
const automations: EnvironmentAutomation[] = [];
const timeZones = new Map<EnvironmentId, string>();
let isPending = false;
for (const [environmentId, presentation] of get(environmentPresentations.presentationsAtom)) {
const result = get(automationsByEnvironment({ environmentId, input: {} }));
Expand All @@ -63,12 +66,13 @@ const allAutomationsAtom = Atom.make((get): AutomationsView => {
isPending ||= result._tag !== "Failure" && isAnswerExpected(presentation);
continue;
}
if (snapshot.timeZone) timeZones.set(environmentId, snapshot.timeZone);
for (const automation of snapshot.automations) {
automations.push({ ...automation, environmentId });
}
}
automations.sort((a, b) => a.name.localeCompare(b.name));
return { automations, isPending };
return { automations, timeZones, isPending };
}).pipe(Atom.withLabel("web-automations:all"));

export function useAutomations(): AutomationsView {
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export type Automation = typeof Automation.Type;

export const AutomationsSnapshot = Schema.Struct({
automations: Schema.Array(Automation),
/** IANA zone the server reads schedules in. Absent from servers that predate it. */
timeZone: Schema.optional(TrimmedNonEmptyString),
});
export type AutomationsSnapshot = typeof AutomationsSnapshot.Type;

Expand Down
Loading