fix(ingest): address review round 2 (Literal reason + exhaustive branch + test)

- escalation: EscalationDecision.reason is now Literal["empty_text",
  "low_confidence"] (parity with kind; ty catches a bad label at call sites).
- processor: nest the decision handling so the hop branch is reached via an
  explicit else under `if decision is not None` — exhaustive over the Literal
  kind, no None-attribute risk.
- tests: add the "OCR processor unregistered (not just disabled) → None"
  quadrant, locking in absent != suppressed.

Deck #324.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-13 15:24:55 +02:00
co-authored by Claude Opus 4.8
parent f8e8645fc2
commit c0fd7dd67b
3 changed files with 46 additions and 28 deletions
@@ -49,7 +49,7 @@ class EscalationDecision:
kind: Literal["hop", "suppressed"]
to_tier: str
reason: str # empty_text | low_confidence
reason: Literal["empty_text", "low_confidence"]
def next_tier(current: str) -> str | None:
+29 -27
View File
@@ -157,33 +157,35 @@ async def _parse_pdf_tier(
decision = registry.evaluate_escalation(
result, content, tier, settings, filename=filename
)
if decision is not None and decision.kind == "suppressed":
# The ideal next tier (e.g. ocr) is disabled, so we do NOT hop: index
# this tier's output as terminal and record the would-be escalation
# so operators see the latent demand ("what-if OCR enabled"; #324).
record_document_escalation_suppressed(
tier, decision.to_tier, decision.reason
)
logger.info(
"Escalation suppressed for %s: %s->%s disabled (reason=%s), "
"indexing at current tier",
filename or "<bytes>",
tier,
decision.to_tier,
decision.reason,
)
elif decision is not None:
record_document_escalation(tier, decision.to_tier, decision.reason)
logger.info(
"Escalating %s %s->%s (reason=%s)",
filename or "<bytes>",
tier,
decision.to_tier,
decision.reason,
)
raise EscalateError(
from_tier=tier, to_tier=decision.to_tier, reason=decision.reason
)
if decision is not None:
if decision.kind == "suppressed":
# The ideal next tier (e.g. ocr) is disabled, so we do NOT hop:
# index this tier's output as terminal and record the would-be
# escalation so operators see the latent demand ("what-if OCR
# enabled"; #324).
record_document_escalation_suppressed(
tier, decision.to_tier, decision.reason
)
logger.info(
"Escalation suppressed for %s: %s->%s disabled (reason=%s), "
"indexing at current tier",
filename or "<bytes>",
tier,
decision.to_tier,
decision.reason,
)
else: # "hop" — the Literal kind makes this branch exhaustive.
record_document_escalation(tier, decision.to_tier, decision.reason)
logger.info(
"Escalating %s %s->%s (reason=%s)",
filename or "<bytes>",
tier,
decision.to_tier,
decision.reason,
)
raise EscalateError(
from_tier=tier, to_tier=decision.to_tier, reason=decision.reason
)
return result