fix(runs): prioritize failed terminal receipts
Some checks failed
CD Pipeline / workflow-shape (push) Has been cancelled
CD Pipeline / cancel-stale-cd (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
Some checks failed
CD Pipeline / workflow-shape (push) Has been cancelled
CD Pipeline / cancel-stale-cd (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import inspect
|
||||
import json
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from types import SimpleNamespace
|
||||
@@ -32,6 +33,7 @@ from src.services.platform_operator_service import (
|
||||
_ai_route_lane_state,
|
||||
_ai_route_policy_order,
|
||||
_ai_route_repair_evidence_item,
|
||||
_apply_run_terminal_truth_precedence,
|
||||
_build_awooop_status_chain,
|
||||
_callback_reply_audit_summary_from_row,
|
||||
_callback_reply_event_item,
|
||||
@@ -2940,6 +2942,128 @@ def test_awooop_status_chain_marks_verified_repair() -> None:
|
||||
assert chain["source_refs"]["refs"]["signoz_alerts"] == ["signoz:abc"]
|
||||
|
||||
|
||||
def test_run_terminal_receipt_overrides_historical_incident_green_state() -> None:
|
||||
historical_chain = {
|
||||
"schema_version": "awooop_status_chain_v1",
|
||||
"source": "truth_chain+adr100_history",
|
||||
"source_id": "INC-BRR-35994B66C2807E74",
|
||||
"incident_ids": ["INC-BRR-35994B66C2807E74"],
|
||||
"current_stage": "execution_succeeded",
|
||||
"stage_status": "success",
|
||||
"verdict": "auto_repaired_verified",
|
||||
"repair_state": "auto_repaired_verified",
|
||||
"verification": "success",
|
||||
"needs_human": False,
|
||||
"next_step": "monitor_for_regression",
|
||||
"operator_outcome": {
|
||||
"state": "completed_verified",
|
||||
"execution_result": {
|
||||
"completion_status": "completed_verified",
|
||||
"terminal": True,
|
||||
},
|
||||
},
|
||||
"evidence": {
|
||||
"auto_repair_records": 1,
|
||||
"operation_records": 4,
|
||||
"mcp_gateway_total": 8,
|
||||
"knowledge_entries": 1,
|
||||
},
|
||||
"writes": {"incident": True, "auto_repair": True},
|
||||
"mcp": {"gateway": {"total": 8, "success": 4}},
|
||||
"execution": {"operation_total": 4, "latest_status": "success"},
|
||||
}
|
||||
run = SimpleNamespace(
|
||||
run_id=UUID("f53d95ac-04d3-5228-ae74-9ab0ad95c013"),
|
||||
state="failed",
|
||||
error_code="E-AGENT99-OUTCOME-TIMEOUT",
|
||||
timeout_at=datetime.fromisoformat("2026-07-15T00:22:32.527349"),
|
||||
completed_at=datetime.fromisoformat("2026-07-15T01:23:15.118099"),
|
||||
error_detail=json.dumps({
|
||||
"outcome_timeout_no_write_terminal": True,
|
||||
"terminalizer_runtime_write_performed": False,
|
||||
"outcome_runtime_write_status": (
|
||||
"unknown_without_authenticated_outcome"
|
||||
),
|
||||
"transport_replayed": False,
|
||||
"incident_resolution_authorized": False,
|
||||
"runtime_closure_verified": False,
|
||||
"safe_next_action": (
|
||||
"await_new_source_recurrence_after_agent99_relay_recovery"
|
||||
),
|
||||
"verifier": {
|
||||
"receipt": {
|
||||
"timeout_at": "2026-07-15T00:22:32.527349",
|
||||
"terminal_at": "2026-07-15T01:23:15.118099",
|
||||
}
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
chain = _apply_run_terminal_truth_precedence(
|
||||
run=run,
|
||||
status_chain=historical_chain,
|
||||
)
|
||||
|
||||
assert chain["source"] == (
|
||||
"run_terminal_receipt>historical_incident_context"
|
||||
)
|
||||
assert chain["stage_status"] == "failed"
|
||||
assert chain["repair_state"] == "failed_no_write_terminal"
|
||||
assert chain["verification"] == "failed_authenticated_outcome_timeout"
|
||||
assert chain["needs_human"] is False
|
||||
assert chain["operator_outcome"]["state"] == "failed_no_write_terminal"
|
||||
assert chain["operator_outcome"]["execution_result"][
|
||||
"completion_status"
|
||||
] == "failed_no_write_terminal"
|
||||
assert chain["writes"] == {"incident": False, "auto_repair": False}
|
||||
assert chain["evidence"]["auto_repair_records"] == 0
|
||||
assert chain["execution"]["operation_total"] == 0
|
||||
assert chain["run_terminal_precedence"] == {
|
||||
"active": True,
|
||||
"reason": "higher_priority_run_terminal_receipt",
|
||||
"run_id": "f53d95ac-04d3-5228-ae74-9ab0ad95c013",
|
||||
"run_state": "failed",
|
||||
"error_code": "E-AGENT99-OUTCOME-TIMEOUT",
|
||||
"outcome_timeout_no_write_terminal": True,
|
||||
"timeout_at": "2026-07-15T00:22:32.527349",
|
||||
"terminal_at": "2026-07-15T01:23:15.118099",
|
||||
"terminalizer_runtime_write_performed": False,
|
||||
"outcome_runtime_write_status": (
|
||||
"unknown_without_authenticated_outcome"
|
||||
),
|
||||
"transport_replayed": False,
|
||||
"incident_resolution_authorized": False,
|
||||
"runtime_closure_verified": False,
|
||||
"safe_next_action": (
|
||||
"await_new_source_recurrence_after_agent99_relay_recovery"
|
||||
),
|
||||
}
|
||||
assert chain["historical_incident_context"]["repair_state"] == (
|
||||
"auto_repaired_verified"
|
||||
)
|
||||
assert chain["historical_incident_context"]["writes"] == {
|
||||
"incident": True,
|
||||
"auto_repair": True,
|
||||
}
|
||||
assert "_apply_run_terminal_truth_precedence" in inspect.getsource(
|
||||
platform_operator_service.get_run_detail
|
||||
)
|
||||
|
||||
|
||||
def test_run_terminal_precedence_leaves_unrelated_failed_run_unchanged() -> None:
|
||||
chain = {"repair_state": "auto_repaired_verified"}
|
||||
run = SimpleNamespace(
|
||||
state="failed",
|
||||
error_code="E-OTHER",
|
||||
error_detail="{}",
|
||||
)
|
||||
|
||||
assert _apply_run_terminal_truth_precedence(
|
||||
run=run,
|
||||
status_chain=chain,
|
||||
) == chain
|
||||
|
||||
|
||||
def test_awooop_status_chain_surfaces_controlled_ansible_apply_proof() -> None:
|
||||
chain = _build_awooop_status_chain(
|
||||
incident_ids=["INC-20260531-D6A3C4"],
|
||||
|
||||
Reference in New Issue
Block a user