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
8 changes: 6 additions & 2 deletions docs/features/recurring-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,13 @@ When completion changes, `scheduled` updates to the next uncompleted instance. I

This means completion history and next-action planning stay synchronized automatically, without manually advancing recurring tasks.

### Rescheduling clears later instances
### Rescheduling and recorded instances

When you change a recurring task's scheduled date (from the context menu or the scheduled-date field), TaskNotes restarts the timeline from the new date: it clears every completed and skipped instance dated **on or after** that date, while keeping older instances as history. This reactivates occurrences you had completed or skipped off-schedule so they can be acted on again. Because clearing is destructive, TaskNotes asks you to confirm first — listing the dates that will be cleared — and cancelling leaves both the schedule and the recorded instances untouched.
For **scheduled-anchored** recurring tasks, moving the next occurrence keeps its original rule date in `recurrence_original_date` and leaves other occurrences' completed and skipped history untouched — even when you move it earlier than a skipped date or onto a previously completed day. When a moved occurrence has no `recurrence_original_date` (such as a Google Calendar-synced task or an older off-pattern note without a marker), moving it onto a day that is already completed or skipped clears only that landing day so the rescheduled occurrence is active there.

For **completion-anchored** recurring tasks, changing the scheduled date re-anchors the timeline and clears every completed and skipped instance dated **on or after** the new date, while keeping older instances as history.

Whenever a reschedule would clear recorded instances from the context menu or the scheduled-date field, TaskNotes asks you to confirm first — listing the dates that will be cleared — and cancelling leaves both the schedule and the recorded instances untouched.

## Flexible Scheduling

Expand Down
1 change: 1 addition & 0 deletions docs/releases/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ When a change has user-facing documentation, include a canonical tasknotes.dev l

## Fixed

