commit 141843ff80d9d8ebab547b32ee795ef491744c1c
parent 1a3d20f47e13f01441f9b7375862603c71fff4c1
Author: triesap <tyson@radroots.org>
Date: Mon, 21 Sep 2026 13:52:09 +0000
core: handle buyer interpretation failures safely
Diffstat:
2 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/src/hyf_application/buyer_failure.mojo b/src/hyf_application/buyer_failure.mojo
@@ -0,0 +1,28 @@
+
+
+@fieldwise_init
+struct BuyerInferenceOutcome(Copyable, Movable):
+ var status: String
+ var resolved_lines: Int
+ var unresolved_lines: Int
+ var reason: String
+
+
+def buyer_inference_failure(reason: String) raises -> BuyerInferenceOutcome:
+ if String(reason).strip().byte_length() == 0:
+ raise Error("buyer inference failure requires a reason")
+ return BuyerInferenceOutcome(
+ status="failed", resolved_lines=0, unresolved_lines=1, reason=String(reason)
+ )
+
+
+def buyer_inference_degraded(reason: String) raises -> BuyerInferenceOutcome:
+ if String(reason).strip().byte_length() == 0:
+ raise Error("buyer inference degradation requires a reason")
+ return BuyerInferenceOutcome(
+ status="degraded", resolved_lines=0, unresolved_lines=1, reason=String(reason)
+ )
+
+
+def buyer_failure_means_unavailable_supply() -> Bool:
+ return False
diff --git a/tests/test_application.mojo b/tests/test_application.mojo
@@ -313,3 +313,19 @@ def test_assemble_reviewable_typed_buyer_need() raises:
_ = assemble_buyer_need(
List[DemandLine](), review_clear(), execution_meta("complete", 0, None, None, None)
)
+
+
+from hyf_application.buyer_failure import (
+ buyer_failure_means_unavailable_supply,
+ buyer_inference_degraded,
+ buyer_inference_failure,
+)
+
+
+def test_buyer_inference_failure_is_not_market_absence() raises:
+ var failed = buyer_inference_failure("provider_timeout")
+ assert_equal(failed.status, "failed")
+ assert_equal(failed.resolved_lines, 0)
+ var degraded = buyer_inference_degraded("provider_degraded")
+ assert_equal(degraded.status, "degraded")
+ assert_true(not buyer_failure_means_unavailable_supply())