Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
dece518
fix(server): make scheduled-task edits atomic
github-actions[bot] Sep 21, 2026
4f5fbac
fix(server): pause scheduled tasks bound to archived threads
github-actions[bot] Sep 24, 2026
4452f5d
fix(server): preserve scheduled task update error causes
github-actions[bot] Sep 26, 2026
43b47fa
feat(server): restrict scheduled tasks to days, hours, and run caps
github-actions[bot] Sep 28, 2026
5183a31
fix(server): decide the run cap from the live row and judge windows a…
github-actions[bot] Sep 30, 2026
f94b2f2
fix(server): refuse to start a run once the cap is reached
github-actions[bot] Sep 30, 2026
f470dc1
fix(server): guard reschedule and re-enable against stale snapshots
github-actions[bot] Sep 30, 2026
76673c1
fix(server): preserve scheduled-task edits across mixed server versions
github-actions[bot] Sep 30, 2026
d2c7ba7
fix(server): preserve atomic schedule edits on current OV2
github-actions[bot] Sep 30, 2026
2f1e43d
fix(server): preserve archive-bound scheduling and authorization
github-actions[bot] Sep 30, 2026
a3821de
fix(server): integrate atomic schedule updates with archive guards
github-actions[bot] Sep 30, 2026
11b49bf
fix(server): integrate schedule caps with atomic archive handling
github-actions[bot] Sep 30, 2026
7eb5427
test(server): encode scheduled-run fixtures with Effect Schema
github-actions[bot] Sep 30, 2026
3c9a91e
fix(clients): show the scheduled-task Enabled switch as a save will l…
github-actions[bot] Oct 1, 2026
01a7974
fix(scheduled-tasks): keep window openings in the future across fall-…
github-actions[bot] Oct 2, 2026
47ff798
fix(server): run a restricted interval when the clock re-enters its w…
github-actions[bot] Oct 2, 2026
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
Prev Previous commit
Next Next commit
fix(scheduled-tasks): keep window openings in the future across fall-…
…back, show unpadded times

Two Macroscope findings on the scheduled-task restrictions:

- In a repeated fall-back hour, the restricted interval schedule added the
  interval with calendar arithmetic, which re-resolves the repeated hour to
  its first occurrence. The next run could land before the current time,
  so a window opening inside that hour kept the task due and rescheduled
  on every poll. The restricted path now adds elapsed time, and a window
  opening that resolves before the candidate steps forward on the
  candidate's own offset.
- The contract accepts window times such as "9:00", but the web editor
  passed them unchanged to native time inputs, which only display
  zero-padded HH:mm, so the configured window showed as blank. The editor
  now pads them when it reads a task.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
  • Loading branch information
github-actions[bot] and claude committed Oct 2, 2026
commit 01a7974c83af71ee6c8a023a9e7e343952527433
15 changes: 15 additions & 0 deletions apps/server/src/scheduledTasks/Schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ describe("interval restrictions at dispatch and across DST", () => {
expect(next && DateTime.toParts(next)).toMatchObject({ day: 9, hour: 2, minute: 10 });
});

it("opens a window at the later 01:30 when a fall-back hour repeats", () => {
// 2026-11-01 01:00-02:00 occurs twice in New York; 06:05Z is the
// repeated 01:05 (EST), after the first 01:30 (EDT) has passed.
const from = DateTime.makeZonedUnsafe("2026-11-01T06:05:00Z", {
timeZone: "America/New_York",
});
expect(DateTime.toParts(from)).toMatchObject({ hour: 1, minute: 5 });
const next = nextScheduledRunAt(
{ type: "interval", everyMs: 15 * 60_000, window: { start: "01:30", end: "03:00" } },
from,
);
expect(next).not.toBeNull();
expect(next && DateTime.toEpochMillis(next)).toBe(DateTime.toEpochMillis(from) + 25 * 60_000);
});

