From 7b08df3bdbc8c96a97f64740183b9f6ffd260f44 Mon Sep 17 00:00:00 2001 From: ogt Date: Fri, 10 Jul 2026 21:51:20 +0800 Subject: [PATCH] fix(agent): accept JSON null pre-decision evidence --- apps/api/src/jobs/awooop_ansible_candidate_backfill_job.py | 5 ++++- apps/api/src/services/awooop_ansible_check_mode_service.py | 6 +++++- .../api/tests/test_awooop_ansible_candidate_backfill_job.py | 1 + apps/api/tests/test_awooop_truth_chain_service.py | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/api/src/jobs/awooop_ansible_candidate_backfill_job.py b/apps/api/src/jobs/awooop_ansible_candidate_backfill_job.py index bc2966aee..47de8ccf6 100644 --- a/apps/api/src/jobs/awooop_ansible_candidate_backfill_job.py +++ b/apps/api/src/jobs/awooop_ansible_candidate_backfill_job.py @@ -188,7 +188,10 @@ async def verify_ansible_candidate_pre_decision_evidence( FROM incident_evidence WHERE id = :snapshot_id AND incident_id = :incident_id - AND post_execution_state IS NULL + AND ( + post_execution_state IS NULL + OR CAST(post_execution_state AS jsonb) = 'null'::jsonb + ) AND sensors_succeeded > 0 AND NULLIF(recent_logs, '') IS NOT NULL AND EXISTS ( diff --git a/apps/api/src/services/awooop_ansible_check_mode_service.py b/apps/api/src/services/awooop_ansible_check_mode_service.py index 05de78399..1c2a03143 100644 --- a/apps/api/src/services/awooop_ansible_check_mode_service.py +++ b/apps/api/src/services/awooop_ansible_check_mode_service.py @@ -967,7 +967,11 @@ async def _load_pre_decision_context_runtime_stage_receipts( ON candidate.op_id = CAST(:candidate_op_id AS uuid) WHERE evidence.incident_id = CAST(:incident_id AS varchar(30)) AND evidence.collected_at <= candidate.created_at - AND evidence.post_execution_state IS NULL + AND ( + evidence.post_execution_state IS NULL + OR CAST(evidence.post_execution_state AS jsonb) + = 'null'::jsonb + ) AND ( NULLIF(evidence.recent_logs, '') IS NOT NULL OR evidence.mcp_health IS NOT NULL diff --git a/apps/api/tests/test_awooop_ansible_candidate_backfill_job.py b/apps/api/tests/test_awooop_ansible_candidate_backfill_job.py index c3162cd97..813ea65ac 100644 --- a/apps/api/tests/test_awooop_ansible_candidate_backfill_job.py +++ b/apps/api/tests/test_awooop_ansible_candidate_backfill_job.py @@ -198,6 +198,7 @@ async def test_predecision_verifier_casts_json_health_to_jsonb( assert verified is True assert "CAST(mcp_health AS jsonb)" in statements[0] + assert "CAST(post_execution_state AS jsonb) = 'null'::jsonb" in statements[0] @pytest.mark.asyncio diff --git a/apps/api/tests/test_awooop_truth_chain_service.py b/apps/api/tests/test_awooop_truth_chain_service.py index 8b634a992..5d8db2eda 100644 --- a/apps/api/tests/test_awooop_truth_chain_service.py +++ b/apps/api/tests/test_awooop_truth_chain_service.py @@ -2037,6 +2037,8 @@ def test_ansible_context_receipts_reference_pre_decision_evidence_without_conten loader_source = inspect.getsource(_load_pre_decision_context_runtime_stage_receipts) assert "evidence.collected_at <= candidate.created_at" in loader_source assert "evidence.post_execution_state IS NULL" in loader_source + assert "CAST(evidence.post_execution_state AS jsonb)" in loader_source + assert "= 'null'::jsonb" in loader_source def test_ansible_context_receipt_rejects_zero_success_mcp_attempts() -> None: