Repository navigation
fix(runtime): tolerate Set/Map mutation during map_iterable - #86
Merged
Merged
Conversation
…erable The sized fast path added in #67 cached `size` and read `iterator.next().value` without checking `done`, so a callback that cleared, deleted from, or added to the Set or Map being iterated received `undefined` items, missed added entries, and saw `is_last` on the wrong item. Route Set and Map back through the peek-ahead iterator path and keep the array preallocation. Reported downstream as octanejs/octane#977. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Merged
This was referenced Sep 7, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the
@tsrx/runtime0.1.5 regression reported downstream in octanejs/octane#977.PR #67 added a
map_sizedfast path forSet/Mapthat cachedsizeand readiterator.next().valuewithout checkingdone. When a@forcallback mutates the collection it is iterating, that path:undefinedas the item once the collection shrinks (Mapdestructuring then throws)is_laston the wrong itemThis restores the 0.1.2 behaviour by sending
SetandMapthrough the existing peek-ahead iterator loop. The array preallocation path from #67 is unchanged.Tests
New cases in
iterable-runtime.test.jscover clear, delete-before-visit, and add-during-iteration for bothSetandMap, asserting values, indices,is_last, plus tail handling after mutation.Performance
Isolated microbenchmark, Node 24,
String(item)body, 100 entries:A hybrid that keeps peek-ahead but preallocates the result from
sizemeasured ~505k ops/s on Set and no change on Map. It was left out to keep this a minimal correctness fix; it can be a follow-up if the Set number matters.Validation
pnpm exec vitest run --project tsrx-utils(23 files, 605 tests)pnpm typecheckpnpm exec prettier --checkon touched files,pnpm changeset:check🤖 Generated with Claude Code
Note
Low Risk
Targeted runtime bugfix with broad new tests; behavior matches pre-#67 semantics aside from intentional Set/Map perf regression.
Overview
Reverts the Set/Map
size-based fast path inmap_iterable(is_sized_iterable/map_sized) so those collections use the same peek-ahead iterator loop as other iterables. That fixes a 0.1.5 regression where mutating the collection inside the callback could yieldundefineditems, skip newly added entries, and setis_lasttoo early.Arrays still use the preallocated
map_arraypath from #67; only default Set/Map iteration behavior changes (with a perf tradeoff on large sets).Tests in
iterable-runtime.test.jsnow cover clear, add during iteration, delete before visit, and tail handling for mutated sets/maps.Reviewed by Cursor Bugbot for commit 6af980c. Bugbot is set up for automated code reviews on this repo. Configure here.