- (#2691) Moving the next occurrence of a scheduled-anchored recurring task no longer clears completed or skipped history on other dates. Moves without a `recurrence_original_date` (such as Google-synced or legacy off-pattern notes) clear only the landing day when it is already recorded, still behind confirmation; completion-anchored recurring tasks keep clearing recorded instances on or after the new date. See [Recurring Tasks](https://tasknotes.dev/features/recurring-tasks/#rescheduling-and-recorded-instances). Thanks to @martin-forge for reporting.
- (#2706) Fixed mdbase validation of scheduled and due times written by TaskNotes. Existing generated type definitions are updated when TaskNotes loads the vault.
- Thanks to @iantierney for reporting
- Protect task notes from being emptied by a failed save, including during workflow loops. If TaskNotes cannot restore an empty note, it keeps a recovery copy and includes its location in the error. Thanks to @chrabia for reporting ([Workflows issue 27](https://github.com/callumalpass/tasknotes-workflows/issues/27)).
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,8 @@ export default class TaskNotesPlugin extends Plugin {

/**
* Ask the user to confirm clearing recorded completed/skipped instances that a
* reschedule would remove (those on or after the new scheduled date).
* reschedule would remove (the landing day for unmarked scheduled-anchored
* moves, or instances on or after the new date for completion-anchored tasks).
*/
private async confirmClearRescheduledInstances(cleared: {
complete: string[];
Expand Down
66 changes: 40 additions & 26 deletions src/services/TaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,12 @@ export class TaskService {
clearRecurringMoveAfterSeriesChange(freshTask, updatePlan.updatedTask);
}

// Reschedule reactivates the timeline: drop instances on/after the new date
// (kept as YYYY-MM-DD, so a lexicographic compare is chronological).
// Completion-anchored moves re-anchor the timeline and clear recorded instances
// on or after the new date (YYYY-MM-DD lexicographic order is chronological).
// Scheduled-anchored moves preserve other occurrences' history when the moved
// occurrence keeps its rule identity in `recurrence_original_date`; only an
// unmarked occurrence (such as a Google-synced or legacy off-pattern note)
// clears a recorded landing day.
let rescheduleClearedOccurrence = false;
if (
property === "scheduled" &&
Expand All @@ -716,32 +720,42 @@ export class TaskService {
const previousScheduledDateStr = getDatePart(freshTask.scheduled);
const scheduledDateStr = getDatePart(updatePlan.normalizedValue);
const scheduledDateChanged = previousScheduledDateStr !== scheduledDateStr;
const completeInstances = freshTask.complete_instances ?? [];
const skippedInstances = freshTask.skipped_instances ?? [];
const removedComplete = completeInstances.filter((d) => d >= scheduledDateStr);
const removedSkipped = skippedInstances.filter((d) => d >= scheduledDateStr);
if (
scheduledDateChanged &&
(removedComplete.length > 0 || removedSkipped.length > 0)
) {
// Give the caller a chance to confirm the destructive clear before
// anything is written; a false result aborts the whole reschedule.
if (options.confirmClearInstances) {
const proceed = await options.confirmClearInstances({
complete: removedComplete,
skipped: removedSkipped,
});
if (!proceed) {
return freshTask;
const isCompletionAnchored =
(freshTask.recurrence_anchor || "scheduled") === "completion";
const hasMoveIdentity = Boolean(
updatePlan.updatedTask.recurrence_original_date ||
getRecurringMoveOriginalDate(freshTask) === scheduledDateStr
);
const shouldClear = isCompletionAnchored
? (d: string) => d >= scheduledDateStr
: !hasMoveIdentity
? (d: string) => d === scheduledDateStr
: null;
if (scheduledDateChanged && shouldClear) {
const completeInstances = freshTask.complete_instances ?? [];
const skippedInstances = freshTask.skipped_instances ?? [];
const removedComplete = completeInstances.filter(shouldClear);
const removedSkipped = skippedInstances.filter(shouldClear);
if (removedComplete.length > 0 || removedSkipped.length > 0) {
// Give the caller a chance to confirm the destructive clear before
// anything is written; a false result aborts the whole reschedule.
if (options.confirmClearInstances) {
const proceed = await options.confirmClearInstances({
complete: removedComplete,
skipped: removedSkipped,
});
if (!proceed) {
return freshTask;
}
}
rescheduleClearedOccurrence = true;
updatePlan.updatedTask.complete_instances = completeInstances.filter(
(d) => !shouldClear(d)
);
updatePlan.updatedTask.skipped_instances = skippedInstances.filter(
(d) => !shouldClear(d)
);
}
rescheduleClearedOccurrence = true;
updatePlan.updatedTask.complete_instances = completeInstances.filter(
(d) => d < scheduledDateStr
);
updatePlan.updatedTask.skipped_instances = skippedInstances.filter(
(d) => d < scheduledDateStr
);
}
}

Expand Down
279 changes: 279 additions & 0 deletions tests/unit/issues/issue-2691-reschedule-clear-rule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
/**
* Issue #2691: Moving the next occurrence of a scheduled-anchored recurring task
* must not clear other occurrences' completed/skipped history.
*
* - Scheduled-anchored tasks with a rule identity (`recurrence_original_date`)
* clear nothing on move.
* - Scheduled-anchored tasks without a rule identity (Google Calendar-synced or
* legacy off-pattern notes without a marker) clear only the landing day when
* that day is already recorded, still behind confirmation.
* - Completion-anchored recurring tasks keep the existing ">= new date" rule.
*/

jest.mock("rrule", () => jest.requireActual("rrule/dist/es5/rrule.js"));

import type TaskNotesPlugin from "../../../src/main";
import { TaskService } from "../../../src/services/TaskService";
import type { TaskInfo } from "../../../src/types";
import { PluginFactory, TaskFactory } from "../../helpers/mock-factories";

function weeklyTask(overrides: Partial<TaskInfo> = {}): TaskInfo {
return TaskFactory.createTask({
id: "weekly",
path: "Tasks/Weekly review.md",
title: "Weekly review",
scheduled: "2026-11-22",
recurrence: "DTSTART:20261101;FREQ=WEEKLY",
complete_instances: ["2026-11-08", "2026-11-15"],
skipped_instances: ["2026-11-29"],
...overrides,
});
}

function createHarness(task: TaskInfo, confirmed = true) {
const frontmatter: Record<string, unknown> = {
scheduled: task.scheduled,
recurrence: task.recurrence,
complete_instances: [...(task.complete_instances ?? [])],
skipped_instances: [...(task.skipped_instances ?? [])],
...(task.recurrence_original_date
? { recurrence_original_date: task.recurrence_original_date }
: {}),
};
const confirm = jest.fn(async () => confirmed);
const plugin = PluginFactory.createMockPlugin({
cacheManager: {
getTaskInfo: jest.fn(async () => task),
updateTaskInfoInCache: jest.fn(),
},
taskCalendarSyncService: { isEnabled: () => false },
});
plugin.app.fileManager.processFrontMatter = jest.fn(
async (_file: unknown, update: (fm: Record<string, unknown>) => void) => {
update(frontmatter);
}
);
const taskService = new TaskService(plugin as unknown as TaskNotesPlugin);
return { task, frontmatter, confirm, plugin, taskService };
}

describe("issue #2691 narrower reschedule-clear rule", () => {
describe("scheduled-anchored native recurring tasks", () => {
it("moving 22 Nov to 21 Nov preserves the skip on 29 Nov and does not ask to confirm", async () => {
const { task, frontmatter, confirm, taskService } = createHarness(weeklyTask());

const result = await taskService.updateProperty(task, "scheduled", "2026-11-21", {
confirmClearInstances: confirm,
});

expect(confirm).not.toHaveBeenCalled();
expect(result.scheduled).toBe("2026-11-21");
expect(result.recurrence_original_date).toBe("2026-11-22");
expect(result.complete_instances).toEqual(["2026-11-08", "2026-11-15"]);
expect(result.skipped_instances).toEqual(["2026-11-29"]);
expect(frontmatter).toMatchObject({
scheduled: "2026-11-21",
recurrence_original_date: "2026-11-22",
complete_instances: ["2026-11-08", "2026-11-15"],
skipped_instances: ["2026-11-29"],
});
});

it("moving 22 Nov onto completed 15 Nov preserves 15 Nov completion and 29 Nov skip", async () => {
const { task, frontmatter, confirm, taskService } = createHarness(weeklyTask());

const result = await taskService.updateProperty(task, "scheduled", "2026-11-15", {
confirmClearInstances: confirm,
});

expect(confirm).not.toHaveBeenCalled();
expect(result.scheduled).toBe("2026-11-15");
expect(result.recurrence_original_date).toBe("2026-11-22");
expect(result.complete_instances).toEqual(["2026-11-08", "2026-11-15"]);
expect(result.skipped_instances).toEqual(["2026-11-29"]);
expect(frontmatter.complete_instances).toEqual(["2026-11-08", "2026-11-15"]);
expect(frontmatter.skipped_instances).toEqual(["2026-11-29"]);
});

it("moving 22 Nov onto skipped 29 Nov preserves 29 Nov skip", async () => {
const { task, confirm, taskService } = createHarness(weeklyTask());

const result = await taskService.updateProperty(task, "scheduled", "2026-11-29", {
confirmClearInstances: confirm,
});

expect(confirm).not.toHaveBeenCalled();
expect(result.recurrence_original_date).toBe("2026-11-22");
expect(result.skipped_instances).toEqual(["2026-11-29"]);
});

it("moving an already-moved occurrence preserves history, including when returning to its original date", async () => {
const moved = weeklyTask({
scheduled: "2026-11-21",
recurrence_original_date: "2026-11-22",
});
const ontoCompleted = createHarness(moved);
const result = await ontoCompleted.taskService.updateProperty(
moved,
"scheduled",
"2026-11-15",
{ confirmClearInstances: ontoCompleted.confirm }
);
expect(ontoCompleted.confirm).not.toHaveBeenCalled();
expect(result.recurrence_original_date).toBe("2026-11-22");
expect(result.complete_instances).toEqual(["2026-11-08", "2026-11-15"]);
expect(result.skipped_instances).toEqual(["2026-11-29"]);

// Exhausted moved occurrence returned home keeps its recorded completion.
const exhaustedMoved = weeklyTask({
scheduled: "2026-11-21",
recurrence: "DTSTART:20261115;FREQ=WEEKLY;COUNT=2",
recurrence_original_date: "2026-11-22",
complete_instances: ["2026-11-15", "2026-11-22"],
skipped_instances: [],
});
const returned = createHarness(exhaustedMoved);
const homeResult = await returned.taskService.updateProperty(
exhaustedMoved,
"scheduled",
"2026-11-22",
{ confirmClearInstances: returned.confirm }
);
expect(returned.confirm).not.toHaveBeenCalled();
expect(homeResult.recurrence_original_date).toBeUndefined();
expect(homeResult.complete_instances).toEqual(["2026-11-15", "2026-11-22"]);
});
});

describe("scheduled-anchored tasks without recurrence_original_date", () => {
it("Google-synced move onto an unrecorded day clears nothing and keeps later skips", async () => {
const synced = weeklyTask({ googleCalendarEventId: "gcal-1" });
const { confirm, taskService } = createHarness(synced);

const result = await taskService.updateProperty(synced, "scheduled", "2026-11-21", {
confirmClearInstances: confirm,
});

expect(confirm).not.toHaveBeenCalled();
expect(result.recurrence_original_date).toBeUndefined();
expect(result.complete_instances).toEqual(["2026-11-08", "2026-11-15"]);
expect(result.skipped_instances).toEqual(["2026-11-29"]);
});

it("Google-synced move onto a completed day asks to clear only that day and keeps later skips", async () => {
const synced = weeklyTask({ googleCalendarEventId: "gcal-1" });
const { frontmatter, confirm, taskService } = createHarness(synced, true);

const result = await taskService.updateProperty(
synced,
"scheduled",
"2026-11-15T10:30",
{ confirmClearInstances: confirm }
);

expect(confirm).toHaveBeenCalledWith({ complete: ["2026-11-15"], skipped: [] });
expect(result.complete_instances).toEqual(["2026-11-08"]);
expect(result.skipped_instances).toEqual(["2026-11-29"]);
expect(frontmatter.complete_instances).toEqual(["2026-11-08"]);
expect(frontmatter.skipped_instances).toEqual(["2026-11-29"]);
});

it("Google-synced move onto a recorded day aborts with no write when confirmation is declined", async () => {
const synced = weeklyTask({ googleCalendarEventId: "gcal-1" });
const { confirm, plugin, taskService } = createHarness(synced, false);

const result = await taskService.updateProperty(synced, "scheduled", "2026-11-29", {
confirmClearInstances: confirm,
});

expect(confirm).toHaveBeenCalledWith({ complete: [], skipped: ["2026-11-29"] });
expect(plugin.app.fileManager.processFrontMatter).not.toHaveBeenCalled();
expect(result.scheduled).toBe("2026-11-22");
expect(result.skipped_instances).toEqual(["2026-11-29"]);
});

it("legacy off-pattern note without marker clears only a recorded landing day", async () => {
const legacy = weeklyTask({ scheduled: "2026-11-19" });

const toUnrecorded = createHarness(legacy);
const unrecordedResult = await toUnrecorded.taskService.updateProperty(
legacy,
"scheduled",
"2026-11-21",
{ confirmClearInstances: toUnrecorded.confirm }
);
expect(toUnrecorded.confirm).not.toHaveBeenCalled();
expect(unrecordedResult.complete_instances).toEqual(["2026-11-08", "2026-11-15"]);
expect(unrecordedResult.skipped_instances).toEqual(["2026-11-29"]);

const toCompleted = createHarness(legacy, true);
const completedResult = await toCompleted.taskService.updateProperty(
legacy,
"scheduled",
"2026-11-15",
{ confirmClearInstances: toCompleted.confirm }
);
expect(toCompleted.confirm).toHaveBeenCalledWith({
complete: ["2026-11-15"],
skipped: [],
});
expect(completedResult.complete_instances).toEqual(["2026-11-08"]);
expect(completedResult.skipped_instances).toEqual(["2026-11-29"]);

const declined = createHarness(legacy, false);
const declinedResult = await declined.taskService.updateProperty(
legacy,
"scheduled",
"2026-11-15",
{ confirmClearInstances: declined.confirm }
);
expect(declined.confirm).toHaveBeenCalledWith({
complete: ["2026-11-15"],
skipped: [],
});
expect(declined.plugin.app.fileManager.processFrontMatter).not.toHaveBeenCalled();
expect(declinedResult.scheduled).toBe("2026-11-19");
});
});

describe("completion-anchored recurring tasks (unchanged)", () => {
it("still clears all recorded instances on or after the new scheduled date", async () => {
const completionAnchored = weeklyTask({ recurrence_anchor: "completion" });

const toSat = createHarness(completionAnchored, true);
const satResult = await toSat.taskService.updateProperty(
completionAnchored,
"scheduled",
"2026-11-21",
{ confirmClearInstances: toSat.confirm }
);
expect(toSat.confirm).toHaveBeenCalledWith({ complete: [], skipped: ["2026-11-29"] });
expect(satResult.complete_instances).toEqual(["2026-11-08", "2026-11-15"]);
expect(satResult.skipped_instances).toEqual([]);

const toEarlier = createHarness(completionAnchored, true);
const earlierResult = await toEarlier.taskService.updateProperty(
completionAnchored,
"scheduled",
"2026-11-15",
{ confirmClearInstances: toEarlier.confirm }
);
expect(toEarlier.confirm).toHaveBeenCalledWith({
complete: ["2026-11-15"],
skipped: ["2026-11-29"],
});
expect(earlierResult.complete_instances).toEqual(["2026-11-08"]);
expect(earlierResult.skipped_instances).toEqual([]);

const declined = createHarness(completionAnchored, false);
const declinedResult = await declined.taskService.updateProperty(
completionAnchored,
"scheduled",
"2026-11-15",
{ confirmClearInstances: declined.confirm }
);
expect(declined.plugin.app.fileManager.processFrontMatter).not.toHaveBeenCalled();
expect(declinedResult.scheduled).toBe("2026-11-22");
});
});
});
Loading
Loading