Repository navigation
0.18 PR3: stop before pulling, validate take/total - #30
Merged
Merged
Conversation
- Guard take/signal before the loop and re-check after `index++` in the series and seriesSync engines, so `take: 0` and an already-aborted signal pull zero items and an abort during pause or step does not pull the next one. `break` keeps iterator.return() and generator finally semantics intact. - Validate `take` as a non-negative integer and `total` as a finite non-negative number in planSeries and findSync, before the planned total is computed. - Count actual pulls (not just results) in take-limits and signal tests, including pre-abort, abort during pause, abort during step, folds with a pre-aborted signal and generator cleanup.
ildella
marked this pull request as ready for review
November 24, 2026 14:35
ildella
commented
Nov 24, 2026
ildella
left a comment
Owner
Author
There was a problem hiding this comment.
APPROVED
REVIEW: Both review passes found no medium-or-higher issues. The pre-loop guards stop take: 0 and a pre-aborted signal before the source is pulled — no next() call, no source errors — and the post-index++ guard prevents the next pull after an abort or a reached take limit while preserving skip and progress index semantics. assertTake/assertTotal validate at the single shared point (planSeries) plus directly in findSync; scan/reduce correctly stay unvalidated per plan. docs/reference.md covers the new take/total contract.
FINDINGS: No medium-or-higher findings. Low/info follow-ups:
- LOW — invalid
take/totalon asyncfilterandmapSeriesthrowsseries() take must be a non-negative integer, becauseplanSeriesdefaults the label to'series'. Trigger:filter(items, fn, {take: -1}); behavior is correct but the message names the wrong wrapper. Plan-conformant, sync twins label correctly. - LOW — the
countingSourcefixture is duplicated intests/signal.test.jsand the newtests/take-limits.test.js. Trigger: changing pull-count semantics requires two edits; test scaffolding only. - INFO — the async pre-loop check and the first in-loop check both evaluate index 0. Trigger: harmless for
take, meaningful forsignalthat aborts between them. - INFO — curried
mapSeries(fn, {take: -1})defers validation to a rejected promise at call time, while its strategy options validate at construction. Trigger: constructing an invalid run; pre-existing split and untested here. - INFO —
take: 0never starts the generator, so itsfinallydoes not execute (cleanedUpstays false). Trigger: writing a cleanup assertion for that case; correct behavior since nothing was acquired. - INFO —
tests/signal.test.jsadds a blanketeslint-disable max-lineswhile mixing cancellation and source-pull suites in one file.
CI: green — the test check (Code Check workflow) succeeded.
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.
What
PR 3 of the 0.18 stabilization plan (
fix/pre-pull-stop).3a. Pre-loop guard + re-check after
index++runAsyncStrategy(src/functional.js) andrunSyncStrategy(
src/functional-sync.js) now check the stop condition before entering theloop and again right after
index++:take: 0pulls zero items from the source.signalpulls zero items and never starts a dyingsource (no
sourceErrors).pauseor during the step no longer pulls the next item.outcome?.skipbranch is gone:index++is common to skip and success.for await/for...ofstay, sobreakstill callsiterator.return()and generator
finallyblocks still run.3b.
take/totalvalidationassertTake/assertTotalinsrc/run.js, called fromplanSeriesandfindSyncbeforegetPlannedTotal:takemust be a non-negative integer.totalmust be a finite non-negative number (total: 0is valid).planFoldis untouched: rejectingtake/totalonscan/reducebelongs toPR 7.
Tests
tests/take-limits.test.jscounts actual pulls from a generator (notjust results) for
series,seriesSync,filter,filterSync,mapSeries,mapSeriesSync,findSync:take: 0→pulled === 0,take: 1→pulled === 1plus cleanup, broken source never started,invalid
take/total→TypeError,total: 0valid.tests/signal.test.jsextended with pull counts for pre-abort, abort duringpause, abort during step, dying source on pre-abort, and
scan/reducewitha pre-aborted signal.
finallymust run(
cleanedUp === true).All new tests fail on the old loop code (verified by stashing the src changes)
and pass with the fix.
Gates
yarn lint— cleanyarn vitest run— 972 passed (933 existing + 39 new), 0 failedyarn check— clean (dup + knip)No existing test had to change: none asserted the buggy pre-pull behaviour.
Plan reference:
.opencode/plan/pipelean-0.18.md§PR 3 (lines 257–368), risk #2(
for awaitcleanup).