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

fix(latency): KI-100 — outer wait_for(25s) around drive_fact_find

Browse files

Live smoke-test post-KI-099 caught T6 at 41.83s with brain_tag
`fact_find_brain::fallback:timeout_after_escalation`. The fact-find brain
at orchestrator.py:401 was outside KI-099's scope (which targeted lines
549 / 639 / 684). Its internal KI-079 escalation (FAST 25s + BRAIN 15s)
sequentially compounded to 40s on doubly-saturated chains.

Wrap drive_fact_find in asyncio.wait_for(timeout=25.0). On outer timeout,
fall through to _canonical_fallback with reason="outer_timeout_25s" so the
user still gets a coherent next-question prompt while the chain recovers.

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

Files changed (1) hide show
  1. backend/orchestrator.py +27 -6
backend/orchestrator.py CHANGED
@@ -400,12 +400,33 @@ async def handle_turn(
400
  drive_fact_find,
401
  )
402
 
403
- outcome = await drive_fact_find(
404
- user_text=user_text,
405
- session=session,
406
- chat_history=chat_history,
407
- session_id=session_id,
408
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
 
410
  # Apply captured updates to profile + mark matching slot ids as asked
411
  # so the orchestrator's downstream `next_question` (used in the
 
400
  drive_fact_find,
401
  )
402
 
403
+ # KI-100 bound drive_fact_find at the orchestrator. KI-079's
404
+ # internal FAST(25s) + BRAIN(15s) escalation can compound to ~40s on
405
+ # a doubly-saturated chain, which breaches the user's <30s per-turn
406
+ # target. Cap at 25s; on outer timeout, fall through to the
407
+ # canonical fallback that drive_fact_find itself uses on internal
408
+ # timeout (build the outcome from current session state).
409
+ try:
410
+ outcome = await asyncio.wait_for(
411
+ drive_fact_find(
412
+ user_text=user_text,
413
+ session=session,
414
+ chat_history=chat_history,
415
+ session_id=session_id,
416
+ ),
417
+ timeout=25.0,
418
+ )
419
+ except asyncio.TimeoutError:
420
+ logging.warning(
421
+ "fact_find_brain outer wait_for(25s) tripped — falling back to canonical (session=%s)",
422
+ session_id,
423
+ )
424
+ from backend.fact_find_brain import _canonical_fallback
425
+ outcome = _canonical_fallback(
426
+ session=session,
427
+ user_text=user_text,
428
+ reason="outer_timeout_25s",
429
+ )
430
 
431
  # Apply captured updates to profile + mark matching slot ids as asked
432
  # so the orchestrator's downstream `next_question` (used in the