fix(agent): preserve log consumer readback on trace failure
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 44s
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-07-01 18:27:59 +08:00
parent d873a3258c
commit 7aa9cb66ec
2 changed files with 94 additions and 6 deletions

View File

@@ -3249,6 +3249,9 @@ def _attach_runtime_receipt_readback(
log_consumer_blockers = log_consumer.get("active_blockers")
if not isinstance(log_consumer_blockers, list):
log_consumer_blockers = []
log_consumer_dispatch_ledger_count = _int_value(
log_consumer_rollups.get("dispatch_ledger_row_count")
)
operation_counts = (readback.get("ansible_operations") or {}).get("counts")
if not isinstance(operation_counts, Mapping):
operation_counts = {}
@@ -3373,11 +3376,17 @@ def _attach_runtime_receipt_readback(
)
),
"live_log_controlled_writeback_dispatch_count": _int_value(
log_dispatch_summary.get("total")
max(
_int_value(log_dispatch_summary.get("total")),
log_consumer_dispatch_ledger_count,
)
),
"live_log_controlled_writeback_recent_dispatch_count": _int_value(
log_dispatch_summary.get("recent")
),
"live_log_controlled_writeback_consumer_dispatch_ledger_count": (
log_consumer_dispatch_ledger_count
),
"live_log_controlled_writeback_consumer_binding_count": _int_value(
log_consumer_rollups.get("consumer_binding_count")
),
@@ -3834,6 +3843,7 @@ async def load_ai_agent_autonomous_runtime_receipt_readback(
"lookback_hours": max(1, int(lookback_hours or _DEFAULT_LOOKBACK_HOURS)),
"limit": max(1, int(limit or 20)),
}
log_controlled_writeback_consumer: dict[str, Any] | None = None
try:
async with get_db_context(project_id) as db:
await db.execute(text("SET LOCAL statement_timeout = '5000ms'"))
@@ -3932,24 +3942,30 @@ async def load_ai_agent_autonomous_runtime_receipt_readback(
"grouped_alert_event_counts",
_RUNTIME_GROUPED_ALERT_EVENT_COUNTS_SQL,
)
log_controlled_writeback_consumer = (
await _load_log_controlled_writeback_consumer_readback(
project_id=project_id,
)
)
except Exception as exc:
logger.warning(
"ai_agent_autonomous_runtime_receipt_readback_failed",
project_id=project_id,
error_type=type(exc).__name__,
)
log_controlled_writeback_consumer = (
await _load_log_controlled_writeback_consumer_readback(
project_id=project_id,
)
)
return build_runtime_receipt_readback_from_rows(
project_id=project_id,
lookback_hours=params["lookback_hours"],
db_read_status="unavailable",
error_type=type(exc).__name__,
log_controlled_writeback_consumer=log_controlled_writeback_consumer,
)
log_controlled_writeback_consumer = (
await _load_log_controlled_writeback_consumer_readback(
project_id=project_id,
)
)
return build_runtime_receipt_readback_from_rows(
project_id=project_id,
lookback_hours=params["lookback_hours"],