From bc191fb59f1355aaf3725b6d226365c2b2434fc7 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Tue, 18 Aug 2026 22:03:17 -0400 Subject: [PATCH] Stop one malformed call document 500ing the whole debug view /admin/debug/correlation built its call lookup as {doc["call_id"]: doc}, which raises KeyError on any stored call missing that field -- and at least one in production is missing it. One bad document took down the entire view rather than dropping a single call from it. The document id is authoritative and always present; the call_id *field* is written by the upload path and evidently has not always been. Keying off the id we asked for removes the dependency on the field entirely. Found while generating a correlation dump server-side, because the UI route this serves has been unusable tonight. Co-Authored-By: Claude Opus 5 --- drb-c2-core/app/routers/admin.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drb-c2-core/app/routers/admin.py b/drb-c2-core/app/routers/admin.py index 21df096..2291044 100644 --- a/drb-c2-core/app/routers/admin.py +++ b/drb-c2-core/app/routers/admin.py @@ -129,7 +129,14 @@ async def debug_correlation( unique_call_ids = list(dict.fromkeys(all_call_ids)) # dedupe, preserve order call_docs = await asyncio.gather(*(fstore.doc_get("calls", cid) for cid in unique_call_ids)) - call_map: dict[str, dict] = {doc["call_id"]: doc for doc in call_docs if doc} + # Key off the id we asked for, not doc["call_id"]. At least one stored call + # has no call_id field -- the document id is authoritative and always + # present, while the field is written by the upload path and evidently was + # not always there. Indexing the field raised KeyError and took the whole + # debug view down with a 500 over a single malformed document. + call_map: dict[str, dict] = { + cid: doc for cid, doc in zip(unique_call_ids, call_docs) if doc + } # ── Build incident debug records ────────────────────────────────────────── incident_records = []