fix(estimator): ghost-anchor — confidence='low' when radius analogs empty (#1871) #1920

Merged
bot-backend merged 1 commit from fix/1871-ghost-anchor-confidence-guard into main 2026-06-26 16:07:12 +00:00

1 commit

Author SHA1 Message Date
99736b6e32 fix(estimator): ghost-anchor — confidence='low' when radius analogs empty (#1871)
All checks were successful
CI / changes (pull_request) Successful in 6s
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped
#1871 P1 (Ghost-anchor) trust defect: when the same-building anchor
replaces the headline estimate, the code sets confidence = anchor["confidence"]
and overwrites n_analogs = anchor["n"] (>0). With ZERO radius analogs
(listings_clean == []) this yielded confidence='high'/'medium' on an
estimate built only on same-building comps (sometimes a single
yandex_valuation, e.g. median 38.4M) with no comparable nearby listings.

The defensive guard _enforce_zero_analog_low only fires on n_analogs == 0,
but n_analogs was already overwritten to anchor["n"] (>0) — so it never
caught this path. UI rendered "Высокая · 0 объектов" = fabricated confidence.

Fix: inline guard inside the `if anchor is not None:` block, right after
n_analogs = anchor["n"]. When listings_clean is empty and confidence != 'low',
downgrade to 'low', log a warning, and append an honest caveat to explanation.
Sits before _enforce_zero_analog_low and before the result is finalized, so the
downgraded confidence + caveat propagate to the response.

Test: tests/test_estimator_ghost_anchor_radius_empty_1871.py exercises the
full estimate path (via the test_same_building_anchor harness) with a
tight-spread anchor (n=5, would be 'high') and empty radius → asserts
confidence='low' + caveat present; plus a control that a non-empty radius is
not downgraded.
2026-06-26 21:01:34 +05:00