fix(iwooos): expose closed Wazuh runtime lane
This commit is contained in:
@@ -839,8 +839,9 @@ async def preview_iwooos_wazuh_controlled_executor_handoff(
|
||||
response_model=dict[str, Any],
|
||||
summary="取得 Wazuh controlled executor live runtime receipt 讀回",
|
||||
description=(
|
||||
"優先讀取內部 worker 排程的 Wazuh sanitized alert-ingress convergence,"
|
||||
"尚無 ingress candidate 時才回退到 manager bounded no-write posture executor;"
|
||||
"同時讀取內部 worker 排程的 Wazuh sanitized alert-ingress convergence 與 manager "
|
||||
"bounded no-write posture executor;已閉環 lane 優先,兩者皆未閉環時維持 ingress "
|
||||
"candidate 優先,並公開兩 lane 的脫敏摘要,避免 blocked lane 遮住 closure truth。"
|
||||
"candidate、check-mode、execution、independent verifier、KM / RAG / PlayBook、"
|
||||
"MCP context 與 Telegram durable receipts。此端點不執行命令、不回傳 command output、"
|
||||
"inventory identity、主機位址、raw Wazuh payload 或機密值。"
|
||||
|
||||
@@ -646,15 +646,90 @@ _LIVE_RUNTIME_SQL = """
|
||||
async def load_latest_iwooos_wazuh_controlled_executor_runtime(
|
||||
*, project_id: str = "awoooi"
|
||||
) -> dict[str, Any]:
|
||||
"""Read the latest Wazuh posture executor chain from durable receipts."""
|
||||
"""Read both Wazuh lanes without letting a blocked lane hide closure."""
|
||||
|
||||
lanes = await load_iwooos_wazuh_controlled_executor_runtime_lanes(
|
||||
project_id=project_id
|
||||
)
|
||||
selected_lane_id, selection_reason = _select_wazuh_runtime_lane(lanes)
|
||||
payload = dict(lanes[selected_lane_id])
|
||||
payload["lane_selection"] = {
|
||||
"schema_version": "iwooos_wazuh_runtime_lane_selection_v1",
|
||||
"selected_lane_id": selected_lane_id,
|
||||
"selection_reason": selection_reason,
|
||||
"lanes": {
|
||||
lane_id: _wazuh_runtime_lane_summary(lane_id, lane)
|
||||
for lane_id, lane in lanes.items()
|
||||
},
|
||||
}
|
||||
return payload
|
||||
|
||||
|
||||
def _select_wazuh_runtime_lane(
|
||||
lanes: Mapping[str, Mapping[str, Any]],
|
||||
) -> tuple[str, str]:
|
||||
"""Choose closed truth first, then retain ingress convergence priority."""
|
||||
|
||||
ingress = lanes["ingress"]
|
||||
if ingress["summary"]["dispatch_candidate_count"] > 0:
|
||||
return ingress
|
||||
return lanes["posture"]
|
||||
posture = lanes["posture"]
|
||||
ingress_closed = _wazuh_runtime_lane_closed(ingress)
|
||||
posture_closed = _wazuh_runtime_lane_closed(posture)
|
||||
if ingress_closed:
|
||||
return "ingress", "ingress_runtime_closed"
|
||||
if posture_closed:
|
||||
return "posture", "posture_runtime_closed_ingress_open"
|
||||
ingress_summary = ingress.get("summary")
|
||||
ingress_candidate_count = (
|
||||
_nonnegative_int(ingress_summary.get("dispatch_candidate_count"))
|
||||
if isinstance(ingress_summary, Mapping)
|
||||
else 0
|
||||
)
|
||||
if ingress_candidate_count > 0:
|
||||
return "ingress", "ingress_candidate_active"
|
||||
return "posture", "posture_fallback_no_ingress_candidate"
|
||||
|
||||
|
||||
def _wazuh_runtime_lane_closed(lane: Mapping[str, Any]) -> bool:
|
||||
summary = lane.get("summary")
|
||||
return bool(
|
||||
isinstance(summary, Mapping)
|
||||
and _nonnegative_int(summary.get("runtime_closed_count")) > 0
|
||||
)
|
||||
|
||||
|
||||
def _wazuh_runtime_lane_summary(
|
||||
lane_id: str,
|
||||
lane: Mapping[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
summary = lane.get("summary")
|
||||
if not isinstance(summary, Mapping):
|
||||
summary = {}
|
||||
return {
|
||||
"lane_id": lane_id,
|
||||
"work_item_id": str(lane.get("work_item_id") or "") or None,
|
||||
"status": str(lane.get("status") or "") or None,
|
||||
"latest_receipt_at": (
|
||||
str(lane.get("latest_receipt_at") or "") or None
|
||||
),
|
||||
"selected_catalog_id": (
|
||||
str(summary.get("selected_catalog_id") or "") or None
|
||||
),
|
||||
"dispatch_candidate_count": _nonnegative_int(
|
||||
summary.get("dispatch_candidate_count")
|
||||
),
|
||||
"check_mode_passed_count": _nonnegative_int(
|
||||
summary.get("check_mode_passed_count")
|
||||
),
|
||||
"check_mode_failed_count": _nonnegative_int(
|
||||
summary.get("check_mode_failed_count")
|
||||
),
|
||||
"same_run_completion_percent": _nonnegative_int(
|
||||
summary.get("same_run_completion_percent")
|
||||
),
|
||||
"runtime_closed": _wazuh_runtime_lane_closed(lane),
|
||||
"missing_stage_ids": list(lane.get("missing_stage_ids") or []),
|
||||
"active_blockers": list(lane.get("active_blockers") or []),
|
||||
}
|
||||
|
||||
|
||||
async def load_iwooos_wazuh_controlled_executor_runtime_lanes(
|
||||
|
||||
Reference in New Issue
Block a user