Skip to content

Keep step outputs and trigger events to plain data (#22) - #23

Merged
callumalpass merged 1 commit into
mainfrom
fix/22-circular-step-output
Nov 10, 2026
Merged

callumalpass merged 1 commit into
mainfrom
fix/22-circular-step-output

Conversation

@callumalpass

Copy link
Copy Markdown
Owner

Fixes #22. Related: callumalpass/tasknotes#2119, callumalpass/obsidian-bases-expression#7.

Cause

Credit to @konstantinopolka for the diagnosis. Once TaskNotes renders a task in a Bases view, it attaches basesData (a Bases entry that reaches the Obsidian App) to the cached TaskInfo. TaskNotes 4.17 returns that object from tasks.get, from mutations such as tasks.patch, and in task event payloads. The graph is circular, so:

  • any $expr that reads steps or event overflows the stack in obsidian-bases-expression's fromJs ("Maximum call stack size exceeded");
  • RunLogService.writeDetail then fails with "Converting circular structure to JSON", which hides the real error.

Fix

  • New src/workflowData.ts with toWorkflowData, which copies a value to plain data. It keeps plain objects, arrays, primitives and Dates. It drops class instances, functions and back-references to an object still being copied, the same way JSON does. Repeated references that are not cycles are kept.
  • WorkflowEngine applies it to the trigger payload, which feeds event and the run detail trigger, and to every step output (local steps and interop outputs) before the output enters steps.*.
  • RunLogService serialises the history line and the detail file through the same function. A stray runtime object can no longer stop the run log from being written.

This doesn't depend on the TaskNotes or library changes. It fixes the issue on TaskNotes 4.17 with obsidian-bases-expression 0.2.0 as they are today.

Tests

  • tests/issue-22-circular-step-output.test.ts uses a TaskInfo-like object carrying a circular basesData. Before the fix, the step-output and event expressions fail with "Maximum call stack size exceeded" and the run log fails with "Converting circular structure to JSON". All 5 tests fail before the fix and pass after.
  • tests/workflowData.test.ts adds unit tests for the converter.
  • npm test (71 passed), npm run typecheck, npm run lint and npm run build all pass. I didn't verify this in Obsidian because no instance was running.

TaskNotes attaches `basesData` (a Bases entry that reaches the Obsidian
App) to the cached TaskInfo once a task is rendered in a Bases view, and
`tasks.get`/`tasks.patch` and task events hand that object over. The
graph is circular, so any `$expr` that reads `steps` or `event` overflowed
the stack in obsidian-bases-expression's `fromJs`, and the run log then
failed with "Converting circular structure to JSON", hiding the real
error.

Add toWorkflowData, which copies values to plain data (plain objects,
arrays, primitives and Dates; class instances, functions and cyclic
back-references are dropped as JSON would), and apply it to the trigger
payload and to every step output before they enter the run context. The
run log serialises through the same function, so a stray runtime object
can no longer stop the detail log from being written.

Root cause diagnosed by konstantinopolka.
Reported by rougeayrn (#22) and chrabia (TaskNotes #2119).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kanban Moves Cause Workflow Failures

1 participant