starfriend commited on
Commit
809af9d
·
verified ·
1 Parent(s): 344a441

Upload research_fallback.py

Browse files
Files changed (1) hide show
  1. backend/research_fallback.py +19 -0
backend/research_fallback.py CHANGED
@@ -6,6 +6,8 @@ circuit breaker is active); never changes retrieval or media analysis.
6
  from __future__ import annotations
7
 
8
  import os
 
 
9
  import threading
10
  import time
11
 
@@ -25,6 +27,23 @@ def is_infrastructure_error(exc: Exception) -> bool:
25
  return any(signal in text for signal in signals)
26
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def llama_circuit_open() -> bool:
29
  with _LOCK:
30
  return time.monotonic() < _UNAVAILABLE_UNTIL
 
6
  from __future__ import annotations
7
 
8
  import os
9
+ import json
10
+ import logging
11
  import threading
12
  import time
13
 
 
27
  return any(signal in text for signal in signals)
28
 
29
 
30
+
31
+ def is_gradio_transport_json_error(exc: Exception) -> bool:
32
+ """Classify only malformed JSON returned while contacting the Llama Space.
33
+
34
+ Never treat JSON parsing failures in publication retrieval or our own
35
+ application data as an infrastructure outage.
36
+ """
37
+ if not isinstance(exc, json.JSONDecodeError):
38
+ return False
39
+ tb = exc.__traceback__
40
+ while tb is not None:
41
+ module = str(tb.tb_frame.f_globals.get("__name__", ""))
42
+ if module == "gradio_client" or module.startswith("gradio_client."):
43
+ return True
44
+ tb = tb.tb_next
45
+ return False
46
+
47
  def llama_circuit_open() -> bool:
48
  with _LOCK:
49
  return time.monotonic() < _UNAVAILABLE_UNTIL