fix(awooop): keep automation log source readback active
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 18s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled

This commit is contained in:
Your Name
2026-06-29 16:15:51 +08:00
parent c14c7338d7
commit 768cd608ed
2 changed files with 48 additions and 1 deletions

View File

@@ -2041,7 +2041,11 @@ async def load_ai_agent_autonomous_runtime_receipt_readback(
async with get_db_context(project_id) as db:
await db.execute(text("SET LOCAL statement_timeout = '5000ms'"))
async def _safe_aux_rows(query_name: str, sql: str) -> list[Mapping[str, Any]]:
async def _safe_aux_rows(
query_name: str,
sql: str,
fallback_sql: str | None = None,
) -> list[Mapping[str, Any]]:
try:
return (await db.execute(text(sql), params)).mappings().all()
except Exception as exc: # pragma: no cover - depends on live schema drift
@@ -2051,6 +2055,16 @@ async def load_ai_agent_autonomous_runtime_receipt_readback(
query_name=query_name,
error_type=type(exc).__name__,
)
if fallback_sql:
try:
return (await db.execute(text(fallback_sql), params)).mappings().all()
except Exception as fallback_exc: # pragma: no cover - live schema drift
logger.warning(
"ai_agent_autonomous_runtime_trace_aux_fallback_failed",
project_id=project_id,
query_name=query_name,
error_type=type(fallback_exc).__name__,
)
return []
operation_counts = (
@@ -2102,10 +2116,12 @@ async def load_ai_agent_autonomous_runtime_receipt_readback(
timeline_counts = await _safe_aux_rows(
"timeline_counts",
_RUNTIME_TIMELINE_COUNTS_SQL,
_RUNTIME_TIMELINE_COUNTS_FALLBACK_SQL,
)
playbook_trust_counts = await _safe_aux_rows(
"playbook_trust_counts",
_RUNTIME_PLAYBOOK_TRUST_COUNTS_SQL,
_RUNTIME_PLAYBOOK_TRUST_COUNTS_FALLBACK_SQL,
)
except Exception as exc:
logger.warning(
@@ -2440,6 +2456,17 @@ _RUNTIME_TIMELINE_COUNTS_SQL = """
WHERE event_type IS NOT NULL
OR actor IS NOT NULL
OR actor_role IS NOT NULL
GROUP BY coalesce(status, 'unknown')
ORDER BY status
"""
_RUNTIME_TIMELINE_COUNTS_FALLBACK_SQL = """
SELECT
'timeline_event' AS status,
count(*) AS total,
0 AS recent
FROM timeline_events
"""
@@ -2469,6 +2496,15 @@ _RUNTIME_PLAYBOOK_TRUST_COUNTS_SQL = """
"""
_RUNTIME_PLAYBOOK_TRUST_COUNTS_FALLBACK_SQL = """
SELECT
'cataloged' AS status,
count(*) AS total,
0 AS recent
FROM playbooks
"""
def _validate_payload(payload: dict[str, Any]) -> None:
if payload.get("schema_version") != _SCHEMA_VERSION:
raise ValueError(f"schema_version must be {_SCHEMA_VERSION}")