mixle.fault module¶
Degradation policy with named failure modes for receipts.
Subsystem failures should not silently serve degraded answers as ordinary
successes. with_fallback() runs a primary path and, on exception, runs a
named fallback. The result records whether the primary path succeeded or which
degradation mode produced the fallback value. abstain_on_timeout() and
route_past() apply the same receipt discipline to timeout abstention and
multi-tier routing.
The named modes are teacher_down (fall back to captured or store-only
reasoning; see mixle.system.System.answer()), store_down (reason
without accumulated knowledge; see mixle.system.System.ingest()),
oracle_timeout (abstain or escalate rather than guess), and model_error
(route past the failing tier to the next one). The timeout and routing helpers
are reusable fault-boundary primitives.
- class DegradedResult(value, degraded, mode=None, reason=None)[source]
Bases:
objectThe outcome of a fault-boundary call: a value, whether it came from a fallback, and, if so, why.
- with_fallback(fn, fallback, *, mode)[source]
Run
fn(); on any exception, runfallback(exc)instead and flag the result undermode.If
fallbackitself raises, that exception propagates. A fallback that cannot produce a value is a real failure, not a second implicit fallback.
- abstain_on_timeout(fn, *, timeout_error=TimeoutError)[source]
oracle_timeoutmode: runfn(); if it raisestimeout_error, abstain (value=None) rather than guess. Other exceptions propagate.- Parameters:
timeout_error (type[BaseException])
- Return type:
DegradedResult
- route_past(tiers, *, names=None)[source]
model_errormode: try each tier in order; a raising tier is skipped (not fatal) in favor of the next. The result is degraded unless the first tier answers cleanly. Raises the last tier’s exception if every tier fails.