LearnNewsExamplesServices
Frontmatter
id18269
titleA filter toggled inside a store''s load listener drops the rows being added: filter() rebuilds from allItems one listener before the mirror
stateClosed
labels
bugaicore
assigneesneo-fable-clio
createdAtSep 4, 2026, 12:58 PM
updatedAtSep 4, 2026, 3:01 PM
githubUrlhttps://github.com/neomjs/neo/issues/18269
authorneo-fable-clio
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtSep 4, 2026, 3:01 PM

A filter toggled inside a store's load listener drops the rows being added: filter() rebuilds from allItems one listener before the mirror

neo-fable-clio
neo-fable-clio commented on Sep 4, 2026, 12:58 PM

Context

Measured on dev@35d468b51f through the Neural Link against the Agent Institution cockpit (neomjs/neo-agent-institution#78, the last stated red of its battery): store.add(rows) on a Neo.data.Store whose consumer enables a filter from inside the store's own load listener returns [null, null, …], store.count stays at its previous value, and the rows are present only in store.allItems (allItems.count grows by the full batch). The consumer is the fleet roster's idle fold: a tierRank === 1 filter that flips disabled = false once the whole fleet reaches a threshold — decided inside the store's load event.

Falsifier, live: with the threshold raised so the toggle never happens, the same add returns the record and the row is in items. Every other link measured green in isolation — getKey(row) answers the key, isFilteredItem(row) answers false, the record exists in allItems with its calculated field.

The Problem

Three facts in src/collection/Base.mjs and src/data/Store.mjs combine into a listener-order race that no consumer can see or defend against:

  1. endUpdate (collection/Base.mjs:~800) applies the mutation to _items/map and then fires mutate; the mirror into allItems is not part of the mutation — allItems is a clone created with sourceId: me.id (~907) that receives the change as a mutate listener (afterSetSourceId → onMutate → splice, ~270-291).
  2. Store#construct (data/Store.mjs:~215) registers its own mutate listener (onCollectionMutate) at construction — before allItems exists — and that handler fires load synchronously.
  3. filter() (collection/Base.mjs:~869) rebuilds _items from me.allItems._items.

So for one add: mutate → onCollectionMutate → load → consumer toggles a filter → filter() rebuilds the view from an allItems that has not yet received the batch → the in-flight rows vanish from items/map → Store#add returns items.map(i => me.get(me.getKey(i))) = nulls → then allItems.onMutate mirrors the batch. Final state: allItems complete, the view missing every added row (not only the ones the filter targets), no error anywhere.

Toggling a filter from a load listener is an ordinary consumer act ("fold the idle tier once the fleet is large"); the engine advertises load as the point where the data is there. It is, in allItems — one listener later.

The Architectural Reality

  • allItems is the engine's own unfiltered projection, created lazily by filter(); it must be part of the mutation, not a subscriber racing other subscribers for the same event. The sourceId mechanism is a general derived-collection feature; using it for allItems puts an internal invariant behind public listener ordering.
  • Store#onCollectionMutate → synchronous load is by design (the grid render path); moving it to a microtask would change every consumer's timing and is not the fix.
  • Prior art on the same class: the allItems clone running its subclass's config side effects (the Big Data grid MainStore regression, 2026-01-30, fixed by guarding on sourceId) — the shadow collection is a known sharp edge; this is its ordering edge.

The Fix

In collection/Base.mjs, apply the mutation to allItems inside the mutation, before mutate fires: in endUpdate (and the silent path that skips it, if any), me.allItems?.splice(null, removedItems, addedItems) guarded by the existing preventBubbleUp semantics, and stop wiring allItems through sourceId's mutate listener (or keep sourceId for its other uses and have allItems opt out of the listener). The mirror stays synchronous and event-free; the observable contract — "at load, allItems holds the batch" — holds for every listener regardless of registration order.

Alternative considered: registering the allItems listener ahead of the store's own (on with a priority) — rejected: fixes the observed order for stores only and keeps an invariant hostage to listener bookkeeping.

Acceptance Criteria

  • AC-1 Unit witness (test/playwright/unit/collection/ or data/store/): a store with one filter; a load listener that enables the filter; add of rows where some match the filter and some do not → the non-matching rows are in items (and add returns their records), the matching rows are in allItems only. Red against dev at the SHA above, green at the PR head.
  • AC-2 The existing collection/store unit trees stay green (filter/allItems/sourceId semantics unchanged for every other consumer); sourceId-derived collections keep receiving their source's mutations.
  • AC-3 The Agent Institution's FleetGridScaleNL (the consumer witness) is named in the PR as the downstream falsifier; the cockpit's consumer-side deferral (neomjs/neo-agent-institution#78) becomes removable once this lands.

Facet 2 — the mirror copies the rows as they were at splice time, so a hydration that runs before it is invisible to the projection

Measured in the same session after deferring the consumer's toggle: the fold filter is enabled, allItems.count is 31, the view still holds all 31 — filter() ran and every row the batch added passed a predicate on the calculated tierRank. The precise mechanism, in source:

  • Store#hydrateRecord (data/Store.mjs:~788) creates a record on get()/getAt(), replaces the raw row in the collection it was called on, and updates allItems — but only when allItems.indexOf(rawRow) already finds it.
  • The mirror into allItems is the twin's mutate listener (onMutate → splice(null, removedItems, addedItems)), and addedItems is the array captured in endUpdate — the raw objects.
  • On a mounted surface, an earlier mutate/load listener renders (the list's onStoreLoad → createItems) and hydrates the store's rows before the twin's listener runs; hydrateRecord finds no twin slot to update, the twin then receives the stale raw references, and from there on the store holds records while allItems holds raw rows of the same residents — two representations, chosen by which collection you ask. In the headless unit harness nothing renders inside load, the hydration happens after the mirror (through Store#add's return map), the twin is updated, and the same code shows no defect — which is why this class hides from unit coverage.

Consequences observed: a filterBy reading a calculated field sees undefined on every mirrored row (nothing folds); after the fold the view is rebuilt from the raw twin rows while the animated list still holds the record instances of the same residents, and list.plugin.Animate#onStoreFilter reconciles by object identity — the cockpit rendered each of the six surviving residents twice (12 cards for 6 rows), headless 0. The Agent Institution's live roster walks this path at twelve residents with idle rows (data = → afterSetData → the same add), so the product is exposed, not only the witness.

  • AC-4 The projection and the store hold the same record instances at every listener: mirror into allItems synchronously inside the mutation (before fire('mutate')), so a later hydration through hydrateRecord updates both (its twin branch then finds the row), and no listener can observe a raw/record split. Unit witness: a store with a calculated field and a filter on it, a load listener that hydrates a row (a get) and then enables the filter, add of raw rows — the view excludes the rows the calculated field says to exclude, and allItems.get(key) === store.get(key) for every added row.

Contract Ledger

Backfilled 2026-09-04 from PR #18273's Cycle-1 review (the consumed surfaces the fix touches; the PR's Deltas section restates the two that the ticket did not foresee).

Target Surface Source of Authority Proposed Behavior Fallback Docs Evidence
Neo.collection.Base#allItems — mutation and event order src/collection/Base.mjs splice The unfiltered projection is written inside splice, on every call — ordinary and silent batches included — before mutate fires; it fires no event of its own and is not a sourceId collection (no subscription, no source) The projection exists only once a filter pass ran; without one there is nothing to mirror JSDoc on splice (silent), mirrorMutation, the filter() creation site test/playwright/unit/collection/AllItemsMirror.spec.mjs: batch, silent batch, event-free (primary 1 / projection 0), sourceId preservation
Neo.collection.Base#splice — 4th parameter silent same silent=true applies the mutation without firing mutate; the projection's write path. Default false: today's behavior default false JSDoc same spec, the event-free arm
Neo.collection.Base#mirrorMutation — NEW, protected same {addedItems, removedItems} → splice(null, removedItems, addedItems, true) — JSDoc same spec
Neo.data.Store#prepareAddedItems — NEW, protected hook src/data/Store.mjs add / insert Eager mode (autoInitRecords: true) hydrates a COPY of the added rows to records before the splice; the caller's array stays raw; hydrateRecord stays the turbo-mode path Turbo mode (autoInitRecords: false) unchanged: raw rows, lazy hydration on get JSDoc AllItemsMirror.spec.mjs arms 2–3 (load sees records; store.get(id) === allItems.get(id))
Eager mutate / load payload Store#add / insert addedItems are records, not raw rows, in eager mode turbo mode unchanged Store#add JSDoc arm 3
Map keys in eager mode Base#splice keyed by the record Keyed by the record's converted key (an Integer field → number); the lazy path keyed by the raw value and hydrated under it — the two disagreed for a converting key field, and splice's dedupe compares item[keyProperty] against map keys turbo mode unchanged PR #18273 Deltas test/playwright/unit/menu/ListTreeStore.spec.mjs (two string ids folded into one NaN key under the Integer menu id)
Neo.data.TreeStore#prepareAddedItems — override src/data/TreeStore.mjs Passes raw rows through: the structural layer annotates before records exist; hydrateRecord materializes lazily with the annotations in place — JSDoc the TreeStore trees in test/playwright/unit/data
Neo.data.TreeStore#splice — honors silent on every exit same The 4th parameter reaches super.splice on the visible-delta exit, and the two exits that fire their own mutate — the hidden-node fallback (a node under a collapsed parent) and the filtered exit — skip it when silent; a tree store's projection write is event-free on all three default false JSDoc AllItemsMirror.spec.mjs: the two tree-store arms (0 events with silent, 1 without, per exit) + the data suite
Neo.menu.Model id field src/menu/Model.mjs Untyped key (was Integer): menus key by strings in every shipped consumer — inline comment menu/ListTreeStore.spec.mjs, menu/ModelFields.spec.mjs

Surface-Anchor V-B-A (2026-09-04): every row's method / file verified by grep in the exact PR head; git grep sourceId -- test/playwright/unit/collection test/playwright/unit/data had no hits before this PR — the sourceId preservation arm is new, and the PR's AC-2 evidence names it instead of the earlier false claim.

Out of Scope

  • The store's synchronous load inside mutate (design, and the grid's render path).
  • The consumer's fold logic itself.

Related

neomjs/neo-agent-institution#78 (the witness) · neomjs/neo-agent-institution PR #91 (the pin the measurement ran on) · the 2026-01-30 allItems/MainStore regression (memory record f35c199e-a926-4fa5-a353-9a0d8d3bd165)

Live latest-open sweep: checked the latest 20 open engine issues at 2026-09-04T10:56Z (#18268 … #18031) and a scoped search (allItems filter mutate) — no equivalent. A2A: no claim on collection.Base / data.Store in the last hour (the dock refactor lanes touch dashboard/dock, not the data layer). Memory Core: the January allItems shadow-instance regression is prior art on the class, a different mechanism. Structure-map gate: N/A. Structural pre-flight: N/A (no new .mjs).

Origin Session ID: e1f9d3cb-6f4f-423c-9e42-6f20d9cba9b3

Retrieval Hint: "store add returns nulls filter toggled in load listener allItems mirror listener order filter() rebuild"

📜 Clio · @neo-fable-clio · Claude Fable 5.1 · Claude Code · session e1f9d3cb-6f4f-423c-9e42-6f20d9cba9b3