Skip to content

[PHP] Bound pending reads when restoring OPFS sites - #4386

Merged
adamziel merged 1 commit into
trunkfrom
codex/opfs-bounded-restore-reads
Oct 6, 2026
Merged

adamziel merged 1 commit into
trunkfrom
codex/opfs-bounded-restore-reads

Conversation

@adamziel

@adamziel adamziel commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Restoring a saved site used to create a pending promise for every entry, even though only 40 reads could run at once. Repeated Promise.any() calls then attached callbacks to all those pending reads. Large saved sites could exhaust the JavaScript heap.

Acquire a slot before creating the read promise. Keep the remaining entries in the directory iterator. If a read fails, drain outstanding reads before returning the error so a retry cannot overlap the previous attempt.

Adds tests for bounded enumeration and failure draining. Does not change OPFS writes, mount tracking, or runtime rotation.

Extracted from #4373. Targets trunk directly and does not depend on the other split PRs.

Testing

Save a large Playground locally, reload it, and check that its files restore. Review the tests that hold reads open to check the queue bound and error handling.

Summary by CodeRabbit

  • Bug Fixes
    • Improved loading of saved files so large directories are processed with bounded read activity.
    • When a file read fails, the error is reported after other in-progress reads finish. Files already read are retained, and the directory is not mounted after the failed copy.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d70946b-6eac-4878-be31-a785e59ff793
📥 Commits

Reviewing files that changed from the base of the PR and between 769e72b and 017eb1c.

📒 Files selected for processing (2)
  • packages/php-wasm/web/src/lib/directory-handle-mount.spec.ts
  • packages/php-wasm/web/src/lib/directory-handle-mount.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

OPFS-to-MEMFS restore now acquires capacity before scheduling each read, stops scheduling after a read fails, and waits for outstanding reads to settle before returning. Tests cover bounded enumeration and restore behavior when a read fails.

Changes

OPFS restore

Layer / File(s) Summary
Bounded restore and failure handling
packages/php-wasm/web/src/lib/directory-handle-mount.ts, packages/php-wasm/web/src/lib/directory-handle-mount.spec.ts
copyOpfsToMemfs acquires semaphore capacity before scheduling reads, stops scheduling after the first read error, and waits for outstanding reads before rethrowing. Tests check that enumeration stays bounded and that a failed copy rejects after pending reads settle.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant MountHandler
  participant copyOpfsToMemfs
  participant OPFS
  participant MEMFS
  MountHandler->>copyOpfsToMemfs: Start restore
  copyOpfsToMemfs->>OPFS: Read files within semaphore capacity
  OPFS->>MEMFS: Copy successfully read files
  OPFS-->>copyOpfsToMemfs: Return first read error
  copyOpfsToMemfs->>OPFS: Wait for outstanding reads to settle
  copyOpfsToMemfs-->>MountHandler: Reject with first read error
Loading

Merge Risk: ⚪ Minimal · up to 017eb

The bounded restore and failure-draining paths show no identified merge-blocking issue. Merge after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: bounding pending reads when restoring OPFS sites.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@adamziel
adamziel merged commit 93e276f into trunk Oct 6, 2026
@adamziel
adamziel deleted the codex/opfs-bounded-restore-reads branch October 6, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant