PDF TO MD EXECUTED TEST

Root-Level Cycle, Simultaneous Cycle + Break, and a Level-5 Chain Break vs a 15-Row Merge: Cycles Survive, One Cut Erased Three Levels at Once

Run 2026-11-29 · PyMuPDF source build · pypdf merge · 3 sources × 5 pages × 5 outline levels · 3 loops · 0 guessed numbers · every number below read back from the saved files, not asserted.

This is the seventh article in our outline-series. Level-2 rows survived a merge, a cyclic outline was untied, a broken level-2 chain lost its row, a level-3 break erased the deepest row, and a level-4 test showed one cut erasing two rows at once. This one closes the last three untested shapes from that article: a cycle at the outline root itself, a simultaneous cycle + chain break in the same source, and a chain break over a five-level subtree.

Construction

Three sources, each 5 pages, each with a 5-level outline:

Clean merge benchmark: 15 rows, five levels, every row on its own page. Merged via pypdf append, offsets A+0 / B+5 / C+10. Three loops, each injected into source A and proven on disk before merging. One provenance note (added 2026-11-29): the original run overwrote its shared source filename, so the cycle-and-break on-disk proof comes from a re-produced source (same injector, same key order) — see the provenance note in day43_results.json and the addendum below, which re-runs the shape under a unique filename.

All three shapes were proven on disk first

Same honest rule as the earlier tests: a loop only counts as evidence if the injected state is readable back from the saved file via a raw (un-dereferenced) read. One method fix we caught ourselves mid-run: the first probe dereferenced values, so a persisted NullObject raised inside the probe and a persisted /Next 17 0 R indirect reference read as "not a cycle" — we switched to raw_get() and to matching the IndirectObject marker in the probe dump. We fixed the probe, not the data. Raw read-back:

LoopInjectedPersisted proof (raw read-back of saved file)
root-cycleOutlines root /Next → A Chapterroot_next_raw contains /Count: -1 and root_next_is_indirect = IndirectObject, points to A Chapter
cycle-and-breakA Sub /Next → A Section (cycle) and A Section /First+/Last → NULL (break), same sourcesection_first_raw = NullObject, section_last_raw = NullObject; cycle_note: the Sub is unreachable from the tree, so the cycle reads back only via the break
chain-break-l5A Section /First+/Last → NULLsection_first_raw = NullObject, section_last_raw = NullObject

Result: cycles survive whole; one level-2 cut erased three levels at once

root-cycle came back 15/15 rows, every page_match true, all_pages_match true. A cycle hanging off the outline root never enters the merge walk — harmless, exactly as the level-2 cycles were in the Day42 test.

The two break loops (12 of 15 rows, all three missing rows named):

TitleDepthPageExpectedpage_match
A Chapter111 (A+0)true
A Section222 (A+0)true
A SubMISSING — expected_depth 3, expected_page 3
A Sub-SubMISSING — expected_depth 4, expected_page 4
A DeepMISSING — expected_depth 5, expected_page 5
B Chapter166 (B+5)true
B Section277 (B+5)true
B Sub388 (B+5)true
B Sub-Sub499 (B+5)true
B Deep51010 (B+5)true
C Chapter11111 (C+10)true
C Section21212 (C+10)true
C Sub31313 (C+10)true
C Sub-Sub41414 (C+10)true
C Deep51515 (C+10)true

bookmarks_out = 12 of 15, all_pages_match = false, missing_rows name A Sub / A Sub-Sub / A Deep with their expected depth and page — never 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 cycle-and-break loop produced the same 12/15 result as the plain break: the injected cycle vanished with the break because its cycle partner (A Sub) was unreachable from the tree — the break dominates.

What this adds to the series conclusion

The erase-zone growth is now measured at three depths: a level-2 cut removed 1 row (level-3) in the level-3 test, 2 rows (levels 3–4) in the level-4 test, and 3 rows (levels 3–5) here — one silent cut, damage proportional to subtree depth. Cycles, at every position tested (self, pair, back-cycle, and now the root itself), never cost a row. Simultaneous cycle + break resolves to the break's outcome. The checker that matters is unchanged: walk the benchmark and the result side by side, and report what the merge dropped by name, depth, and expected page.

Addendum (2026-11-29): the loop2 file provenance, and a live cycle with the break elsewhere

Two things the addendum run closes, same 3-source × 5-level bench, same offsets A+0 / B+5 / C+10:

1. loop2 re-run under a unique filename. The original injector saves the cycle+break source to its own file this time (never overwritten). Raw read-back of that original shows why the cycle never had on-disk evidence in the first run: clone_from drops the unreachable orphan entirely — the A Sub object is not present in the saved file at all (objects 22+ unresolved; the only Sub-titled object in the file is the font subtype line). The break (Section /First+/Last = NullObject) is on disk exactly as before. The re-produced-source proof in day43_results.json stands as the only on-disk cycle evidence for this shape, and is now labeled as such.

2. A live cycle + a break elsewhere. Every cycle so far sat on /Next, which the tree walk never follows (the bench builds nesting through /First). The addendum puts the cycle where the walker can reach it while keeping both nodes live: A Sub-Sub /Next → A Sub (sibling chain cycle, both nodes reachable from the root) plus A Section /Last → NULL (break elsewhere; /First intact, so nothing becomes unreachable). Acceptance: bookmarks_out = 15 exactly, and the cycle raw read-back still present.

Result: 15/15 rows, every page_match true, no crash — but the second acceptance check fails honestly: the merged file's A Sub-Sub object has no /Next key at all (confirmed two ways: pypdf raw_get and a PyMuPDF raw xref dump of the merged file; pypdf logged "Detected cycle in outlines." during the merge). pypdf did not crash on the live cycle and did not lose a row — it silently untied the loop edge while copying, without writing Null and without a marker. So the series conclusion holds and sharpens: a cycle never costs a row, and pypdf removes the cycle edge itself during merge; the checker that catches this is the raw read-back, not the row count.

Files (all read back from disk, not asserted)

Addendum artifacts:

Honest limits — what we did NOT test