Skip to content

fix(document): find a hinted page's index without the page tree (#410) - #413

Merged
michaelstonis merged 2 commits into
spec/33-broadside-v1from
410-remote-first-page-flake
Oct 24, 2026
Merged

michaelstonis merged 2 commits into
spec/33-broadside-v1from
410-remote-first-page-flake

Conversation

@michaelstonis

Copy link
Copy Markdown
Owner

Closes #410.

Root cause (a viewer bug, not a slow runner)

The CI failure was captured with a diagnostic build of the test (dispatched blazor-wasm runs on this branch). In 1 of 18 attempts, the viewer stopped at page 2 with frames idle. The sample showed this message above the viewer:

Bytes 1237022 to 1238274 of the remote file have not been fetched, and this document may not fetch them synchronously …

Those bytes are the main cross-reference section at the end of the linearized file. The chain:

  1. Page 1 shows, and the viewer loads page 1's selectable text and accessible tree. Both call PdfPage.ExtractLayout, which asks PdfPageCollection.IndexOf for the page's index.
  2. IndexOf walked the whole page tree. That needs the main cross-reference section and every tree node, and neither is part of a hinted page's prefetch. In the browser, synchronous range fetching is off, so this threw PdfRangeNotLoadedException. It failed for every page of a remote linearized file, in every run.
  3. The sample reports viewer errors as a .message banner above the viewer. The banner resizes the viewer, and InputModel.Resize stops a running scroll animation. The test's End jump therefore stopped wherever it was.
  4. The test passed only when the banner appeared before the key press. That is why the failure looked like a timing flake.

Fix

While the hint tables locate the pages, PdfPageCollection.IndexOf(CosDictionary) and TryGetPage now answer from the pages the hints handed out. F.3.7 guarantees that hinted pages are in page order, the same order this[int] already uses. Anything the hints did not hand out still goes through the page tree. HintedPageList records each handed-out page object's index.

Tests

  • FirstPageFirstTests.A_hinted_page_finds_its_index_and_extracts_its_layout_without_the_page_tree (Table and Stream xref layouts): with synchronous fetching off, pages 1, 2 and 30 return their index and extract their layout, with no request beyond each page's prefetch. Red before the fix (PdfRangeNotLoadedException), green after.
  • DocumentSessionTests.A_remote_linearized_page_loads_its_links_text_and_accessible_tree_without_synchronous_fetches (pages 0, 1, 29): a cooperative remote session, as in the browser. Red 3/3 before, green 3/3 after.
  • RemoteFirstPageTests: the test now waits until page 1's text layer has loaded (still behind the gate) and asserts that the viewer reported no error, both before the jump and at the end. It runs in Chromium, WebKit and Firefox. Against the pre-fix app the new assertion fails deterministically (10/10), so a regression can no longer show up as a flake.

Pass rates

Before After
Local, headless Chromium, test alone (old assertions) 30/30 30/30 (new assertions)
Local, three full suites in parallel, Chrome (old assertions) 15/15 –
Local, Chromium headless shell + WebKit – 30/30 + 30/30
Local, Google Chrome channel – 30/30
Local, new assertion against the old app 0/10 –
CI dispatched runs (diagnostic build, 6 repeats per run) 17/18 attempts, 1 reproduced failure see CI below

Firefox could not be launched inside the local agent sandbox, so it runs in CI only.

Follow-up (not in this PR)

InputModel.Resize stops a page jump in flight. Any banner or toolbar that appears during a jump cancels it. That is arguably a separate UX issue, and it is noted in flaky-tests.md.

🤖 Generated with Claude Code

michaelstonis and others added 2 commits October 23, 2026 20:31
RemoteFirstPageTests timed out intermittently in the blazor-wasm job. The
cause was a real bug, not slowness. For a remote linearized file, the
viewer's text selection and accessibility loads call PdfPage.ExtractLayout,
which asked PdfPageCollection.IndexOf for the page's index. IndexOf walked
the whole page tree, which needs the main cross-reference section at the
end of the file. The browser cannot fetch that synchronously, so every
page's load failed with a PdfRangeNotLoadedException. The Blazor sample
showed that error as a message above the viewer. The message resized the
viewer, and InputModel.Resize stops a running page animation, so the
test's End key jump stopped at whatever page it had reached (page 2 in
the captured CI failure). The test passed only when the message appeared
before the key press.

While the hint tables locate the pages, IndexOf and TryGetPage now answer
from the pages the hints handed out (F.3.7: hinted pages are in page
order), and fall back to the page tree for anything else.

Tests: a core test extracts the layout of pages 1, 2 and 30 of a remote
linearized file with synchronous fetching off and no request beyond each
page's prefetch; a viewer test loads links, text and the accessible tree
of those pages through a cooperative remote session; the browser test now
waits for page 1's text layer, asserts the viewer reported no error, and
runs in Chromium, WebKit and Firefox. The new browser assertion fails 10
of 10 times against the old app; all of them pass after the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 24, 2026 01:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

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.

2 participants