Spaces:
Sleeping
fix(upload-extract): status completeness now matches scorecard endpoint
Browse filesBug: /api/upload/extraction-status reported data_completeness_pct off
build_scorecard(policy.model_dump(), profile=None) β no insurer_reviews
arg. /api/policies/{id}/scorecard reads the SAME extracted JSON but
ALSO passes insurer_reviews loaded off insurer_slug, so the Claim
Experience sub-score (and downstream data_completeness accounting)
diverged between the two endpoints.
On the 2026-05-27 proof upload (Sarvah Param β manipalcigna) this surfaced
as status=17.4% while the card endpoint served 52.2%, looking exactly
like a merge regression even though the merge was working correctly.
Fix: mirror the scorecard endpoint's exact path inside the status
resolver β load EXTRACTED_DIR/<pid>.json (the freshly-written LLM JSON),
load insurer_reviews off the resolved insurer_slug, call
build_scorecard(policy, insurer_reviews=ir, profile=None). Completeness
and grade on the status endpoint now equal what the card renders, by
construction.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- backend/uploaded_docs.py +24 -7
|
@@ -1145,20 +1145,37 @@ async def extract_one_for_upload(
|
|
| 1145 |
policy_id, getattr(policy, "extraction_confidence_pct", "n/a"),
|
| 1146 |
)
|
| 1147 |
|
| 1148 |
-
# Resolve the freshly-graded card so the status can report
|
| 1149 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1150 |
_final_completeness = None
|
| 1151 |
_final_grade = None
|
| 1152 |
try:
|
| 1153 |
-
import backend.main as _bm2
|
| 1154 |
from backend.scorecard import build_scorecard as _bs
|
| 1155 |
-
|
| 1156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1157 |
if _sc is not None:
|
| 1158 |
_final_completeness = float(_sc.data_completeness_pct)
|
| 1159 |
_final_grade = _sc.overall_grade
|
| 1160 |
-
except Exception: # noqa: BLE001
|
| 1161 |
-
|
|
|
|
|
|
|
|
|
|
| 1162 |
|
| 1163 |
await _set_extraction_status(
|
| 1164 |
policy_id, status="complete",
|
|
|
|
| 1145 |
policy_id, getattr(policy, "extraction_confidence_pct", "n/a"),
|
| 1146 |
)
|
| 1147 |
|
| 1148 |
+
# Resolve the freshly-graded card so the status can report the
|
| 1149 |
+
# actual completeness + grade the CHAT CARD will show. Mirror
|
| 1150 |
+
# the /api/policies/{id}/scorecard endpoint's resolution path
|
| 1151 |
+
# byte-for-byte: load the same EXTRACTED_DIR/<pid>.json we just
|
| 1152 |
+
# wrote AND pass the same insurer_reviews. Without the reviews
|
| 1153 |
+
# arg the Claim Experience sub-score (and downstream completeness
|
| 1154 |
+
# accounting) diverges from what the card endpoint serves β that
|
| 1155 |
+
# was the 2026-05-27 "17.4% status vs 52.2% card" false-regression
|
| 1156 |
+
# the operator saw on the proof upload.
|
| 1157 |
_final_completeness = None
|
| 1158 |
_final_grade = None
|
| 1159 |
try:
|
|
|
|
| 1160 |
from backend.scorecard import build_scorecard as _bs
|
| 1161 |
+
_doc_for_sc = json.loads(out_json.read_text())
|
| 1162 |
+
_ir = None
|
| 1163 |
+
if insurer_slug:
|
| 1164 |
+
_rp = _settings.DATA_DIR / "reviews" / f"{insurer_slug}.json"
|
| 1165 |
+
if _rp.exists():
|
| 1166 |
+
try:
|
| 1167 |
+
_ir = json.loads(_rp.read_text())
|
| 1168 |
+
except Exception:
|
| 1169 |
+
_ir = None
|
| 1170 |
+
_sc = _bs(_doc_for_sc, insurer_reviews=_ir, profile=None)
|
| 1171 |
if _sc is not None:
|
| 1172 |
_final_completeness = float(_sc.data_completeness_pct)
|
| 1173 |
_final_grade = _sc.overall_grade
|
| 1174 |
+
except Exception as _sc_err: # noqa: BLE001
|
| 1175 |
+
_log.warning(
|
| 1176 |
+
"[upload-extract] status-card resolve failed for %s: %s: %s",
|
| 1177 |
+
policy_id, type(_sc_err).__name__, str(_sc_err)[:160],
|
| 1178 |
+
)
|
| 1179 |
|
| 1180 |
await _set_extraction_status(
|
| 1181 |
policy_id, status="complete",
|