EmmaScharfmann HF Staff commited on
Commit
f0ce0fa
·
1 Parent(s): 9d69640

fix backend bug

Browse files
Files changed (2) hide show
  1. app.py +14 -1
  2. static/index.html +9 -2
app.py CHANGED
@@ -887,7 +887,20 @@ async def meccog_results() -> dict[str, Any]:
887
 
888
  if isinstance(results_resp, Exception) or not results_resp.is_success:
889
  err = str(results_resp) if isinstance(results_resp, Exception) else results_resp.text[:200]
890
- raise HTTPException(502, f"Backend API error: {err}")
 
 
 
 
 
 
 
 
 
 
 
 
 
891
 
892
  results_raw: list[dict] = results_resp.json().get("items", [])
893
  lb_rows: list[dict] = (
 
887
 
888
  if isinstance(results_resp, Exception) or not results_resp.is_success:
889
  err = str(results_resp) if isinstance(results_resp, Exception) else results_resp.text[:200]
890
+ log.warning("Backend API error on /v1/results: %s", err)
891
+ # The bucket-sync API is a separate service and can be briefly down or
892
+ # slow to wake — degrade to the last known-good payload rather than
893
+ # taking the whole Results tab down with a 502, mirroring how
894
+ # _SingleFlightCache serves stale data for /api/messages etc.
895
+ if _meccog_cache["data"] is not None:
896
+ stale = dict(_meccog_cache["data"])
897
+ stale["error"] = f"Backend API error (showing cached data): {err}"
898
+ return stale
899
+ return {
900
+ "results": [], "leaderboard": [], "coverage": {},
901
+ "consensus": {}, "hyp_order": HYP_ORDER, "hypotheses": HYPOTHESES,
902
+ "fetched_at": "", "error": f"Backend API error: {err}",
903
+ }
904
 
905
  results_raw: list[dict] = results_resp.json().get("items", [])
906
  lb_rows: list[dict] = (
static/index.html CHANGED
@@ -3454,12 +3454,19 @@ function renderMeccogTab(d) {
3454
  if (!d) return;
3455
  const { coverage, consensus, results, agents, hyp_order, hypotheses, fetched_at, error } = d;
3456
 
3457
- if (error) {
 
 
 
 
 
3458
  meccogStatus.textContent = 'not configured';
3459
  hypGridEl.innerHTML = `<div class="mc-empty" style="grid-column:1/-1">${escapeHtml(error)}</div>`;
3460
  return;
3461
  }
3462
- meccogStatus.textContent = fetched_at ? `updated ${fetched_at}` : '';
 
 
3463
 
3464
  // Populate the submission activity chart on the leaderboard tab.
3465
  if (results?.length) renderSubmissionsChart(results);
 
3454
  if (!d) return;
3455
  const { coverage, consensus, results, agents, hyp_order, hypotheses, fetched_at, error } = d;
3456
 
3457
+ // An `error` alongside empty data means there's nothing to show (e.g.
3458
+ // BACKEND_API_URL unset, or the very first fetch failed with no cache
3459
+ // yet to fall back to). An `error` alongside populated data means the
3460
+ // backend is having trouble but we're showing the last known-good
3461
+ // snapshot — render it rather than blanking the tab.
3462
+ if (error && !results?.length && !hyp_order?.length) {
3463
  meccogStatus.textContent = 'not configured';
3464
  hypGridEl.innerHTML = `<div class="mc-empty" style="grid-column:1/-1">${escapeHtml(error)}</div>`;
3465
  return;
3466
  }
3467
+ meccogStatus.textContent = error
3468
+ ? `⚠ ${error}`
3469
+ : (fetched_at ? `updated ${fetched_at}` : '');
3470
 
3471
  // Populate the submission activity chart on the leaderboard tab.
3472
  if (results?.length) renderSubmissionsChart(results);