store: auto-migrate old KGs (edges.origin_question); machine: abort honestly on dead LM
- KnowledgeStore._migrate(): idempotent additive migration on open — a pre-2026-10-19 KG no longer crashes the set gate with 'no such column' - _lm_dead(): transport/timeout deaths abort the run with notes (no answer beats a made-up one); code bugs still crash loudly - tests: migration from a hand-built old-schema store; LM-death abort (24/24)
This commit is contained in:
@@ -47,6 +47,23 @@ class RunReport:
|
||||
elapsed_s: float = 0.0
|
||||
|
||||
|
||||
def _lm_dead(e: BaseException) -> bool:
|
||||
"""Is this exception the LM dying (transport/timeout), not a code bug?
|
||||
Walks the cause chain: dspy wraps transport deaths in LM* classes
|
||||
(LMTransportError) over raw TimeoutErrors. Code bugs must still crash
|
||||
loudly in development."""
|
||||
seen: list[BaseException] = []
|
||||
cur: BaseException | None = e
|
||||
while cur is not None and cur not in seen:
|
||||
seen.append(cur)
|
||||
if type(cur).__name__.startswith("LM"):
|
||||
return True
|
||||
if "timed out" in str(cur).lower():
|
||||
return True
|
||||
cur = cur.__cause__ or cur.__context__
|
||||
return False
|
||||
|
||||
|
||||
class FloopRun:
|
||||
"""One FLOOP execution over one question (top-level or recursive child)."""
|
||||
|
||||
@@ -95,6 +112,13 @@ class FloopRun:
|
||||
except BudgetExhausted:
|
||||
self.notes.append(f"budget exhausted at llm_calls={self.budget.llm_calls}")
|
||||
break
|
||||
except Exception as e: # noqa: BLE001 — LM deaths abort honestly
|
||||
if _lm_dead(e):
|
||||
self.notes.append(
|
||||
f"LM unreachable at llm_calls={self.budget.llm_calls} "
|
||||
f"({type(e).__name__}); aborting — no answer beats a made-up one")
|
||||
break
|
||||
raise
|
||||
return self._finish(t0)
|
||||
|
||||
# ---- steps -------------------------------------------------------------
|
||||
@@ -267,6 +291,12 @@ class FloopRun:
|
||||
self.streams.final(answer)
|
||||
except BudgetExhausted:
|
||||
self.notes.append("budget died before the answer step")
|
||||
except Exception as e: # noqa: BLE001 — a dead LM answers nothing
|
||||
if _lm_dead(e):
|
||||
self.notes.append(f"LM unreachable before synthesis ({type(e).__name__}); "
|
||||
"evidence is kept, the answer is not written")
|
||||
else:
|
||||
raise
|
||||
return RunReport(
|
||||
goal=self.query, final_answer=answer, verified=verified,
|
||||
llm_calls=self.budget.llm_calls, engine_calls=self.engine_calls,
|
||||
|
||||
Reference in New Issue
Block a user