FA-76721 / Email MIME structure / Open access
Reassemble message/partial fragments: unknown total · case 01
A message is declared complete before the fragment carrying the total has arrived.
ROOT CAUSE
The unknown total decision evaluates `total = g['totals'][0] if g['totals'] else max(g['parts'])` where the contract requires `if not g['totals']: out.append([pid, 'incomplete', None]) continue total = g['totals'][0]`.
THE FAILURE
The unknown total decision evaluates `total = g['totals'][0] if g['totals'] else max(g['parts'])` where the contract requires `if not g['totals']: out.append([pid, 'incomplete', None]) continue total = g['totals'][0]`.
Unsuccessful approach: Guessing the total from the fragment count is equally premature. The attempted `total = g['totals'][0] if g['totals'] else len(g['parts'])` still disagrees with a fixture.
Case contract
fragments {id, number, total (optional), body}. Per id: the first fragment with a given number wins; totals seen on fragments must all agree (otherwise "conflict"); without any total the message is "incomplete"; it is "complete" when every number 1..total is present, and its text joins those numbers in order (other numbers are ignored). Result rows [id, status, text or None] sorted by id.
Why this case matters
Large messages split with message/partial must be reassembled exactly once and in order.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(fragments):
groups = {}
for f in fragments:
g = groups.setdefault(f['id'], {'totals': [], 'parts': {}})
if f.get('total') is not None:
g['totals'].append(f['total'])
g['parts'].setdefault(f['number'], f['body'])
out = []
for pid in sorted(groups):
g = groups[pid]
if len(set(g['totals'])) > 1:
out.append([pid, 'conflict', None])
continue
total = g['totals'][0] if g['totals'] else max(g['parts'])
if all(n in g['parts'] for n in range(1, total + 1)):
out.append([pid, 'complete', ''.join(g['parts'].get(n, '') for n in range(1, total + 1))])
else:
out.append([pid, 'incomplete', None])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD1'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD1']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b1'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '11'}],), [['r', 'complete', '1123']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z1'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one1'}],), [['t', 'complete', 'one1two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z1'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w1', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w1', 'complete', 'solo']])], 2: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD2'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD2']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b2'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '12'}],), [['r', 'complete', '1223']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z2'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one2'}],), [['t', 'complete', 'one2two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z2'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w2', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w2', 'complete', 'solo']])], 3: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD3'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD3']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b3'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '13'}],), [['r', 'complete', '1323']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z3'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one3'}],), [['t', 'complete', 'one3two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z3'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w3', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w3', 'complete', 'solo']])], 4: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD4'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD4']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b4'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '14'}],), [['r', 'complete', '1423']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z4'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one4'}],), [['t', 'complete', 'one4two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z4'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w4', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w4', 'complete', 'solo']])], 5: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD5'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD5']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b5'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '15'}],), [['r', 'complete', '1523']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z5'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one5'}],), [['t', 'complete', 'one5two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z5'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w5', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w5', 'complete', 'solo']])]}
for _label, _args, _expected in _CASES[N]:
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| retransmitted fragment | [['p', 'complete', 'ABCD1']] | [['p', 'complete', 'ABCD1']] | Passed |
| no total yet | [['q', 'complete', 'ab1']] | [['q', 'incomplete', None]] | Failed |
| repeated equal totals | [['r', 'complete', '1123']] | [['r', 'complete', '1123']] | Passed |
| disagreeing totals | [['s', 'conflict', None]] | [['s', 'conflict', None]] | Passed |
| out of order with stray number | [['t', 'complete', 'one1two']] | [['t', 'complete', 'one1two']] | Passed |
| missing middle with stray | [['u', 'incomplete', None]] | [['u', 'incomplete', None]] | Passed |
| two messages | [['v', 'incomplete', None], ['w1', 'complete', 'solo']] | [['v', 'incomplete', None], ['w1', 'complete', 'solo']] | Passed |
SHA-256 / 039eb542499359c4bb95d39ab51445612cbf8199288e7ce8622fa42398b4e8fb
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(fragments):
groups = {}
for f in fragments:
g = groups.setdefault(f['id'], {'totals': [], 'parts': {}})
if f.get('total') is not None:
g['totals'].append(f['total'])
g['parts'].setdefault(f['number'], f['body'])
out = []
for pid in sorted(groups):
g = groups[pid]
if len(set(g['totals'])) > 1:
out.append([pid, 'conflict', None])
continue
total = g['totals'][0] if g['totals'] else len(g['parts'])
if all(n in g['parts'] for n in range(1, total + 1)):
out.append([pid, 'complete', ''.join(g['parts'].get(n, '') for n in range(1, total + 1))])
else:
out.append([pid, 'incomplete', None])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD1'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD1']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b1'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '11'}],), [['r', 'complete', '1123']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z1'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one1'}],), [['t', 'complete', 'one1two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z1'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w1', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w1', 'complete', 'solo']])], 2: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD2'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD2']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b2'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '12'}],), [['r', 'complete', '1223']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z2'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one2'}],), [['t', 'complete', 'one2two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z2'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w2', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w2', 'complete', 'solo']])], 3: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD3'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD3']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b3'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '13'}],), [['r', 'complete', '1323']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z3'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one3'}],), [['t', 'complete', 'one3two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z3'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w3', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w3', 'complete', 'solo']])], 4: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD4'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD4']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b4'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '14'}],), [['r', 'complete', '1423']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z4'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one4'}],), [['t', 'complete', 'one4two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z4'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w4', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w4', 'complete', 'solo']])], 5: [('retransmitted fragment', ([{'id': 'p', 'number': 1, 'body': 'AB'}, {'id': 'p', 'number': 2, 'total': 2, 'body': 'CD5'}, {'id': 'p', 'number': 1, 'body': 'XX'}],), [['p', 'complete', 'ABCD5']]), ('no total yet', ([{'id': 'q', 'number': 1, 'body': 'a'}, {'id': 'q', 'number': 2, 'body': 'b5'}],), [['q', 'incomplete', None]]), ('repeated equal totals', ([{'id': 'r', 'number': 2, 'total': 3, 'body': '2'}, {'id': 'r', 'number': 3, 'total': 3, 'body': '3'}, {'id': 'r', 'number': 1, 'body': '15'}],), [['r', 'complete', '1523']]), ('disagreeing totals', ([{'id': 's', 'number': 1, 'total': 3, 'body': 'x'}, {'id': 's', 'number': 2, 'total': 4, 'body': 'y'}, {'id': 's', 'number': 3, 'total': 3, 'body': 'z5'}],), [['s', 'conflict', None]]), ('out of order with stray number', ([{'id': 't', 'number': 2, 'total': 2, 'body': 'two'}, {'id': 't', 'number': 3, 'body': 'junk'}, {'id': 't', 'number': 1, 'body': 'one5'}],), [['t', 'complete', 'one5two']]), ('missing middle with stray', ([{'id': 'u', 'number': 1, 'total': 2, 'body': 'a'}, {'id': 'u', 'number': 5, 'body': 'z5'}],), [['u', 'incomplete', None]]), ('two messages', ([{'id': 'w5', 'number': 1, 'total': 1, 'body': 'solo'}, {'id': 'v', 'number': 1, 'total': 2, 'body': 'half'}],), [['v', 'incomplete', None], ['w5', 'complete', 'solo']])]}
for _label, _args, _expected in _CASES[N]:
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| retransmitted fragment | [['p', 'complete', 'ABCD1']] | [['p', 'complete', 'ABCD1']] | Passed |
| no total yet | [['q', 'complete', 'ab1']] | [['q', 'incomplete', None]] | Failed |
| repeated equal totals | [['r', 'complete', '1123']] | [['r', 'complete', '1123']] | Passed |
| disagreeing totals | [['s', 'conflict', None]] | [['s', 'conflict', None]] | Passed |
| out of order with stray number | [['t', 'complete', 'one1two']] | [['t', 'complete', 'one1two']] | Passed |
| missing middle with stray | [['u', 'incomplete', None]] | [['u', 'incomplete', None]] | Passed |
| two messages | [['v', 'incomplete', None], ['w1', 'complete', 'solo']] | [['v', 'incomplete', None], ['w1', 'complete', 'solo']] | Passed |
SHA-256 / ca337984b1a3722c6a2eea512a35cc6989fd2ebc47f288e57f7d0a24d4042d60
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 7 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
Stipulated offline model over pre-parsed MIME dictionaries; not a conforming MIME parser, generator or mail client. 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:19.110779+00:00.
Case digest / b612de37a85f869b9593bbe838e527121b207ac2b51e2110b5c9bdc37544f9d7