Merge remote-tracking branch 'origin/main' into codex/p0-obs-002-20260715
This commit is contained in:
@@ -8,6 +8,7 @@ the database boundary.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
@@ -29,6 +30,7 @@ RECONCILIATION_SUMMARY_OPERATION = "asset_capability_reconciliation_completed"
|
||||
RECONCILIATION_WORK_ITEM_OPERATION = "asset_capability_reconciliation_work_item_created"
|
||||
FRESHNESS_SLO_SECONDS = 2 * 60 * 60
|
||||
RECONCILIATION_FRESHNESS_SLO_SECONDS = 36 * 60 * 60
|
||||
LIVE_READBACK_TIMEOUT_SECONDS = 8.0
|
||||
|
||||
STAGE_IDS = (
|
||||
"source_truth",
|
||||
@@ -1044,6 +1046,7 @@ async def _load_live_rows(
|
||||
"created_at": item.get("coverage_created_at"),
|
||||
}
|
||||
|
||||
asset_ids = list(assets_by_id) or [0]
|
||||
compliance_result = await db.execute(
|
||||
text(
|
||||
"""
|
||||
@@ -1054,7 +1057,7 @@ async def _load_live_rows(
|
||||
ORDER BY asset_id, dimension, detected_at DESC
|
||||
"""
|
||||
),
|
||||
{"asset_ids": list(assets_by_id) or [0]},
|
||||
{"asset_ids": asset_ids},
|
||||
)
|
||||
for row in compliance_result.mappings().all():
|
||||
item = dict(row)
|
||||
@@ -1072,9 +1075,11 @@ async def _load_live_rows(
|
||||
FROM asset_change_event
|
||||
WHERE detected_at >= NOW() - INTERVAL '36 hours'
|
||||
AND asset_id IS NOT NULL
|
||||
AND asset_id = ANY(:asset_ids)
|
||||
ORDER BY detected_at DESC
|
||||
"""
|
||||
)
|
||||
),
|
||||
{"asset_ids": asset_ids},
|
||||
)
|
||||
for row in changes_result.mappings().all():
|
||||
item = dict(row)
|
||||
@@ -1112,6 +1117,7 @@ async def build_asset_capability_matrix_with_live_readback(
|
||||
*,
|
||||
project_id: str = DEFAULT_PROJECT_ID,
|
||||
repo_root: Path | None = None,
|
||||
timeout_seconds: float = LIVE_READBACK_TIMEOUT_SECONDS,
|
||||
) -> dict[str, Any]:
|
||||
"""Build the matrix from live DB truth, failing closed to declared scope."""
|
||||
|
||||
@@ -1120,12 +1126,17 @@ async def build_asset_capability_matrix_with_live_readback(
|
||||
)
|
||||
|
||||
scope_classes = get_ai_automation_program_scope_classes()
|
||||
bounded_timeout_seconds = max(0.001, float(timeout_seconds))
|
||||
try:
|
||||
latest_run, live_assets, receipt = await _load_live_rows(project_id)
|
||||
latest_run, live_assets, receipt = await asyncio.wait_for(
|
||||
_load_live_rows(project_id),
|
||||
timeout=bounded_timeout_seconds,
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.warning(
|
||||
"asset_capability_matrix_live_readback_degraded",
|
||||
error_type=type(exc).__name__,
|
||||
timeout_seconds=bounded_timeout_seconds,
|
||||
)
|
||||
payload = build_asset_capability_matrix(
|
||||
scope_classes,
|
||||
@@ -1133,8 +1144,9 @@ async def build_asset_capability_matrix_with_live_readback(
|
||||
live_readback_status="degraded",
|
||||
)
|
||||
payload["live_readback_error_type"] = type(exc).__name__
|
||||
payload["live_readback_timeout_seconds"] = bounded_timeout_seconds
|
||||
return payload
|
||||
return build_asset_capability_matrix(
|
||||
payload = build_asset_capability_matrix(
|
||||
scope_classes,
|
||||
live_assets=live_assets,
|
||||
latest_run=latest_run,
|
||||
@@ -1142,3 +1154,5 @@ async def build_asset_capability_matrix_with_live_readback(
|
||||
repo_root=repo_root,
|
||||
live_readback_status="ready",
|
||||
)
|
||||
payload["live_readback_timeout_seconds"] = bounded_timeout_seconds
|
||||
return payload
|
||||
|
||||
Reference in New Issue
Block a user