openpencil/apps
Fini 067340b6fc fix(ai): JSONL collectIds handles self-parented duplicate children (cycles)
parseJsonlToTree resolves `_parent` via a `Map<id, node>` that's
overwritten on duplicate ids. A JSONL line whose `_parent` equals its
own `id` (or otherwise references a node that ends up being itself
after the map overwrite) produces `node.children = [node]` — a cyclic
graph. Without a cycle guard, `collectIds` would recurse forever
walking node → node.children[0] → node → … and never surface the
duplicate or fail the dispatch.

Two-part guard:
  1. Reference-identity `WeakSet` (visitedRefs) — short-circuits the
     recursion the moment we re-enter the same node object.
  2. Early return after pushing a duplicate id — once we've recorded
     the dup, descending into its (potentially cyclic) subtree adds no
     information.

Either guard alone would prevent the stack overflow; together they
make the dup-detection robust against any malformed input shape that
parseJsonlToTree might produce.
2026-05-05 01:22:48 +08:00
..
cli Merge origin/v0.8.0 into feat/rust-ification 2026-05-03 21:00:00 +08:00
desktop Merge origin/v0.8.0 into feat/rust-ification 2026-05-03 21:00:00 +08:00
web fix(ai): JSONL collectIds handles self-parented duplicate children (cycles) 2026-05-05 01:22:48 +08:00