it("finds the next Sunday window even when it opens inside a spring-forward gap", () => {
const from = zoned("America/New_York", { year: 2026, month: 3, day: 1, hour: 5, minute: 0 });
const next = nextScheduledRunAt(
Expand Down
16 changes: 14 additions & 2 deletions apps/server/src/scheduledTasks/Schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function nextRestrictedIntervalRun(
schedule.weekdays && schedule.weekdays.length > 0 ? new Set(schedule.weekdays) : null;
const windowStart = schedule.window ? minutesOfDay(schedule.window.start) : null;
const windowEnd = schedule.window ? minutesOfDay(schedule.window.end) : null;
let candidate = DateTime.add(from, { milliseconds: everyMs });
// Elapsed-time arithmetic: a calendar add would re-resolve a repeated
// fall-back hour to its first occurrence and step backwards.
let candidate = DateTime.addDuration(from, everyMs);
for (let hop = 0; hop < 16; hop += 1) {
if (weekdays !== null && !weekdays.has(DateTime.toParts(candidate).weekDay)) {
candidate = startOfNextDay(candidate);
Expand All @@ -55,12 +57,22 @@ function nextRestrictedIntervalRun(
continue;
}
if (local >= windowStart) return candidate;
const opensAt = DateTime.setParts(atMidnight(candidate), {
const wallClockOpening = DateTime.setParts(atMidnight(candidate), {
hour: Math.floor(windowStart / 60),
minute: windowStart % 60,
second: 0,
millisecond: 0,
});
// In a fall-back overlap the wall-clock opening resolves to its earlier
// occurrence, which can precede the candidate; step forward on the
// candidate's own offset to the repeated opening instead.
const { second, millisecond } = DateTime.toParts(candidate);
const opensAt = DateTime.isGreaterThan(wallClockOpening, candidate)
? wallClockOpening
: DateTime.addDuration(
candidate,
(windowStart - local) * MINUTE_MS - second * 1000 - millisecond,
);
// A window opening inside a spring-forward gap does not exist that day.
if (localMinutes(opensAt) === windowStart) return opensAt;
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
Resolved
candidate = startOfNextDay(candidate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ describe("interval restrictions round-trip through the draft", () => {
expect(scheduleFromDraft(draft)).toEqual(restrictedTask.schedule);
});

it("pads a single-digit window hour so the time inputs can show it", () => {
// The contract accepts "9:00" (for example from an MCP client), but a
// native time input only displays zero-padded HH:mm values.
const draft = taskToDraft({
...restrictedTask,
schedule: { type: "interval", everyMs: 1_800_000, window: { start: "9:00", end: "17:00" } },
});
expect(draft.windowStart).toBe("09:00");
expect(draft.windowEnd).toBe("17:00");
});

it("reads an unrestricted interval as windowless with no cap", () => {
const draft = taskToDraft(legacyTask);
expect(draft.intervalWeekdays.size).toBe(0);
Expand Down
14 changes: 12 additions & 2 deletions apps/web/src/components/settings/scheduledTasksSettings.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ export function runCapReached(task: ScheduledTask): boolean {
return task.schedule.maxRuns !== undefined && task.runCount >= task.schedule.maxRuns;
}

/** "9:00" -> "09:00": native time inputs only display zero-padded HH:mm. */
function paddedTime(value: string): string {
const [hours, minutes] = value.trim().split(":");
return hours !== undefined && minutes !== undefined
? `${hours.padStart(2, "0")}:${minutes}`
: value;
}

export function taskToDraft(task: ScheduledTask): DraftState {
const schedule = task.schedule;
const weekdays =
Expand All @@ -167,8 +175,10 @@ export function taskToDraft(task: ScheduledTask): DraftState {
schedule.type === "interval" ? String(Math.max(1, schedule.everyMs / 60_000)) : "15",
intervalWeekdays: new Set(schedule.type === "interval" ? (schedule.weekdays ?? []) : []),
windowEnabled: schedule.type === "interval" && schedule.window !== undefined,
windowStart: schedule.type === "interval" && schedule.window ? schedule.window.start : "09:00",
windowEnd: schedule.type === "interval" && schedule.window ? schedule.window.end : "17:00",
windowStart:
schedule.type === "interval" && schedule.window ? paddedTime(schedule.window.start) : "09:00",
windowEnd:
schedule.type === "interval" && schedule.window ? paddedTime(schedule.window.end) : "17:00",
maxRuns: schedule.maxRuns === undefined ? "" : String(schedule.maxRuns),
timeOfDay: schedule.type === "fixed_time" ? schedule.timeOfDay : "09:00",
weekdays,
Expand Down