Skip to content

Commit 9861585

Browse files
willsmanleyclaude
andcommitted
fix(scheduler): address review of the time zone option
The update_scheduled_task description said every optional schedule field left out of an update keeps its stored value. Only timeZone, webhook dedupe and filters do; a left-out signature turns off signature checks and left-out weekdays make the task daily. The description now says which fields to resend. A client whose time zone data lacked a zone the server had accepted refused every edit to that task. The web and mobile forms now leave an unchanged zone out of the save, so the server keeps it, and still refuse a newly typed unknown zone. The user guide said a skipped time runs an hour later; it runs later by the size of the clock change, which is 30 minutes on Lord Howe Island. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7b635bc commit 9861585

10 files changed

Lines changed: 65 additions & 12 deletions

File tree

‎apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScroll
5151
import { SegmentedControl } from "../../components/ui/SegmentedControl";
5252
import { ThemedSwitch } from "../../components/ui/ThemedSwitch";
5353
import { webhookAddress } from "@t3tools/client-runtime/webhook-address";
54-
import { localTimeZone, parseTimeZoneDraft } from "@t3tools/client-runtime/scheduled-task-schedule";
54+
import { localTimeZone, timeZoneForSave } from "@t3tools/client-runtime/scheduled-task-schedule";
5555
import { tryCopyTextWithHaptic } from "../../lib/copyTextWithHaptic";
5656
import { usePreparedConnection } from "../../state/session";
5757
import { buildModelOptions } from "../../lib/modelOptions";
@@ -719,7 +719,7 @@ function TaskForm({
719719
}
720720
if (
721721
draft.schedule.mode === "fixed_time" &&
722-
parseTimeZoneDraft(draft.schedule.timeZone) === undefined
722+
timeZoneForSave(draft.schedule.timeZone, draft.schedule.savedTimeZone) === undefined
723723
) {
724724
Dialog.alert(
725725
"Unknown time zone",

‎apps/mobile/src/features/settings/scheduledTaskDraft.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ describe("scheduleFromDraft", () => {
103103
expect(scheduleFromDraft({ ...draft, timeZone: "Chicago" })).toBeNull();
104104
});
105105

106+
it("keeps a stored zone this client's time zone data lacks when other fields change", () => {
107+
const draft = scheduleDraftForTask({
108+
schedule: { type: "fixed_time", timeOfDay: "09:00", timeZone: "Mars/Olympus_Mons" },
109+
});
110+
expect(scheduleFromDraft({ ...draft, timeOfDay: "10:00" })).toEqual({
111+
type: "fixed_time",
112+
timeOfDay: "10:00",
113+
});
114+
expect(scheduleFromDraft({ ...draft, timeZone: "Mars/Tharsis" })).toBeNull();
115+
});
116+
106117
it.each([
107118
["1.5", 90_000],
108119
[String(60_001 / 60_000), 60_001],

‎apps/mobile/src/features/settings/scheduledTaskDraft.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
webhookFilterDraftsChanged,
1818
type WebhookFilterDraft,
1919
} from "@t3tools/client-runtime/scheduled-task-webhook";
20-
import { parseTimeZoneDraft } from "@t3tools/client-runtime/scheduled-task-schedule";
20+
import { timeZoneForSave } from "@t3tools/client-runtime/scheduled-task-schedule";
2121
import {
2222
resolveProjectSettings,
2323
type LegacyProjectSettingsFields,
@@ -57,6 +57,8 @@ export type ScheduleDraft = {
5757
readonly weekdays: ReadonlyArray<number>;
5858
/** Blank runs at the environment's local time. */
5959
readonly timeZone: string;
60+
/** The zone the form opened with. */
61+
readonly savedTimeZone: string;
6062
readonly intervalMinutes: string;
6163
readonly signature: ScheduledTaskWebhookSignature | null;
6264
readonly maxDeliveryAgeMinutes: string;
@@ -73,6 +75,7 @@ export const DEFAULT_SCHEDULE: ScheduleDraft = {
7375
timeOfDay: "09:00",
7476
weekdays: [1, 2, 3, 4, 5],
7577
timeZone: "",
78+
savedTimeZone: "",
7679
intervalMinutes: "15",
7780
signature: null,
7881
maxDeliveryAgeMinutes: "",
@@ -93,6 +96,7 @@ export function scheduleDraftForTask(task: Pick<ScheduledTask, "schedule">): Sch
9396
? [...new Set(task.schedule.weekdays)].sort((a, b) => a - b)
9497
: [0, 1, 2, 3, 4, 5, 6],
9598
timeZone: task.schedule.timeZone ?? "",
99+
savedTimeZone: task.schedule.timeZone ?? "",
96100
};
97101
case "interval":
98102
return {
@@ -173,7 +177,7 @@ export function scheduleFromDraft(draft: ScheduleDraft): ScheduledTaskUpsertSche
173177
return minutes >= 1 && Number.isSafeInteger(everyMs) ? { type: "interval", everyMs } : null;
174178
}
175179
const weekdays = [...new Set(draft.weekdays)].sort((a, b) => a - b);
176-
const timeZone = parseTimeZoneDraft(draft.timeZone);
180+
const timeZone = timeZoneForSave(draft.timeZone, draft.savedTimeZone);
177181
if (
178182
timeZone === undefined ||
179183
!/^([01]?\d|2[0-3]):[0-5]\d$/.test(draft.timeOfDay) ||
@@ -186,7 +190,7 @@ export function scheduleFromDraft(draft: ScheduleDraft): ScheduledTaskUpsertSche
186190
type: "fixed_time",
187191
timeOfDay: draft.timeOfDay,
188192
...(weekdays.length === 7 ? {} : { weekdays }),
189-
timeZone,
193+
...timeZone,
190194
};
191195
}
192196

‎apps/server/src/mcp/toolkits/orchestrator/tools.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const ListScheduledTasksTool = Tool.make("list_scheduled_tasks", {
145145

146146
const UpdateScheduledTaskTool = Tool.make("update_scheduled_task", {
147147
description:
148-
"Update an existing scheduled task by scheduledTaskId (from list_scheduled_tasks). Webhook schedule dedupe accepts replayKey, coalesceKey, and coalesceWindowSeconds (10–3600, default 120) to suppress replays for 7 days and retain the latest payload in each fixed window. Only the provided fields change; omit a field to leave it as-is. The same holds inside schedule: an optional field such as timeZone that you leave out keeps its stored value, and null removes it. Use enabled=false to pause a task without deleting it. Set bindToCurrentThread to move the task between posting into this thread and launching a fresh thread per run. A webhook schedule without filters keeps the stored filters; pass filters to replace them, or filters:[] to clear them.",
148+
"Update an existing scheduled task by scheduledTaskId (from list_scheduled_tasks). Webhook schedule dedupe accepts replayKey, coalesceKey, and coalesceWindowSeconds (10–3600, default 120) to suppress replays for 7 days and retain the latest payload in each fixed window. Only the provided fields change; omit a field to leave it as-is. A schedule you pass replaces the stored one, but a fixed_time timeZone you leave out is kept (null removes it), as are webhook dedupe and filters. So resend a fixed_time's weekdays, or it runs every day. On a signed webhook, resend signature with its header, encoding and prefix, or signature checks stop; the stored secret is kept. Resend maxDeliveryAgeMinutes too, or the age limit is removed. Use enabled=false to pause a task without deleting it. Set bindToCurrentThread to move the task between posting into this thread and launching a fresh thread per run. A webhook schedule without filters keeps the stored filters; pass filters to replace them, or filters:[] to clear them.",
149149
parameters: OrchestratorMcpUpdateScheduledTaskInput,
150150
success: OrchestratorMcpScheduleTaskResult,
151151
failure: OrchestratorMcpFailure,

‎apps/server/src/scheduledTasks/Schedule.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ describe("scheduled task schedule calculation", () => {
5656
expect(next({ timeOfDay: "02:30" }, "2026-03-08T08:31:00.000Z")).toBe(
5757
"2026-03-09T07:30:00.000Z",
5858
);
59+
// Lord Howe Island moves forward 30 minutes on October 4, so 02:15 runs at 02:45.
60+
expect(
61+
next({ timeOfDay: "02:15", timeZone: "Australia/Lord_Howe" }, "2026-10-03T14:00:00.000Z"),
62+
).toBe("2026-10-03T15:45:00.000Z");
5963
});
6064

6165
it("keeps the wall-clock time across the fall-back change and runs a repeated time once", () => {

‎apps/web/src/components/settings/ScheduledTasksSettings.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ const EMPTY_DRAFT: DraftState = {
141141
timeOfDay: "09:00",
142142
weekdays: new Set([1, 2, 3, 4, 5]),
143143
timeZone: "",
144+
savedTimeZone: "",
144145
projectId: "",
145146
threadId: "",
146147
workspaceMode: "worktree",

‎apps/web/src/components/settings/scheduledTasksSettings.logic.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ describe("timed schedule settings", () => {
166166
expect(scheduleFromDraft({ ...draft, timeZone: " " })).toMatchObject({ timeZone: null });
167167
expect(scheduleFromDraft({ ...draft, timeZone: "Chicago" })).toBeNull();
168168
});
169+
170+
it("keeps a stored zone this client's time zone data lacks when other fields change", () => {
171+
const draft = taskToDraft({
172+
...legacyTask,
173+
schedule: { type: "fixed_time", timeOfDay: "09:00", timeZone: "Mars/Olympus_Mons" },
174+
});
175+
expect(scheduleFromDraft({ ...draft, timeOfDay: "10:00" })).toEqual({
176+
type: "fixed_time",
177+
timeOfDay: "10:00",
178+
});
179+
expect(scheduleFromDraft({ ...draft, timeZone: "Mars/Tharsis" })).toBeNull();
180+
});
169181
});
170182

171183
describe("webhook scheduled tasks", () => {

‎apps/web/src/components/settings/scheduledTasksSettings.logic.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
webhookFilterDraftsChanged,
1919
type WebhookFilterDraft,
2020
} from "@t3tools/client-runtime/scheduled-task-webhook";
21-
import { parseTimeZoneDraft } from "@t3tools/client-runtime/scheduled-task-schedule";
21+
import { timeZoneForSave } from "@t3tools/client-runtime/scheduled-task-schedule";
2222

2323
import {
2424
resolveProjectSettings,
@@ -67,6 +67,8 @@ export interface DraftState {
6767
readonly weekdays: ReadonlySet<number>;
6868
/** Blank runs at the environment's local time. */
6969
readonly timeZone: string;
70+
/** The zone the form opened with. */
71+
readonly savedTimeZone: string;
7072
readonly projectId: string;
7173
readonly threadId: string;
7274
readonly workspaceMode: WorkspaceMode;
@@ -104,7 +106,10 @@ export const WEBHOOK_SIGNATURE_DEFAULTS = {
104106

105107
export function scheduleDraftErrors(draft: DraftState) {
106108
if (draft.scheduleMode === "webhook") return webhookDraftErrors(draft);
107-
if (draft.scheduleMode === "fixed" && parseTimeZoneDraft(draft.timeZone) === undefined)
109+
if (
110+
draft.scheduleMode === "fixed" &&
111+
timeZoneForSave(draft.timeZone, draft.savedTimeZone) === undefined
112+
)
108113
return [
109114
{
110115
title: "Unknown time zone",
@@ -208,7 +213,7 @@ export function scheduleFromDraft(draft: DraftState): ScheduledTaskUpsertSchedul
208213
type: "fixed_time",
209214
timeOfDay: draft.timeOfDay || "09:00",
210215
...(selectedEveryDay ? {} : { weekdays: [...draft.weekdays].toSorted() }),
211-
timeZone: parseTimeZoneDraft(draft.timeZone) ?? null,
216+
...timeZoneForSave(draft.timeZone, draft.savedTimeZone),
212217
};
213218
}
214219

@@ -231,6 +236,7 @@ export function taskToDraft(task: ScheduledTask): DraftState {
231236
timeOfDay: schedule.type === "fixed_time" ? schedule.timeOfDay : "09:00",
232237
weekdays,
233238
timeZone: schedule.type === "fixed_time" ? (schedule.timeZone ?? "") : "",
239+
savedTimeZone: schedule.type === "fixed_time" ? (schedule.timeZone ?? "") : "",
234240
projectId: task.projectId,
235241
threadId: task.threadId ?? "",
236242
workspaceMode: task.workspaceStrategy.type,

‎docs/user/project-settings.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ Leaving an edited form asks before discarding unsaved changes.
8282
A task that runs **At a time** uses the environment's clock unless you set a
8383
**Time zone**, such as `America/Chicago`. It then keeps that local time when
8484
daylight saving starts or ends. A time skipped when clocks move forward runs
85-
an hour later that day, and a time that repeats when they move back runs once.
85+
later by the size of the change, and a time that repeats when they move back
86+
runs once.
8687

8788
## Webhook automations
8889

‎packages/client-runtime/src/scheduledTaskSchedule.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isValidTimeZone } from "@t3tools/contracts";
22

3-
/** Blank means the environment's local time; undefined means the text is not a known zone, which blocks saving. */
4-
export function parseTimeZoneDraft(value: string): string | null | undefined {
3+
/** Blank means the environment's local time; undefined means the text is not a zone this client knows. */
4+
function parseTimeZoneDraft(value: string): string | null | undefined {
55
const zone = value.trim();
66
if (zone === "") return null;
77
// Intl matches names case-insensitively; store the canonical spelling.
@@ -10,6 +10,20 @@ export function parseTimeZoneDraft(value: string): string | null | undefined {
1010
: undefined;
1111
}
1212

13+
/**
14+
* The `timeZone` part of a fixed-time save, or undefined when the entry blocks saving.
15+
* A zone left as it was loaded is omitted when this client's time zone data lacks it;
16+
* the server keeps the stored zone, so other edits to the task still save.
17+
*/
18+
export function timeZoneForSave(
19+
value: string,
20+
saved: string,
21+
): { readonly timeZone?: string | null } | undefined {
22+
const timeZone = parseTimeZoneDraft(value);
23+
if (timeZone !== undefined) return { timeZone };
24+
return value === saved ? {} : undefined;
25+
}
26+
1327
export function localTimeZone(): string {
1428
return Intl.DateTimeFormat().resolvedOptions().timeZone;
1529
}

0 commit comments

Comments
 (0)