Merge remote-tracking branch 'origin/main' into codex/p0-obs-002-20260715
This commit is contained in:
@@ -443,7 +443,19 @@ async def _try_auto_repair_background(
|
||||
# Agent99 is the only dispatch owner for host control-plane recovery.
|
||||
# The generic Ansible catalog must not manufacture candidates from
|
||||
# incidental words such as 110, backup, Docker, or container.
|
||||
route_id = str(handoff.get("route_id") or "")
|
||||
policy_route_id = str(handoff.get("route_id") or "")
|
||||
route_id = policy_route_id
|
||||
if (
|
||||
handoff.get("single_writer_executor") == "Agent99"
|
||||
and durable_agent99_route is not None
|
||||
):
|
||||
route_id = str(durable_agent99_route["route_id"])
|
||||
handoff.update({
|
||||
"policy_route_id": policy_route_id,
|
||||
"route_id": route_id,
|
||||
"agent99_kind": durable_agent99_route["kind"],
|
||||
"agent99_mode": durable_agent99_route["suggested_mode"],
|
||||
})
|
||||
dispatch_result = await bridge_alertmanager_to_agent99(
|
||||
alert_id=source_alert_id,
|
||||
alertname=source_alertname or alert_type,
|
||||
|
||||
@@ -613,7 +613,7 @@ async def reconcile_agent99_controlled_dispatches_once(
|
||||
else {}
|
||||
)
|
||||
}
|
||||
if is_cold_start_same_run_identity(identity):
|
||||
if is_cold_start_same_run_identity(identity, receipt):
|
||||
source_receipt = await asyncio.to_thread(
|
||||
read_cold_start_source_resolution,
|
||||
)
|
||||
@@ -637,6 +637,7 @@ async def reconcile_agent99_controlled_dispatches_once(
|
||||
request_agent99_same_run_status_reconcile,
|
||||
identity,
|
||||
source_receipt,
|
||||
receipt,
|
||||
)
|
||||
if request_receipt.get("accepted") is True:
|
||||
counters["status_reconcile_requested"] += 1
|
||||
|
||||
@@ -343,6 +343,15 @@ def build_agent99_dispatch_receipt_envelope(
|
||||
else "dispatch_delivery_unknown_reconcile_only"
|
||||
),
|
||||
"identity": public_identity,
|
||||
"dispatch_scope": {
|
||||
"schema_version": "agent99_dispatch_scope_v1",
|
||||
"kind": str(dispatch_receipt.get("kind") or ""),
|
||||
"suggested_mode": str(dispatch_receipt.get("suggested_mode") or ""),
|
||||
"target_resource": str(dispatch_receipt.get("target_resource") or ""),
|
||||
"controlled_apply_requested": bool(
|
||||
dispatch_receipt.get("controlled_apply_requested") is True
|
||||
),
|
||||
},
|
||||
"dispatch_receipt": {
|
||||
"schema_version": str(
|
||||
dispatch_receipt.get("schema_version")
|
||||
@@ -493,6 +502,13 @@ class PostgresAgent99DispatchLedger:
|
||||
"schema_version": "agent99_controlled_dispatch_receipt_v1",
|
||||
"status": "dispatch_reserved",
|
||||
"identity": identity_payload,
|
||||
"dispatch_scope": {
|
||||
"schema_version": "agent99_dispatch_scope_v1",
|
||||
"kind": input_payload["kind"],
|
||||
"suggested_mode": input_payload["suggested_mode"],
|
||||
"target_resource": input_payload["target_resource"],
|
||||
"controlled_apply_requested": input_payload["controlled_apply"],
|
||||
},
|
||||
"dispatch_accepted": False,
|
||||
"controlled_apply_requested": bool(input_payload["controlled_apply"]),
|
||||
"controlled_apply_authorized": False,
|
||||
|
||||
@@ -13,6 +13,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
import re
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
@@ -82,16 +83,51 @@ _COLD_START_QUERIES = {
|
||||
}
|
||||
|
||||
|
||||
def is_cold_start_same_run_identity(identity: Agent99DispatchIdentity) -> bool:
|
||||
"""Limit this transport to the existing cold-start Recover identity."""
|
||||
def is_cold_start_same_run_identity(
|
||||
identity: Agent99DispatchIdentity,
|
||||
receipt: dict[str, Any] | None = None,
|
||||
) -> bool:
|
||||
"""Admit only a canonical cold-start Recover dispatch to no-write Status."""
|
||||
|
||||
return bool(
|
||||
legacy_identity = bool(
|
||||
identity.route_id == AGENT99_COLD_START_ROUTE_ID
|
||||
and identity.incident_id == AGENT99_COLD_START_INCIDENT_ID
|
||||
and str(identity.run_id) == AGENT99_COLD_START_RUN_ID
|
||||
and identity.source_fingerprint.startswith("legacy-cold-start:")
|
||||
and identity.execution_generation == "1"
|
||||
)
|
||||
if legacy_identity:
|
||||
return True
|
||||
|
||||
scope = (
|
||||
receipt.get("dispatch_scope")
|
||||
if isinstance(receipt, dict)
|
||||
and isinstance(receipt.get("dispatch_scope"), dict)
|
||||
else {}
|
||||
)
|
||||
try:
|
||||
generation = int(identity.execution_generation)
|
||||
except ValueError:
|
||||
return False
|
||||
expected_work_item_id = (
|
||||
f"agent99-dispatch:awoooi:{identity.incident_id}:"
|
||||
f"{AGENT99_COLD_START_ROUTE_ID}"
|
||||
)
|
||||
return bool(
|
||||
identity.project_id == "awoooi"
|
||||
and identity.route_id == AGENT99_COLD_START_ROUTE_ID
|
||||
and re.fullmatch(r"INC-[0-9]{8}-[0-9A-F]{6}", identity.incident_id)
|
||||
is not None
|
||||
and identity.work_item_id == expected_work_item_id
|
||||
and re.fullmatch(r"[0-9a-f]{32,64}", identity.source_fingerprint)
|
||||
is not None
|
||||
and 1 <= generation <= 3
|
||||
and scope.get("schema_version") == "agent99_dispatch_scope_v1"
|
||||
and scope.get("kind") == "host_recovery"
|
||||
and scope.get("suggested_mode") == "Recover"
|
||||
and scope.get("target_resource") == "cold-start-gate"
|
||||
and scope.get("controlled_apply_requested") is True
|
||||
)
|
||||
|
||||
|
||||
def agent99_same_run_evidence_id(identity: Agent99DispatchIdentity) -> str:
|
||||
@@ -235,6 +271,7 @@ def read_cold_start_source_resolution(
|
||||
def request_agent99_same_run_status_reconcile(
|
||||
identity: Agent99DispatchIdentity,
|
||||
source_receipt: dict[str, Any],
|
||||
dispatch_receipt: dict[str, Any] | None = None,
|
||||
*,
|
||||
relay_url: str | None = None,
|
||||
relay_token: str | None = None,
|
||||
@@ -242,7 +279,7 @@ def request_agent99_same_run_status_reconcile(
|
||||
) -> dict[str, Any]:
|
||||
"""Ask Agent99 for one idempotent, no-write Status on the existing run."""
|
||||
|
||||
if not is_cold_start_same_run_identity(identity):
|
||||
if not is_cold_start_same_run_identity(identity, dispatch_receipt):
|
||||
return {
|
||||
"status": "identity_not_eligible_fail_closed",
|
||||
"accepted": False,
|
||||
|
||||
@@ -838,6 +838,14 @@ def dispatch_agent99_sre_alert_with_receipt(
|
||||
|
||||
alert_id = _safe_text(payload.get("id"), max_length=160)
|
||||
kind = _safe_text(payload.get("kind"), max_length=120)
|
||||
awoooi = (
|
||||
payload.get("awoooi")
|
||||
if isinstance(payload.get("awoooi"), dict)
|
||||
else {}
|
||||
)
|
||||
target_resource = _safe_text(awoooi.get("targetResource"), max_length=240)
|
||||
suggested_mode = _safe_text(payload.get("suggestedMode"), max_length=80)
|
||||
controlled_apply_requested = bool(payload.get("controlledApply") is True)
|
||||
if settings.AGENT99_SRE_ALERT_RELAY_URL:
|
||||
raw_receipt = post_agent99_sre_alert(payload) or {}
|
||||
response_payload: dict[str, Any] = {}
|
||||
@@ -862,6 +870,9 @@ def dispatch_agent99_sre_alert_with_receipt(
|
||||
"transport": "relay",
|
||||
"alert_id": alert_id,
|
||||
"kind": kind,
|
||||
"target_resource": target_resource,
|
||||
"suggested_mode": suggested_mode,
|
||||
"controlled_apply_requested": controlled_apply_requested,
|
||||
"http_status": http_status,
|
||||
"accepted": accepted,
|
||||
"inbox_triggered": inbox_triggered,
|
||||
@@ -884,6 +895,9 @@ def dispatch_agent99_sre_alert_with_receipt(
|
||||
"transport": "file",
|
||||
"alert_id": alert_id,
|
||||
"kind": kind,
|
||||
"target_resource": target_resource,
|
||||
"suggested_mode": suggested_mode,
|
||||
"controlled_apply_requested": controlled_apply_requested,
|
||||
"accepted": True,
|
||||
"inbox_triggered": False,
|
||||
# A file write is not proof that the Agent99 inbox consumed it.
|
||||
@@ -903,6 +917,9 @@ def dispatch_agent99_sre_alert_with_receipt(
|
||||
"transport": "disabled",
|
||||
"alert_id": alert_id,
|
||||
"kind": kind,
|
||||
"target_resource": target_resource,
|
||||
"suggested_mode": suggested_mode,
|
||||
"controlled_apply_requested": controlled_apply_requested,
|
||||
"accepted": False,
|
||||
"inbox_triggered": False,
|
||||
"delivery_certainty": "not_delivered",
|
||||
|
||||
Reference in New Issue
Block a user