Skip to content

perf(mobile): keep four bundle chunk reads in flight across the whole manifest (OTA phase C follow-up) - #22376

Merged
Jinwoo-H merged 9 commits into
mainfrom
ota-fu-bundle-chunk-pipeline
Sep 23, 2026
Merged

Jinwoo-H merged 9 commits into
mainfrom
ota-fu-bundle-chunk-pipeline

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​303 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​294
Prod 790 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2140 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2024 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​116

The mobile web bundle fetch paged each asset one chunk at a time and ran one reader per asset, so the largest script (71 chunks of 48 KiB) was 71 serial round trips while the other three readers sat idle once the small assets were done. On a relay link every round trip costs the link's latency, so the bundle download was bounded by the biggest asset, not by the four read slots the host offers.

Now every (asset, offset) on the host's chunk grid is planned up front, largest asset first, and four workers pull from that one queue, so the four slots stay busy until the last chunk. eof is still taken from the reply; because offsets are planned, a reply is accepted only if it fills exactly its slot of the grid (a short non-final chunk is asset-short, a reply past the declared length is asset-overlong). One failed chunk stops every other read. A caller abort during the final window rejects with fetch-stopped as the contract says. Progress now counts bytes per accepted chunk rather than per completed asset, because largest-first would otherwise show "0 files, 0 bytes" for most of the download. Wire, host, and the released chunk method are unchanged.

Measured on a synthetic manifest of one 71-chunk asset plus five one-chunk assets, counting released waves through a fake host: 72 round trips before, 19 after. The new suite fails on the base code with expected 72 to be 19; the abort-in-the-last-window and progress-before-first-completion cases fail on the previous shape; the fake host keeps draining after the fetch settles, so the sibling-stop bounds fail (76 reads) if the stop is removed.

Design review. An Opus review pass took the branch from a hand-rolled dispatcher with read-limit narrowing to this worker pool: narrowing was dropped because the host frees its read slot before replying, so a lone fetch capped at four cannot trip the limit (a mobile_web_bundle_read_limited refusal fails the fetch, as before); a lazily allocated buffer with an unreachable null guard, a redundant per-asset byte count, and an unreachable stop branch were removed; one mutable field per asset remains.

Recording goldens. The bundle-fetch goldens record the order requests go out and the progress effects, so they are re-recorded here with baseline pinned to this branch's last fenced commit (the same shape as #22179). Five bundle goldens change bodies (request order, plus one progress effect per chunk); the two bundle-fetch scenarios in pilot-scenarios.json have their bind/complete steps in the new order; every other golden changes its baseline line only. The chunk-placement mutant is still killed. A repin to main's tip follows the squash as its own PR, as #22185 did.

Inert today: this code runs only in an EXPO_PUBLIC_MOBILE_SHELL=ota build's shell download path. Session-route closure pin unchanged at 4,213.

… manifest

The fetch ran one worker per asset and paged inside an asset sequentially, so
the largest script's 71 chunks were 71 serial round trips while the other
readers idled. One window of four chunk reads now covers every (asset, offset)
on the host's chunk grid, largest asset first. A read_limited refusal narrows
the window and retries the read; eof is still read from the reply.

Synthetic manifest (one 71-chunk asset, five small): 72 round trips -> 19.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Baseline moves to a1ee317, the pipelined fetch.
781 goldens change only their `baseline` header line. Six bodies move:
mobile-web-bundle-fetch-paged, mobile-web-bundle-build-changed, and the four
matrix-mobileweb.bundle-fetch-* goldens.

