Skip to content

Commit abad999

Browse files
Zaid Salemclaude
authored andcommitted
fix(route): KB overrides Valhalla only on human-verified corridors
Confidence gate in kb_service: serve the KB route only when it contains at least one human_local (ground-truth) edge. Pure model_inferred scaffold corridors fall back to Valhalla (richer geometry + OCHA restriction layer) until confirmed via the worklist. Verified Ramallah<->Nablus stays on wbkb; e.g. Bethlehem<->Hebron falls back until verified. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a9e1f68 commit abad999

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

services/westbank-alerts/app/routing/kb_service.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ def _shape(res: dict, nodes: dict) -> dict:
145145
}
146146

147147

148+
def _has_verified_edge(res: dict, edges: dict) -> bool:
149+
for leg in res.get("edges", []):
150+
e = edges.get(leg["id"])
151+
if not e:
152+
continue
153+
for slot in ("permission", "road_exists"):
154+
if (e["facts"].get(slot) or {}).get("source") == "human_local":
155+
return True
156+
return False
157+
158+
148159
def plan(from_latlon: tuple[float, float], to_latlon: tuple[float, float], envelopes: list) -> dict | None:
149160
"""Try a KB route. Returns the /v2/route plan dict, or None to fall back."""
150161
if not _AVAILABLE:
@@ -161,6 +172,12 @@ def plan(from_latlon: tuple[float, float], to_latlon: tuple[float, float], envel
161172
res = kbrouter.route(nodes, edges, src, dst, _status_map(envelopes))
162173
if not res.get("found"):
163174
return None
175+
# Confidence gate: only let the KB override Valhalla on a route that has at
176+
# least one human-verified (ground-truth) edge. Pure model_inferred scaffold
177+
# corridors fall back to Valhalla (richer geometry + OCHA restriction layer)
178+
# until they're confirmed via the worklist.
179+
if not _has_verified_edge(res, edges):
180+
return None
164181
assert_safe(res, edges) # never return a forbidden route
165182
return _shape(res, nodes)
166183
except Exception: # noqa: BLE001 — any failure → Valhalla fallback

0 commit comments

Comments
 (0)