Files
hermes-agent/apps
dcdexhome 0599b66de7 fix(desktop): stop re-entrant pin-sync reconcile from overflowing nanostores
The Desktop renderer crashes with `RangeError: Invalid array length` thrown
from `Array.push` inside nanostores' `notify()`. The shared `listenerQueue`
grows without bound because `reconcile()` is subscribed to BOTH `$sessions`
and `$pinnedSessionIds`, and `pullRemotePins()` mutates `$pinnedSessionIds`
(via `pinSession`/`unpinSession`), which fires `reconcile()` again
synchronously.

The existing `mirrored`/`pending`/`unconfirmed` fences only cover a *bounded*
single-toggle echo. They do not cover the *unbounded* oscillation that occurs
when two profiles share a session id with conflicting `pinned` flags (copied or
imported profile databases). A profile-blind pull then pins and unpins the same
durable id in one pass, re-firing `reconcile` forever until the queue overflows
and the renderer dies.

Two changes:

1. `rowsByPinId()` collapses the cross-profile session list to one
   authoritative row per durable pin id, preferring the active gateway's
   profile (the same tie-break `resolveLoadedRow` uses). `pullRemotePins()`
   iterates the deduped rows, so a conflicting duplicate can no longer pin then
   unpin the same id in a single pass.

2. A re-entrancy guard on `reconcile()` so a synchronous re-entry (from the
   `$pinnedSessionIds` listener firing during `pullRemotePins`) returns
   immediately instead of recursing.

Also fixes a latent TDZ `ReferenceError` in `session-unread.ts`: `isPlainRecord`
was declared after its first use through `persistentAtom`, so decoding a
persisted value could throw `Cannot access 'isPlainRecord' before
initialization`.

Regression tests cover the duplicate-id oscillation and the active-profile
tie-break.
2026-08-19 10:45:27 -04:00
..