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:
- A: A Chapter (depth 1, p1) → A Section (2, p2) → A Sub (3, p3) → A Sub-Sub (4, p4) → A Deep (5, p5)
- B: same five levels on pages 6–10
- C: same five levels on pages 11–15
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:
| Loop | Injected | Persisted proof (raw read-back of saved file) |
|---|---|---|
| root-cycle | Outlines root /Next → A Chapter | root_next_raw contains /Count: -1 and root_next_is_indirect = IndirectObject, points to A Chapter |
| cycle-and-break | A Sub /Next → A Section (cycle) and A Section /First+/Last → NULL (break), same source | section_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-l5 | A Section /First+/Last → NULL | section_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):
| 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 — expected_depth 3, expected_page 3 | |||
| A Sub-Sub | MISSING — expected_depth 4, expected_page 4 | |||
| A Deep | MISSING — expected_depth 5, expected_page 5 | |||
| B Chapter | 1 | 6 | 6 (B+5) | true |
| B Section | 2 | 7 | 7 (B+5) | true |
| B Sub | 3 | 8 | 8 (B+5) | true |
| B Sub-Sub | 4 | 9 | 9 (B+5) | true |
| B Deep | 5 | 10 | 10 (B+5) | true |
| C Chapter | 1 | 11 | 11 (C+10) | true |
| C Section | 2 | 12 | 12 (C+10) | true |
| C Sub | 3 | 13 | 13 (C+10) | true |
| C Sub-Sub | 4 | 14 | 14 (C+10) | true |
| C Deep | 5 | 15 | 15 (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)
- day43_results.json — three loops: construction, persisted-probes, source/merged read-backs, checks, missing_rows, honest_limits
- day43_merged_chain-break-l5.pdf — merged output with the three-row erasure (12 rows)
- day43_merged_cycle-and-break.pdf — the simultaneous cycle+break loop (same 12/15)
- day43_merged_root-cycle.pdf — the 15/15 root-cycle loop
- day43_A_root-cycle.pdf · day43_A_chain-break-l5.pdf — source A with each shape on disk
- day43_B.pdf · day43_C.pdf — clean sources B and C (2,902 bytes each)
- day43_run.py — the full archived run script
Addendum artifacts:
- day43_addendum_results.json — loop2 unique-filename re-run + live-cycle run: raw probes, merged read-backs, acceptance checks
- day43_addendum_run.py — the addendum script (unique filenames, raw object-stream and xref dumps)
- day43_A_live_cycle_break_elsewhere.pdf — source A with the live sibling cycle + break elsewhere on disk
- day43_merged_live_cycle_break_elsewhere.pdf — the 15/15 merged output whose raw dump shows the cycle edge removed
Honest limits — what we did NOT test
- Level-6+ depth: untested.
- Malformed XREF / cross-reference-stream corruption: untested.
- Breaks or cycles in sources B or C: untested — only source A was broken.
- Cycle kept alive after a break elsewhere (cycle partner reachable from both sides): tested in the 2026-11-29 addendum above — 15/15 rows, cycle edge silently untied in the merged output.