Skip to content

fix: a marginal note reading "Orat." discarded its whole container - #40

Merged
rayondemiel merged 1 commit into
mainfrom
fix/enrich-lone-abbreviation-refusals
Sep 21, 2026
Merged

rayondemiel merged 1 commit into
mainfrom
fix/enrich-lone-abbreviation-refusals

Conversation

@rayondemiel

Copy link
Copy Markdown
Member

The bug

teille-sync run reported incidents like this on documents that
otherwise converted cleanly:

lost to an incident                                       this needs a human
  containers failed      3 of 394 containers       the service refused these

The run still exits 0 and every document is ok, so the incident is pure
noise in the report — but it is noise that says "this needs a human", and
that kind of false alarm is what wears down attention on the real ones.

Root cause

Traced end to end, and reproducible on demand.

PyHellen answers HTTP 400 on a block whose entire text is a French
abbreviation. pie_extended masks those forms before sentence splitting
so their period does not end the sentence
(models/fr/excluders.py, ABBREVIATIONS). When the block holds nothing
but the abbreviation, nothing is left to split: zero sentences reach
PaPie, whose padding does max() on an empty list and raises
ValueError: max() arg is an empty sequence. PyHellen catches it in
_handle_processing_error and turns it into a 400.

Probed directly against the service — Orat. and Ibid. are in the
upstream list, the others are not:

input result
Orat., Ibid. 400
Arist., Cic., Plin., Abcd. 200
orat., ORAT. (list is case-sensitive) 200
Orat. Le roi est mort. (other content survives) 200

Every refusal observed on the corpus is one of these: 3 × Orat. in
LIV0020, 2 × Ibid. in LIV0026c. Both are exactly 5 characters, which is
precisely ENRICHMENT_MIN_TEXT_LENGTH — they clear the existing filter by
a hair.

What this changes

1. A refused block no longer discards its neighbours.
_finish_container returned on the first non-ok outcome, so one 400 threw
away every block of the container the service had answered — a
five-character reference could cost a Latin quotation and two French
paragraphs. It now skips that block and keeps the rest. The refusal flags
are counted once after the loop: the report divides them by
containers_found, so they must stay container counts, not block counts.

2. A lone abbreviation is not sent at all.
There is no lemma to find in Orat., so _prepare_container skips the
block instead of making the request that provokes the 400. The guard is
exact equality on the block's stripped text, not a "word then period"
heuristic — that would have swallowed Bonjour., a real word with a real
lemma. A test pins that boundary.

The two are independent: (1) is the robustness fix and matters for any
future refusal from any cause; (2) removes this particular one at the
source.

Evidence

Enrich phase only, against the live service:

document before after
LIV0020 3 of 394 — the service refused these no incident
LIV0026c 2 of 1687 — the service refused these no incident

PyHellen logged zero 400s across both runs. containers unanchored
is untouched (5 and 48): that guard is a deliberate decision, not a bug,
and this PR does not touch it. Full suite green; the end-to-end golden
diff is unchanged.

Not fixed here

The upstream defect stands: nothing to tag is not a bad request, and
PyHellen should answer 200 with an empty token list rather than 400 —
ultimately pie_extended should yield one sentence for an input that is
only an abbreviation, not zero. This PR stops the pipeline from losing
good blocks over it, and ENRICHMENT_LONE_ABBREVIATIONS carries a note to
resynchronise if the upstream list moves.

🤖 Generated with Claude Code

PyHellen answers HTTP 400 on a block whose text is nothing but a French
abbreviation. `pie_extended` masks those forms before sentence splitting
so their period does not end the sentence (models/fr/excluders.py,
ABBREVIATIONS); when the block holds nothing else, no sentence is left,
PaPie's padding calls `max()` on an empty list and raises
`ValueError: max() arg is an empty sequence`. The pipeline counted the
block in `containers_refused` and the run reported it as an incident
needing a human.

Two independent changes:

- `_finish_container` no longer returns on the first refused block. One
  block coming back 400 threw away every block of the container the
  service HAD answered -- a five-character reference could cost a Latin
  quotation and two French paragraphs. The refusal flags are counted once
  after the loop, because the report divides them by `containers_found`
  and they have to stay container counts, not block counts.

- `_prepare_container` does not send a block reduced to a lone
  abbreviation. There is no lemma to find in "Orat." or "Ibid.", so the
  request that provokes the 400 is not made at all. The guard is exact
  equality on the stripped block, not a "word then period" heuristic,
  which would have swallowed "Bonjour." as well.

Measured on the corpus, enrich phase only, against the live service:
LIV0020 went from "3 of 394 containers -- the service refused these" to
no incident, LIV0026c from 2 of 1687 to none, and PyHellen logged no 400
at all. The `containers unanchored` counts are untouched (5 and 48): that
guard is a deliberate decision, not a bug.

The upstream defect remains: "nothing to tag" is not a bad request, and
PyHellen should answer 200 with an empty token list rather than 400.
This change stops the pipeline from losing good blocks over it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@rayondemiel
rayondemiel merged commit 07981b1 into main Sep 21, 2026
1 check passed
rayondemiel added a commit that referenced this pull request Sep 21, 2026
Carries the fix from #40: a block refused by PyHellen no longer discards
the blocks the service did answer, and a lone abbreviation is not sent at
all. Patch release — no interface change, no output change (the
end-to-end golden diff is unchanged).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant