Repository navigation
Description
Summary
The map_iterable helper exported by octane/tsrx-iterable delegates to @tsrx/runtime/iterable. In runtime 0.1.5, its Set/Map fast path caches the collection's initial size and reads iterator.next().value without checking done. Clearing or deleting unvisited entries during a callback can therefore pass undefined as an item; Map destructuring can throw. Newly added entries can also be omitted.
This is a TSRX runtime dependency regression, reported here because Octane exposes the helper. Octane 0.2.5 still uses the affected source.
Minimal reproduction
Node 26.2.0, ESM; no bundler required:
import { map_iterable } from 'octane/tsrx-iterable';
const rows = new Set([1, 2]);
console.log(
map_iterable(rows, (value) => {
rows.clear();
return value;
}),
);
// Actual with @tsrx/runtime 0.1.5: [1, undefined]
const pairs = new Map([[1, 'a'], [2, 'b']]);
console.log(
map_iterable(pairs, ([key]) => {
pairs.clear();
return key;
}),
);
// Actual: TypeError when the second callback destructures undefinedThe same calls against runtime 0.1.2 return [1, 2]: its existing iterator-driven implementation reads one item ahead before invoking each callback. That is the compatibility baseline, not a claim that clearing a collection should generally visit every original item.
A second control starts with Set([1, 2]) and adds 3 from the first callback: 0.1.2 visits [1, 2, 3], while 0.1.5 visits only [1, 2]. Map shows the same omission.
Cause and proposed fix
map_sized in the pinned TSRX runtime source assumes size stays constant across callbacks. Simply checking done avoids the undefined item but does not restore addition or is_last semantics.
A narrow compatibility fix is to send Set/Map through the existing peek-ahead iterator path while retaining the array optimization. Regression coverage should compare deletion, clear, and addition for both collections, including callback values, indices, is_last, and tail/empty handling.
Scope and verification
- Reproduced through the public Octane export with the affected 0.1.5 runtime source; independently compared with 0.1.2.
- The affected helper source is unchanged in current TSRX main.
- Octane's native DOM
forBlockuses a separate path that snapshots non-array inputs withArray.from. This report does not establish a native DOM-loop regression. - A downstream compatibility patch is being prepared; no fix is claimed to be released upstream.
Provenance
- An agent authored this report (
agent-authored).
Activity
fix(runtime): walk Set and Map with the peek-ahead iterator in map_it…
leonidaz commentedon Sep 7, 2026
fixed by tsrx-org/tsrx#86