From 7312c4e2837b67ead0fa303e8e9a88a1cf2f5572 Mon Sep 17 00:00:00 2001 From: callumalpass Date: Wed, 11 Nov 2026 03:47:53 +1100 Subject: [PATCH] Keep basesData out of TaskInfo returned by the runtime API (#2119) Bases views attach their entry to the cached TaskInfo as `basesData`, and the entry holds the Obsidian app, so the object graph is circular. The runtime API copied tasks with copyTaskInfo, which kept the field, so `tasks.get`, task lists, relationships, mutation results and task event payloads all handed it to companion plugins. TaskNotes Workflows then overflowed the stack in expressions and failed to write its run log. Drop `basesData` in copyTaskInfo, which every API task result and event payload already passes through, and use the copied task in the pomodoro event `data` field instead of the raw payload. MCP output and buildTaskChanges already skipped the field. Root cause found by konstantinopolka. Reported by chrabia. --- docs/releases/unreleased.md | 3 ++ src/api/TaskNotesAPI.ts | 6 ++-- tests/unit/api/tasknotes-api-v1.test.ts | 46 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/docs/releases/unreleased.md b/docs/releases/unreleased.md index 06cadcb0d..d816bd3a9 100644 --- a/docs/releases/unreleased.md +++ b/docs/releases/unreleased.md @@ -34,6 +34,9 @@ When a change has user-facing documentation, include a canonical tasknotes.dev l ## Fixed +- (#2119) Fixed companion plugins such as TaskNotes Workflows failing with "Converting circular structure to JSON" or "Maximum call stack size exceeded" after a task was moved on a Kanban board or edited in another Bases view. Tasks and task events from the TaskNotes API no longer include the internal Bases view data that views attach to a task. + - Thanks to @chrabia for reporting this, and to @konstantinopolka for finding the cause + - (#2527) Fixed timeblock titles being invisible in light themes in the calendar's "+N more" popover for overlapping events, in month view and in list view. These places draw the timeblock without its colour fill, but the text stayed white. It now uses the theme's text colour there. Property-based calendar events had the same problem and are fixed too. - Thanks to @RumiaKitinari for reporting this - (#2528) Fixed calendar time grids hiding the time range on some timed events and timeblocks. Events about an hour long or shorter lost their time in narrow columns, such as a week view, while longer ones kept it. Long titles could also push the time out of view. The time now stays visible whenever the event has room for two lines, and the title is shortened instead. diff --git a/src/api/TaskNotesAPI.ts b/src/api/TaskNotesAPI.ts index f33da1db6..f26144232 100644 --- a/src/api/TaskNotesAPI.ts +++ b/src/api/TaskNotesAPI.ts @@ -2961,7 +2961,7 @@ export class TaskNotesAPI implements TaskNotesRuntimeApiV1 { taskPath, task, changes: {}, - data: payload, + data: task ? { ...data, task } : payload, context, rawEvent, }), @@ -3467,7 +3467,9 @@ function getRawEventForRuntimeEvent(event: TaskNotesRuntimeEventName): string { } function copyTaskInfo(task: TaskInfo): TaskInfo { - const copy = { ...task }; + // `basesData` is the Bases entry a view attached to the cached task. It holds + // the Obsidian app, so it is circular and must not reach API consumers. + const { basesData: _basesData, ...copy }: TaskInfo = task; if (task.tags) { copy.tags = [...task.tags]; diff --git a/tests/unit/api/tasknotes-api-v1.test.ts b/tests/unit/api/tasknotes-api-v1.test.ts index 5f10a86bc..43e1750d7 100644 --- a/tests/unit/api/tasknotes-api-v1.test.ts +++ b/tests/unit/api/tasknotes-api-v1.test.ts @@ -928,6 +928,52 @@ describe("TaskNotesApiV1", () => { ); }); + it("keeps Bases view data out of tasks and events returned to companion plugins (#2119)", async () => { + // Bases views attach their entry to the cached TaskInfo. The entry + // reaches the Obsidian app, which is a circular object graph. + const app: { appMenuBarManager?: { app: unknown } } = {}; + app.appMenuBarManager = { app }; + const parent = createTask({ + title: "Parent", + path: "Projects/project.md", + basesData: { app }, + }); + const task = createTask({ + projects: ["[[Projects/project]]"], + tags: ["work"], + basesData: { app }, + }); + const { plugin, emitter } = createPluginContext([parent, task]); + const api = new TaskNotesAPI(plugin); + const events: TaskNotesApiEventPayload[] = []; + api.on("task.status.changed", (payload) => events.push(payload)); + const pomodoroEvents: TaskNotesApiEventPayload[] = []; + api.on("pomodoro.started", (payload) => pomodoroEvents.push(payload)); + + const returned: unknown[] = [ + await api.getTask(task.path), + await api.listTasks(), + await api.relationships.parents(task.path), + await api.updateTask(task.path, { status: "active" }), + ]; + + expect(returned[0]).toEqual({ ...task, basesData: undefined }); + expect(events).toHaveLength(1); + for (const value of [...returned, events[0]?.task, events[0]?.before, events[0]?.after]) { + expect(() => JSON.stringify(value)).not.toThrow(); + } + expect(events[0]?.after).not.toHaveProperty("basesData"); + expect(events[0]?.changes).toEqual({ status: { before: "open", after: "active" } }); + + emitter.trigger(EVENT_POMODORO_START, { task, session: { taskPath: task.path } }); + expect(pomodoroEvents).toHaveLength(1); + expect(() => JSON.stringify(pomodoroEvents[0])).not.toThrow(); + expect(pomodoroEvents[0]?.data).toEqual({ + task: { ...task, basesData: undefined }, + session: { taskPath: task.path }, + }); + }); + it("exposes query, stats, time summary, task time data, and health helpers", async () => { const task = createTask({ timeEntries: [