FAILURE MAP
← Case archive

FA-79981 / Typography line breaking / Open access

Widow and orphan page breaking: widow pull-back amount · case 01

The wrong number of lines is moved to the next page to cure a widow.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Lines kept are computed from the page room instead of the remaining paragraph lines.

THE FAILURE

Lines kept are computed from the page room instead of the remaining paragraph lines.

Unsuccessful approach: Keeping one extra line re-creates the widow.

Case contract

Input [paragraph line counts, page height, min orphan lines, min widow lines]. Lines flow onto pages. When a paragraph must break on a page that already holds lines, at least min widow lines must carry to the next page (move lines forward) and, if the paragraph starts on this page, at least min orphan lines must stay (else move it all). A paragraph that exactly fits stays. Constraints are waived on an empty page. Return lines per page.

Why this case matters

Line breaking decides where paragraphs wrap on screen and in print; a wrong decision point shifts every following line.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    paras, H, orphan, widow = x
    pages = []
    used = 0
    for p in paras:
        rem = p
        started = True
        while rem > 0:
            room = H - used
            if rem <= room:
                used += rem
                rem = 0
                continue
            a = room
            if used > 0:
                if rem - a < widow:
                    a = max(room - widow, 0)
                if started and a < orphan:
                    a = 0
            used += a
            rem -= a
            if a > 0:
                started = False
            pages.append(used)
            used = 0
    if used > 0:
        pages.append(used)
    return pages
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('regression: widow pull-back amount', [[5, 5, 3], 9, 1, 3], [7, 6]), ('regression: widow pull-back amount', [[1, 5, 6, 1, 2, 4, 2, 6], 7, 2, 3], [6, 7, 6, 5, 3]), ('regression: widow pull-back amount', [[5, 5, 4, 3], 8, 1, 2], [8, 7, 2]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('control layout', [[8, 7, 6, 3, 8], 10, 3, 3], [8, 10, 10, 4]), ('control layout', [[4, 1, 9, 9, 1], 12, 1, 2], [12, 12])], [('regression: widow pull-back amount', [[4, 6, 5, 6, 1, 7, 3, 4], 9, 3, 3], [7, 8, 7, 7, 7]), ('regression: widow pull-back amount', [[3, 2, 1, 1, 5, 5, 6], 5, 2, 3], [5, 4, 5, 5, 4]), ('regression: widow pull-back amount', [[1, 2, 2, 4, 6, 2], 8, 1, 2], [7, 8, 2]), ('regression: widow pull-back amount', [[6, 4, 6, 7, 5, 3], 8, 3, 2], [6, 8, 7, 7, 3]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('control layout', [[1, 3, 9, 4, 3, 6], 10, 3, 1], [10, 10, 6]), ('control layout', [[5, 1, 9, 2, 5, 1, 7, 1], 7, 2, 1], [6, 7, 7, 7, 4])], [('regression: widow pull-back amount', [[9, 7, 3, 7, 4, 4, 7], 10, 1, 3], [10, 10, 10, 8, 3]), ('regression: widow pull-back amount', [[8, 7, 5, 1, 8, 2, 2], 6, 2, 3], [6, 6, 5, 6, 6, 4]), ('regression: widow pull-back amount', [[6, 4, 6, 7, 5, 3], 8, 3, 2], [6, 8, 7, 7, 3]), ('regression: widow pull-back amount', [[2, 3, 3, 3, 5, 6, 5, 5], 4, 2, 3], [2, 3, 3, 3, 4, 4, 3, 4, 3, 3]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('control layout', [[2, 2, 4, 6], 4, 3, 3], [4, 4, 4, 2]), ('control layout', [[6, 9, 1, 3], 8, 1, 2], [8, 8, 3])], [('regression: widow pull-back amount', [[2, 8, 4, 5, 9, 5, 8, 2], 9, 3, 3], [7, 7, 9, 5, 9, 6]), ('regression: widow pull-back amount', [[2, 1, 4, 9, 4, 3], 5, 1, 3], [4, 5, 5, 3, 3, 3]), ('regression: widow pull-back amount', [[4, 6, 5, 8, 9], 5, 2, 2], [4, 5, 4, 5, 5, 5, 4]), ('partial-repair probe', [[7, 9, 3, 9, 7, 5], 5, 3, 3], [5, 5, 5, 4, 5, 4, 5, 2, 5]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('control layout', [[4, 9, 6], 5, 3, 1], [4, 5, 4, 5, 1]), ('control layout', [[5, 5, 8, 4, 2], 10, 2, 1], [10, 10, 4])], [('regression: widow pull-back amount', [[4, 6, 5, 6, 1, 7, 3, 4], 9, 3, 3], [7, 8, 7, 7, 7]), ('regression: widow pull-back amount', [[1, 5, 2, 2, 2, 6], 9, 3, 3], [8, 7, 3]), ('regression: widow pull-back amount', [[1, 2, 6, 8, 5, 2], 8, 2, 2], [7, 8, 7, 2]), ('regression: widow pull-back amount', [[8, 7, 6, 5, 6, 5, 5, 3], 11, 1, 2], [11, 11, 11, 10, 2]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[3, 6, 2, 3], 11, 2, 1], [11, 3]), ('control layout', [[2, 2, 9, 7, 5, 4], 6, 2, 1], [6, 6, 6, 6, 5])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
single widow pulled back[3, 4][5, 2]Failed
regression: widow pull-back amount[6, 7][7, 6]Failed
regression: widow pull-back amount[6, 7, 6, 4, 4][6, 7, 6, 5, 3]Failed
regression: widow pull-back amount[8, 6, 3][8, 7, 2]Failed
paragraph exactly fills page[6, 3][6, 3]Passed
orphan pushed forward[5, 3][5, 3]Passed
control layout[8, 10, 10, 4][8, 10, 10, 4]Passed
control layout[12, 12][12, 12]Passed

SHA-256 / b3c8b6b942bac90e5bc6deec54d110255179bc62b2a7b04a47d283db58480e87

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    paras, H, orphan, widow = x
    pages = []
    used = 0
    for p in paras:
        rem = p
        started = True
        while rem > 0:
            room = H - used
            if rem <= room:
                used += rem
                rem = 0
                continue
            a = room
            if used > 0:
                if rem - a < widow:
                    a = max(rem - widow + 1, 0)
                if started and a < orphan:
                    a = 0
            used += a
            rem -= a
            if a > 0:
                started = False
            pages.append(used)
            used = 0
    if used > 0:
        pages.append(used)
    return pages
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('regression: widow pull-back amount', [[5, 5, 3], 9, 1, 3], [7, 6]), ('regression: widow pull-back amount', [[1, 5, 6, 1, 2, 4, 2, 6], 7, 2, 3], [6, 7, 6, 5, 3]), ('regression: widow pull-back amount', [[5, 5, 4, 3], 8, 1, 2], [8, 7, 2]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('control layout', [[8, 7, 6, 3, 8], 10, 3, 3], [8, 10, 10, 4]), ('control layout', [[4, 1, 9, 9, 1], 12, 1, 2], [12, 12])], [('regression: widow pull-back amount', [[4, 6, 5, 6, 1, 7, 3, 4], 9, 3, 3], [7, 8, 7, 7, 7]), ('regression: widow pull-back amount', [[3, 2, 1, 1, 5, 5, 6], 5, 2, 3], [5, 4, 5, 5, 4]), ('regression: widow pull-back amount', [[1, 2, 2, 4, 6, 2], 8, 1, 2], [7, 8, 2]), ('regression: widow pull-back amount', [[6, 4, 6, 7, 5, 3], 8, 3, 2], [6, 8, 7, 7, 3]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('control layout', [[1, 3, 9, 4, 3, 6], 10, 3, 1], [10, 10, 6]), ('control layout', [[5, 1, 9, 2, 5, 1, 7, 1], 7, 2, 1], [6, 7, 7, 7, 4])], [('regression: widow pull-back amount', [[9, 7, 3, 7, 4, 4, 7], 10, 1, 3], [10, 10, 10, 8, 3]), ('regression: widow pull-back amount', [[8, 7, 5, 1, 8, 2, 2], 6, 2, 3], [6, 6, 5, 6, 6, 4]), ('regression: widow pull-back amount', [[6, 4, 6, 7, 5, 3], 8, 3, 2], [6, 8, 7, 7, 3]), ('regression: widow pull-back amount', [[2, 3, 3, 3, 5, 6, 5, 5], 4, 2, 3], [2, 3, 3, 3, 4, 4, 3, 4, 3, 3]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('control layout', [[2, 2, 4, 6], 4, 3, 3], [4, 4, 4, 2]), ('control layout', [[6, 9, 1, 3], 8, 1, 2], [8, 8, 3])], [('regression: widow pull-back amount', [[2, 8, 4, 5, 9, 5, 8, 2], 9, 3, 3], [7, 7, 9, 5, 9, 6]), ('regression: widow pull-back amount', [[2, 1, 4, 9, 4, 3], 5, 1, 3], [4, 5, 5, 3, 3, 3]), ('regression: widow pull-back amount', [[4, 6, 5, 8, 9], 5, 2, 2], [4, 5, 4, 5, 5, 5, 4]), ('partial-repair probe', [[7, 9, 3, 9, 7, 5], 5, 3, 3], [5, 5, 5, 4, 5, 4, 5, 2, 5]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('control layout', [[4, 9, 6], 5, 3, 1], [4, 5, 4, 5, 1]), ('control layout', [[5, 5, 8, 4, 2], 10, 2, 1], [10, 10, 4])], [('regression: widow pull-back amount', [[4, 6, 5, 6, 1, 7, 3, 4], 9, 3, 3], [7, 8, 7, 7, 7]), ('regression: widow pull-back amount', [[1, 5, 2, 2, 2, 6], 9, 3, 3], [8, 7, 3]), ('regression: widow pull-back amount', [[1, 2, 6, 8, 5, 2], 8, 2, 2], [7, 8, 7, 2]), ('regression: widow pull-back amount', [[8, 7, 6, 5, 6, 5, 5, 3], 11, 1, 2], [11, 11, 11, 10, 2]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[3, 6, 2, 3], 11, 2, 1], [11, 3]), ('control layout', [[2, 2, 9, 7, 5, 4], 6, 2, 1], [6, 6, 6, 6, 5])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
single widow pulled back[6, 1][5, 2]Failed
regression: widow pull-back amount[8, 5][7, 6]Failed
regression: widow pull-back amount[6, 7, 6, 6, 2][6, 7, 6, 5, 3]Failed
regression: widow pull-back amount[8, 8, 1][8, 7, 2]Failed
paragraph exactly fills page[6, 3][6, 3]Passed
orphan pushed forward[5, 3][5, 3]Passed
control layout[8, 10, 10, 4][8, 10, 10, 4]Passed
control layout[12, 12][12, 12]Passed

SHA-256 / 170c95223e147eae7ab439921252bee7af4f3079e2cb129e88530382aa7c1cf6

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

Verification & scope

A deterministic toy typesetting model with integer widths and a stipulated rule set; it does not claim conformance to any engine. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:49:49.644392+00:00.

Case digest / 4b5930fab9420941ae832468642aefd10612f8ee1c4e487e46bbcd6745ae3207