rohitsar567 Claude Opus 4.7 (1M context) commited on
Commit
66eb4ed
·
1 Parent(s): 55c83b9

fix(orchestrator): KI-101 — drop function-local 'import logging' to fix UnboundLocalError

Browse files

KI-099a added module-level `import logging`, but several legacy function-
local `import logging` lines (from KI-005/006/091 handlers) caused Python
to treat 'logging' as a local in handle_turn. When the wait_for TimeoutError
branch fired BEFORE the function-local import statement, 'logging' was
unbound and the orchestrator raised HTTP 500. Caught live by the 15-persona
smoke test (B5 T8 'Mild asthma, controlled').

Delete every function-local import; rely on the single module-level one.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. backend/orchestrator.py +0 -6
backend/orchestrator.py CHANGED
@@ -285,7 +285,6 @@ async def handle_turn(
285
  # KI-004 — surface translator failures in HF Space logs. The
286
  # brain will still try with the original Indic text, but with
287
  # degraded quality. The log lets us tune the Sarvam fallback.
288
- import logging
289
  logging.warning(
290
  "indic translator failed (session=%s lang=%s): %s: %s",
291
  session_id, language, type(e).__name__, str(e)[:200],
@@ -479,7 +478,6 @@ async def handle_turn(
479
  "health_conditions": p.health_conditions,
480
  })
481
  except Exception as e:
482
- import logging
483
  logging.warning(
484
  "fact_find_brain profile-chunk upsert failed (session=%s): %s: %s",
485
  session_id, type(e).__name__, str(e)[:200],
@@ -627,7 +625,6 @@ async def handle_turn(
627
  # KI-005 — log profile-chunk upsert failures so we can see
628
  # when Chroma is locking or schema-drifting. The chat still
629
  # ships; subsequent turns just won't see the latest profile.
630
- import logging
631
  logging.warning(
632
  "profile-chunk upsert failed (session=%s): %s: %s",
633
  session_id, type(e).__name__, str(e)[:200],
@@ -642,7 +639,6 @@ async def handle_turn(
642
  except Exception as e:
643
  # KI-006 — log profile-extraction failures (extractor LLM down,
644
  # malformed model output, etc.). The chat ships unaffected.
645
- import logging
646
  logging.warning(
647
  "profile extractor failed (session=%s): %s: %s",
648
  session_id, type(e).__name__, str(e)[:200],
@@ -864,7 +860,6 @@ async def handle_turn(
864
  reason="shown_in_recommendation",
865
  )
866
  except Exception as inner:
867
- import logging
868
  logging.warning(
869
  "KI-063 shown_policies log failed (session=%s): %s: %s",
870
  session_id, type(inner).__name__, str(inner)[:200],
@@ -875,7 +870,6 @@ async def handle_turn(
875
  _asyncio.create_task(_asyncio.to_thread(_log_shown_policies))
876
  except Exception as e:
877
  # Never let logging failures break the chat reply.
878
- import logging
879
  logging.warning(
880
  "KI-063 shown_policies scheduling failed (session=%s): %s: %s",
881
  session_id, type(e).__name__, str(e)[:200],
 
285
  # KI-004 — surface translator failures in HF Space logs. The
286
  # brain will still try with the original Indic text, but with
287
  # degraded quality. The log lets us tune the Sarvam fallback.
 
288
  logging.warning(
289
  "indic translator failed (session=%s lang=%s): %s: %s",
290
  session_id, language, type(e).__name__, str(e)[:200],
 
478
  "health_conditions": p.health_conditions,
479
  })
480
  except Exception as e:
 
481
  logging.warning(
482
  "fact_find_brain profile-chunk upsert failed (session=%s): %s: %s",
483
  session_id, type(e).__name__, str(e)[:200],
 
625
  # KI-005 — log profile-chunk upsert failures so we can see
626
  # when Chroma is locking or schema-drifting. The chat still
627
  # ships; subsequent turns just won't see the latest profile.
 
628
  logging.warning(
629
  "profile-chunk upsert failed (session=%s): %s: %s",
630
  session_id, type(e).__name__, str(e)[:200],
 
639
  except Exception as e:
640
  # KI-006 — log profile-extraction failures (extractor LLM down,
641
  # malformed model output, etc.). The chat ships unaffected.
 
642
  logging.warning(
643
  "profile extractor failed (session=%s): %s: %s",
644
  session_id, type(e).__name__, str(e)[:200],
 
860
  reason="shown_in_recommendation",
861
  )
862
  except Exception as inner:
 
863
  logging.warning(
864
  "KI-063 shown_policies log failed (session=%s): %s: %s",
865
  session_id, type(inner).__name__, str(inner)[:200],
 
870
  _asyncio.create_task(_asyncio.to_thread(_log_shown_policies))
871
  except Exception as e:
872
  # Never let logging failures break the chat reply.
 
873
  logging.warning(
874
  "KI-063 shown_policies scheduling failed (session=%s): %s: %s",
875
  session_id, type(e).__name__, str(e)[:200],