Level-3 Bookmarks and a Broken Grandparent Chain: the Deepest Row Vanished and Only the Surviving 8 Told You Where It Was
Run 2026-11-27 · PyMuPDF 1.28.2 source build · pypdf 6.20.0 merge · 3 sources × 3 pages × 3 outline levels · 0 guessed numbers · every number below read back from the saved files, not asserted.
This is the fourth article in our outline-series. Nested bookmarks survived a merge (level-2 rows), a cyclic outline was untied, and a broken level-2 chain lost its row. This one pushes the break one level deeper: what happens to a level-3 row when the chain above it is cut — and does anything in the merged output tell you it existed?
Construction
Three sources, each 3 pages, each with a 3-level outline:
- A: A Chapter (depth 1, p1) → A Section (depth 2, p2) → A Sub (depth 3, p3)
- B: B Chapter (p4) → B Section (p5) → B Sub (p6)
- C: C Chapter (p7) → C Section (p8) → C Sub (p9)
Clean merge benchmark: 9 rows, three levels, every row on its own page. We then broke the level-3 parent chain in source A two ways and merged A (broken) with B and C (clean) via pypdf append, offsets A+0 / B+3 / C+6.
Both breaks were proven on disk first
Same honest rule as the level-2 test: a loop only counts as evidence if the broken state is readable back from the saved file. Raw read-back:
| Loop | Injected | Persisted proof (raw read-back of saved file) |
|---|---|---|
| chain-break-l3 | A Section /First+/Last → NULL | section_first=NullObject, section_last=NullObject — A Sub unreachable |
| dangling-first-l3 | A Section /First → IndirectObject(9999) | section_first=9999 + pypdf read warnings “Object 9999 0 not defined” / “Outline node is not a dictionary: NullObject” |
Result: the level-3 row vanished, and the survivors named it
Both loops produced the same outcome — the cleanest signal in this series so far:
| Title | Depth | Page | Expected | page_match |
|---|---|---|---|---|
| A Chapter | 1 | 1 | 1 (A+0) | true |
| A Section | 2 | 2 | 2 (A+0) | true |
| A Sub | MISSING — reported in broken_parent_links: expected_depth 3, expected_page 3 | |||
| B Chapter | 1 | 4 | 4 (B+3) | true |
| B Section | 2 | 5 | 5 (B+3) | true |
| B Sub | 3 | 6 | 6 (B+3) | true |
| C Chapter | 1 | 7 | 7 (C+6) | true |
| C Section | 2 | 8 | 8 (C+6) | true |
| C Sub | 3 | 9 | 9 (C+6) | true |
bookmarks_out = 8 of 9 in both loops. all_pages_match = false in both loops — because the missing-row scan found the gap, not because any surviving row was repaired. Every surviving row’s page_match is true against its offset-adjusted expectation, and its landing page contains the source-page marker text. The level-3 row was silently pruned by the merge, and the only trace it left is the missing-row report: broken_parent_links: [{title: "A Sub", expected_depth: 3, expected_page: 3}].
Why the level-3 row dies harder than a level-2 row
In the level-2 break test, the merge dropped the orphan too. What’s new at level 3 is who can kill it: the row’s parent is A Section, not a top-level chapter. Cutting A Section’s child pointers doesn’t just orphan the level-3 row — it severs the only path the merge walks to discover it. A depth-stack rebuild (the fix from the nested merge test) can’t resurrect what the walker never reached. That’s the practical difference between “a row is broken” and “a row is unreachable”: unreachable rows don’t get migrated, they get erased, and the erasure is silent unless your checker walks the benchmark and the result side by side.
Files (all read back from disk, not asserted)
- day41_results.json — both loops: construction, persisted-proof, source/merged read-backs, 8 checks each, missing-row entries, honest_limits
- day41_merged_chain-break-l3.pdf · day41_merged_dangling-first-l3.pdf — merged outputs (8 rows each)
- day41_A_chain-break-l3.pdf — source A with the level-3 break on disk
Honest limits — what we did NOT test
- Level-4+ depth: untested. A break above a level-4 row may behave differently.
- L3 break in sources B or C: untested — only source A was broken.
- Cyclic references at level-3: untested (see the cyclic test for the level-1/2 version).
- Malformed XREF / cross-reference-stream corruption: untested.