The two bundle-fetch scenarios now bind requests in pipelined order, largest
asset first, with every chunk sent before any reply: index.html@0 (#1),
index.html@16 (#2), assets/app.js@0 (#3).
- fetch-paged: the request set is identical, only reordered. The chunk
  sender names/ordinals and the scenarioSha256 moved; the replies and the
  fetched bytes did not.
- build-changed: the same reorder, plus one request that is new because
  pipelining puts it in flight before the refusal lands (index.html@16).
  The refusal and the checkpoint are unchanged.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Baseline moves from a1ee317 to e94bde3,
the comment-only commit on a fenced path. All 787 goldens and the scenarios file
change only their `baseline` line. No golden body moved.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one rough edge around caller abort.

Reviewed changes

  • Pipelined chunk window: fetchMobileWebBundle drops the four per-asset workers for a single pre-planned queue of (asset, offset) reads with up to four in flight across the whole manifest, largest asset first (planChunkReads, runChunkWindow in mobile/src/transport/mobile-web-bundle-fetch.ts).
  • Read-limited backpressure: a mobile_web_bundle_read_limited refusal at width > 1 narrows the window by one and retries the read; a refusal of a read sent alone fails the fetch.
  • Slot-filled chunk contract: a non-final chunk shorter than the advertised size, or one that reaches the declared length without eof, is now refused (asset-short / asset-overlong), which the host's fixed-grid read already guarantees.
  • Tests and goldens: new mobile-web-bundle-fetch-pipeline.test.ts (a wave-released fake host) plus adjusted mobile-web-bundle-fetch.test.ts; six bundle goldens and pilot-scenarios.json re-recorded, the other 781 goldens repinned to a1ee317.

The invariants hold under inspection: inFlight <= width <= 4 always, width is monotone non-increasing so retries terminate, the window only resolves when every planned read has settled, and a retry re-queues the same read object after a refusal that transferred no bytes. Host and client agree on the fixed 48 KiB grid, so the planned offsets match what the old chained reader asked for.

ℹ️ Nitpicks

  • MAX_CONCURRENT_ASSET_READS now bounds chunk reads across the whole manifest rather than one read per asset; the docstring explains the shift, but the identifier still reads as the old meaning.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No new issues in this increment — the prior caller-abort note still stands (thread open).

Reviewed changes (incremental, since e94bde3)

  • Recording-corpus repin: 6f5a5adffc moves the baseline header of all 788 goldens from a1ee317 to e94bde3 — the docs/comment commit that touched mobile-web-bundle-operations.ts. No source or test hunks; the recorded bodies are byte-identical. Provenance-only, consistent with the rpc-recording workflow.

The pipelined chunk-window rewrite itself was reviewed at e94bde3; this increment adds no behavioral surface. The one non-blocking note from that review — a caller abort that lands after the last read is dispatched resolves instead of rejecting — is unchanged and is the open thread.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review skipped: 792 files exceed the limit of 300.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

…t progress per chunk

Design-review fix round, sketch C: four workers take reads from one planned
chunk queue, largest asset first. They replace the central pump and the
read_limited narrowing. A host frees its read slot before it replies, so a lone
fetch capped at four cannot trip the limit. A refusal now fails the fetch, as
it did on base, and stops the other reads.

- Each asset's buffer is allocated when the plan is built. That removes the
  nullable buffer and its guard. The per-asset byte count is gone, and the
  hash is the oracle (S1, S2).
- The caller's signal is checked before each read and once after the pool
  drains, so an abort during the final window rejects with fetch-stopped
  (S3). The stopped check now covers only the caller's abort. The internal
  stop only makes late replies skip checks, hashing and progress (S4).
- Progress is reported per accepted chunk. completedAssets still counts on
  completion (S6).
- Renames: MAX_CONCURRENT_CHUNK_READS, and `reply` for the RPC reply (N1).
- The slot check states exact-slot acceptance once, then classifies the
  refusal (N3).
- Stale test titles and comments are renamed (N4).

The synthetic manifest still takes 19 round trips.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Baseline moves to 34fda6f. 782 goldens and
the scenarios file change only their `baseline` line. Five bodies move:
mobile-web-bundle-fetch-paged and the four matrix-mobileweb.bundle-fetch-*
goldens. The only change is bundle-progress effects. One report now lands
after the first accepted chunk of index.html (0 assets, 16 bytes), and the
later progress ordinals shift by one. Requests, replies and fetched bytes
are identical. mobile-web-bundle-build-changed keeps its body, because its
one accepted chunk is the whole of assets/app.js.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…ing-stop bounds can fail

The wave host stopped releasing replies once the fetch settled. Reads that
should have been stopped were never answered, so the read_limited bound (7)
and the chunk-failure bound (5) held even with no sibling stop at all. It now
drains until nothing waits. With the worker's stopped.abort() removed, both
bounds fail at 76 requests. assertChunkDescribesAsset's parameter is renamed
to `reply`.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… fix

Baseline moves from 34fda6f to 97b13ec.
All 787 goldens and the scenarios file change only their `baseline` line. No
golden body moved.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Worker pool over the planned grid: fetchMobileWebBundle drops the read-limit-narrowing dispatcher for four workers draining one manifest-wide queue of planned (asset, offset) reads (largest asset first); a mobile_web_bundle_read_limited refusal now fails the fetch instead of narrowing.
  • Per-chunk progress and eager reassembly: planChunkReads allocates each asset's whole buffer up front and drops the per-asset byte count; onProgress reports per accepted chunk, and verifyReassembledAsset keeps only the hash check because each slot is filled exactly once.
  • Exact-slot acceptance: assertChunkFillsItsSlot fast-accepts a reply that fills its planned slot (byteLength === min(chunkBytes, declared - offset) and matching eof), then classifies off-grid replies as chunk-oversize / asset-overlong / asset-no-progress / asset-short.
  • Caller abort in the final window: throwIfCallerAborted(args.signal) after Promise.all makes an abort that lands once every read is dispatched reject with fetch-stopped, with a new pipeline test.
  • Tests and recording corpus: the wave-released fake host now keeps draining after the fetch settles so the sibling-stop bounds can fail; the bundle goldens are re-recorded under per-chunk progress and the rest of the corpus is repinned.

The invariants hold: at most four reads in flight (peaks asserted exactly), every planned offset shifted once, a failed read rejects promptly through Promise.all while siblings stop, and the new tests fail when the stop or the final-window check is removed (verified by in-place mutation). The previous review thread on the final-window caller abort is addressed and resolved.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 0c2514e into main Sep 23, 2026
24 checks passed
@Jinwoo-H
Jinwoo-H deleted the ota-fu-bundle-chunk-pipeline branch September 23, 2026 04:11
Jinwoo-H added a commit that referenced this pull request Sep 23, 2026
…22394)

#22376 pinned its own branch commit, which the squash left off main; the corpus now pins main at 0c2514e, the tree its fenced paths match. Every golden changes only its baseline line.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
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