Skip to content

Add Stage D fallback channel calculator (pre-fire prep) - #341

Merged
WilfordGrimley merged 2 commits into
masterfrom
stage-d-prefire-prep
Jul 23, 2026
Merged

Add Stage D fallback channel calculator (pre-fire prep)#341
WilfordGrimley merged 2 commits into
masterfrom
stage-d-prefire-prep

Conversation

@WilfordGrimley

@WilfordGrimley WilfordGrimley commented Jul 22, 2026

Copy link
Copy Markdown

Description

Pre-fire prep for the full-catalog Stage D fire (code only — this PR does not run the fire, the targeted re-extraction of #340's 373-card cohort, or any other prod extraction/write; both remain separate owner-gated prod steps, see docs/pipeline-fidelity-gate.md).

Fallback channel calculator (calculate_fallback_verdict/run_fallback_calculator, own anonymous_id="stage-d-fallback-v1"): Stage D's own port of local_fallback.py's pilot "Pass 2" border/artist/symbol evidence-combination model, run only over cards the join-key calculator already found no confident hit for. Unlike the pilot's own live-image version, this operates entirely off already-persisted ImageEvidence fields:

  • border: evidence.layout_classlocal_fallback.filter_by_border_color (PROTECTED CORE, called not modified)
  • artist: evidence.artist_ocr_namelocal_fallback.match_artist (PROTECTED CORE, called not modified)
  • symbol: evidence.symbol_phash → new _filter_by_symbol_phash, which calls local_fallback.render_set_symbol (PROTECTED CORE) and reimplements only the Hamming-distance arithmetic — the same pattern _symbol_phash_tiebreak already established for the join-key calculator, duplicated rather than shared since the two return different shapes (see that function's own docstring).

A vote is cast only when the intersection across every sub-check that produced a reading narrows to exactly one candidate — local_fallback.py's own documented rule, reproduced exactly, with no added agreement/corroboration layer (that layer doesn't exist in local_fallback.py, so this is a faithful port, not an augmented one). source=VoteSource.OCR (not DEDUCTION) — VoteSource's own docstring explicitly names "the border/artist/symbol evidence-combination fallback" as part of OCR's umbrella, not deductive_backfill's zero-image-inspection deduction.

Wired into the management command between the join-key and slow-path calculators (own verify_zero_resolutions gate check, same as join-key's), and _slow_path_eligible_cards_queryset now also excludes any card this calculator successfully voted on, so a card it resolves isn't also routed to human review in the same invocation.

Revision (2026-07-22): an earlier revision of this PR also added a .exclude(printing_tags__source=VoteSource.DEDUCTION) clause to the shared eligibility queryset ("constant #3" from the pipeline-fidelity gate's knowledge-inventory sweep — the pilot never re-voted a card the 2026-07-14 deductive backfill had already voted for). Owner ruled this OUT after a read-only investigation: that backfill is pure name/metadata deduction (never phash/OCR), its votes are sound (15-card sample all correct), and excluding those cards would strand ~27,819 sound-but-UNRESOLVED cards outside Stage D for no protective benefit — re-evaluating them is safe under the human-backed consensus gate (agreement dedups, disagreement surfaces to human review). The pilot's own exclusion was a performance optimization, not a soundness mechanism. That clause and its tests have been removed; the pre-existing per-calculator stable-anonymous_id idempotence exclusion (independent mechanism) is untouched. This PR is now fallback-calculator-only.

Constants #1 (RESOLUTION_FLOOR_DPI) and #2 (EXCLUDED_RESOLVED_TAGS) remain out of scope — their forward-impact sizing is still open per the gate page.

Protected core imported/called, never touched: local_fallback.filter_by_border_color, match_artist, render_set_symbol, SYMBOL_DISTANCE_THRESHOLD, SYMBOL_MARGIN, FALLBACK_CONFIDENCE_MULTI_EVIDENCE, FALLBACK_CONFIDENCE_SINGLE_EVIDENCE. local_fallback.py itself has zero diff in this PR.

Docs updated in the same PR: docs/features/catalog-completion-plan.md (Stage D "Pre-fire prep" entry, revised to record the constant-#3 non-restoration), docs/pipeline-fidelity-gate.md §3 (item 3 reframed as "intentionally not restored" with the owner-ruling rationale), docs/reports/2026-07-22-knowledge-inventory.md (constant-#3 row updated to match). No wiki update needed (backend-only, no user/admin-facing surface change) and no extractable-primitives.md row (hard dependency on resolve_and_persist_printing/CardPrintingTag, not a clean primitive).

Checklist

  • I have installed pre-commit and installed the hooks with pre-commit install before creating any commits.
  • I have updated any related tests for code I modified or added new tests where appropriate.
  • I have manually tested my changes as follows:
    • Ran the full backend suite from the pre-provisioned host venv (/home/ubuntu/.venvs/mpcautofill-pilot) against the live Postgres/ES containers' exposed ports (pytest-django's own ephemeral test DB, no prod read/write): 1642 passed, 4 skipped (the same CI-documented named skips), 0 failed.
    • mypy --config-file mypy.ini clean on both changed source files.
    • pre-commit run (ruff/isort/black/mypy/prettier) clean on every changed file.
    • makemigrations not applicable — zero model changes (confirmed models.py has no diff in this PR).
    • docs_lint.py clean.
    • Idempotence re-verified WITHOUT constant Simplify flag icons: static SVG assets instead of hand-rolled geometry #3: TestRunJoinKeyCalculator/TestRunSlowPathCalculator/TestRunFallbackCalculator's own test_idempotent_against_its_own_anonymous_id all still pass — idempotence comes entirely from the stable per-calculator anonymous_id exclusion, independent of constant Simplify flag icons: static SVG assets instead of hand-rolled geometry #3.
  • I have updated any relevant documentation or created new documentation where appropriate.

…n guard

Pre-fire prep (owner-bundled ahead of the full-catalog Stage D fire, code
only): ports local_fallback.py's border/artist/symbol evidence-combination
model to Stage D (calculate_fallback_verdict/run_fallback_calculator, own
anonymous_id) for cards the join-key calculator found no confident hit for,
and adds the missing deductive-backfill exclusion (constant #3 from the
pipeline-fidelity gate) to the shared eligible-cards queryset so a repeated
Stage D fire never re-votes a card the backfill already covered.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Owner ruled: the 2026-07-14 backfill is pure name/metadata deduction with
sound votes (15-card sample all correct); excluding those cards would
strand ~27,819 sound-but-UNRESOLVED cards for no protective benefit, since
the human-backed consensus gate already makes re-evaluation safe. Removes
the .exclude(printing_tags__source=VoteSource.DEDUCTION) clause and its
tests; the pre-existing stable-anonymous_id idempotence exclusion is
untouched. Fallback channel calculator unchanged. Docs reframed to record
this as an intentional non-restoration, not a gap.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@WilfordGrimley WilfordGrimley changed the title Stage D fallback channel calculator + deductive-backfill exclusion guard Add Stage D fallback channel calculator (pre-fire prep) Jul 22, 2026
@WilfordGrimley
WilfordGrimley merged commit 7936a3b into master Jul 23, 2026
6 checks passed
WilfordGrimley added a commit that referenced this pull request Jul 23, 2026
WilfordGrimley added a commit that referenced this pull request Jul 23, 2026
* Ratify artifact-1 parity-replay outcome (issue #154)

* Rebase onto #341, record constants #1/#2 must-fix ruling, clarify cross-method replay baseline
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