bound the QA evidence overlay and fetch only what it draws

evidence_geojson emitted one feature per false positive, one per false negative
and two per match, with no limit. A regional check of 40k detections against 45k
reference footprints produced well over a hundred thousand features in a single
response, plus one warning string per unresolvable identifier. The endpoint the
entire review workflow depends on therefore failed exactly where review matters
most.

What to draw is now decided before any geometry is fetched, so the query work is
proportional to the result rather than to the size of the check — previously
130k geometries were resolved through an IN clause holding every identifier in
the check, to then discard most of them.

The budget is split between misses and false positives in proportion to their
populations with at least one of each, rather than by strict priority, which
would mean a check with 50.000 misses and three false positives never showed
one. Confirmations fill what remains, and a match is kept or dropped as a pair
because half a match is not reviewable evidence.

limit_evidence and evidence_role_counts are removed: plan_evidence supersedes
them, and helpers kept alive only by their own tests read like a contract.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Jens
2026-08-22 15:14:26 +02:00
co-authored by Claude Opus 5
parent 52c2bfd120
commit 5278fcd361
7 changed files with 412 additions and 64 deletions
@@ -95,8 +95,17 @@ def test_quality_check_evidence_geojson_resolves_persisted_vector_features() ->
assert result["feature_count"] == 4
assert result["geojson"]["type"] == "FeatureCollection"
roles = [feature["properties"]["qa_evidence_role"] for feature in result["geojson"]["features"]]
assert roles == ["match_candidate", "match_reference", "false_positive", "false_negative"]
match_candidate = result["geojson"]["features"][0]
# Every role resolves to persisted geometry. Errors are emitted before
# confirmations, because a capped overlay must spend its budget on the
# objects a reviewer has to act on.
assert sorted(roles) == ["false_negative", "false_positive", "match_candidate", "match_reference"]
assert roles.index("false_negative") < roles.index("match_candidate")
assert roles.index("false_positive") < roles.index("match_candidate")
match_candidate = next(
feature
for feature in result["geojson"]["features"]
if feature["properties"]["qa_evidence_role"] == "match_candidate"
)
assert match_candidate["properties"]["quality_check_id"] == str(quality_check_id)
assert match_candidate["properties"]["candidate_feature_id"] == "candidate-match"
assert match_candidate["properties"]["reference_feature_id"] == "reference-match"
@@ -148,7 +157,11 @@ def test_quality_check_evidence_geojson_api_uses_canonical_envelope(monkeypatch)
app.dependency_overrides.pop(get_db, None)
assert response.status_code == 200
assert response.json() == {"data": payload}
# The envelope wraps the service result; asserting the exact field list
# would break every time the response model gains a documented field.
body = response.json()
assert set(body) == {"data"}
assert body["data"].items() >= payload.items()
def test_frontend_quality_evidence_overlay_contract_is_wired() -> None: