Skip to content

fix(sqlite): keep statement iterators exhausted - #9909

Closed
proggeramlug wants to merge 1 commit into
PerryTS:mainfrom
proggeramlug:fix/9202-sqlite-iterate-exhaustion
Closed

fix(sqlite): keep statement iterators exhausted#9909
proggeramlug wants to merge 1 commit into
PerryTS:mainfrom
proggeramlug:fix/9202-sqlite-iterate-exhaustion

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

After a for...of loop consumed a DatabaseSync statement iterator, calling .next() on that same iterator restarted it at the first row. Node keeps the iterator exhausted and returns { done: true, value: null }.

The SQLite-specific array iterator now clears its backing array when it reaches the end, matching its existing terminal behavior after .return(). Calling statement.iterate() again still creates a fresh iterator and executes a second pass normally. A runtime regression covers the optimized for...of drain followed by a manual .next().

Refs #9202.

Validation:

  • focused runtime regression: sqlite_iterator_stays_exhausted_after_fused_for_of_drain
  • exact sqlite/statements/iterate.ts output matches Node 26.5.1
  • complete SQLite node-suite: 47/47 passed
  • full perry-runtime: 3,243 passed, 4 ignored; doc tests 8 ignored
  • full perry-stdlib: 132 passed
  • ./scripts/run_lint_gates.sh: all 64 gates passed, 2 CI-only skipped

Summary by CodeRabbit

  • Bug Fixes

    • SQLite statement iterators now remain exhausted after completing a for...of loop.
    • Calling .next() afterward correctly returns { done: true, value: null } instead of replaying rows.
  • Documentation

    • Added a changelog entry describing the corrected iterator behavior.

@proggeramlug
proggeramlug force-pushed the fix/9202-sqlite-iterate-exhaustion branch from addc439 to 48cf508 Compare September 6, 2026 18:11
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 69b02dcf-5f49-4f23-b73d-f64bf39f2bfd

📥 Commits

Reviewing files that changed from the base of the PR and between 504e180 and 48cf508.

📒 Files selected for processing (2)
  • changelog.d/9909-sqlite-iterate-exhaustion.md
  • crates/perry-runtime/src/array/iter_object.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

SQLite statement iterators now stay exhausted after a for...of loop. Subsequent .next() calls return { done: true, value: null }. The runtime includes regression coverage and a changelog entry.

Changes

SQLite iterator exhaustion

Layer / File(s) Summary
Permanent iterator exhaustion
crates/perry-runtime/src/array/iter_object.rs, changelog.d/9909-sqlite-iterate-exhaustion.md
Completed SQLite statement iterators clear their backing array and remain closed. Regression tests verify repeated .next() calls after a fused drain. The changelog documents the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 48cf5

SQLite statement iterators now remain exhausted after a completed loop, returning the expected terminal result on later calls. The behavior is covered by regression testing and presents no remaining merge-readiness risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: keeping SQLite statement iterators exhausted after completion.
Description check ✅ Passed The description explains the behavior change, implementation, related issue, regression coverage, and validation results. It does not use every template heading or checklist item, but it contains the …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main via merge train #9922. Validated as a tree: 64/64 lint gates, and perry-runtime/codegen/hir/stdlib all green (5,962 tests, 0 failures). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant