Repository navigation
fix(ppr): prioritize document shell captures - #801
Merged
Merged
Conversation
commit: |
4 tasks done
ivogt
added a commit
that referenced
this pull request
Jul 18, 2026
…-store guard (#803) Three operability gaps from the #801 incident: a queue-dropped capture reported only its wait (now: priority class + backlog at enqueue on the skip event and the rango.background span); bake cost was invisible (now: bakeWaitMs names the slowest gate-holding source on stored attempts, with a once-per-key dev warning past 2s carrying the nest/cache()/loading() remedy ladder); and a store whose shell family can only no-op (KV-less CFCacheStore, declared via SegmentCacheStore.shellFamilyInert) still burned a full background render per MISS (now: skip-inert-store at the scheduling gate).
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.
Problem
A consumer using PPR with production viewport prefetch can enqueue several slow navigation-only shell captures before a document MISS schedules its document-shell capture. The per-isolate capture queue previously used strict FIFO ordering, so speculative navigation work could consume the full 15-second queue budget first. The requested page remained on repeated
x-rango-shell: MISSresponses and its background trace ended asskip-queue-timeout, even though the route was eligible for a reusable document shell.Before And After
The consumer configuration does not change:
Before: if viewport prefetch scheduled several slow navigation snapshots first, the
/productsdocument capture waited behind all of them and could expire without storing a shell.After: the active capture still completes, then the queued
/productsdocument capture runs before queued navigation-only captures. The route can transition fromMISStoHITwithin the existing queue budget without any consumer migration.End-To-End Example
A product index renders a cached document shell around a live loader boundary. When the browser discovers several product links, viewport prefetch starts navigation-only PPR captures. A simultaneous hard request for
/productsserves its normal liveMISSresponse immediately and schedules a document capture in the same isolate. Once the currently running capture finishes, the document capture overtakes the queued speculative snapshots, stores the shell, and the next document request returnsx-rango-shell: HIT; the live products loader still resumes through the captured hole.Semantics
skip-queue-timeout; no failure backoff is addedskip-capacityCode Changes
src/rsc/capture-queue.tswith explicit document and navigation queues while retaining one active capture per isolate, admission accounting, per-item wait timers, rejection isolation, and the 60-second wedge cap.waitUntilpromise settles; resolving first allowed workerd to retire the context whilecaptureRunningremained locked.src/rsc/shell-capture.tsfrom the existingdescriptor.navigationOnlysignal. This keeps priority at the orchestration boundary where document and navigation captures are already distinguished.storedwith queue wait below the 15-second budget.Regression proof: strict FIFO makes the priority unit test receive
navigationbeforedocument, and the pressure scenario leaves the document capture behind speculative captures until the queue timeout path. The first CI run also exposed the workerd handoff bug: two later PPR document tests stayedMISSthrough all retries. The same 46-test Cloudflare PPR sequence reproduced both failures locally before the handoff fix and passed46/46afterward.Test Plan
pnpm run typecheckpnpm run test:unit:all(363 router files; 5,568 passed; 6 todo, plus all consumer unit and RSC suites)pnpm run lintpnpm run formatenqueueSerializedCapture > prioritizes a document capture over queued navigation capturesenqueueSerializedCapture > hands off before the completed capture caller can enqueue more worke2e/ppr-shell.test.ts(46/46passed)shell-capture-timeout (dev) > a document capture overtakes queued navigation-only capturesshell-capture-timeout (production) > a document capture overtakes queued navigation-only capturesppr capture timeout (dev) > a document capture overtakes queued navigation-only capturesppr capture timeout (production) > a document capture overtakes queued navigation-only capturesNotes