fix(agent): bound stale retry terminalization

This commit is contained in:
ogt
2026-07-11 16:18:32 +08:00
parent bd27d4e759
commit 673b0d57a4
2 changed files with 58 additions and 24 deletions

View File

@@ -4799,17 +4799,28 @@ async def run_failed_apply_check_mode_replay_once(
claim.input_payload.get("automation_run_id")
or claim.source_candidate_op_id
)
blockers = _runtime_blockers()
if blockers:
stats["blockers"] = blockers
return stats
transport_blockers = await recent_ansible_transport_blockers(
project_id=project_id
stale_replay_op_id = str(row.get("stale_replay_op_id") or "")
stale_recovery_count = int(
row.get("stale_replay_recovery_count") or 0
)
if transport_blockers:
stats["blockers"] = transport_blockers
return stats
stale_retry_terminalized = bool(
stale_replay_op_id
and stale_recovery_count >= _CONTROLLED_RETRY_MAX_ATTEMPTS
)
stats["stale_retry_reclaimed"] = int(bool(stale_replay_op_id))
stats["stale_retry_terminalized"] = int(stale_retry_terminalized)
if not stale_retry_terminalized:
blockers = _runtime_blockers()
if blockers:
stats["blockers"] = blockers
return stats
transport_blockers = await recent_ansible_transport_blockers(
project_id=project_id
)
if transport_blockers:
stats["blockers"] = transport_blockers
return stats
retry_claim_id = str(uuid4())
retry_claimed_at = datetime.now(UTC).isoformat()
@@ -4834,9 +4845,6 @@ async def run_failed_apply_check_mode_replay_once(
),
}
async with get_db_context(project_id) as db:
stale_replay_op_id = str(
row.get("stale_replay_op_id") or ""
)
await db.execute(
text("""
SELECT pg_advisory_xact_lock(
@@ -4969,15 +4977,6 @@ async def run_failed_apply_check_mode_replay_once(
stats["blockers"] = ["failed_apply_retry_claim_raced"]
return stats
replay_op_id = str(replay_op_id_value)
stale_recovery_count = int(
row.get("stale_replay_recovery_count") or 0
)
stale_retry_terminalized = bool(
stale_replay_op_id
and stale_recovery_count >= _CONTROLLED_RETRY_MAX_ATTEMPTS
)
stats["stale_retry_reclaimed"] = int(bool(stale_replay_op_id))
stats["stale_retry_terminalized"] = int(stale_retry_terminalized)
if stale_retry_terminalized:
replay_result = AnsibleRunResult(
returncode=1,
@@ -5014,6 +5013,7 @@ async def run_failed_apply_check_mode_replay_once(
"approval_required_before_apply": False,
"owner_review_required": False,
"runtime_apply_executed": False,
"check_mode_executed": not stale_retry_terminalized,
"check_mode_replay_performed": not stale_retry_terminalized,
"stale_pending_retry_terminalized": stale_retry_terminalized,
"bounded_execution_scope": "retry_check_mode_only",
@@ -5033,6 +5033,7 @@ async def run_failed_apply_check_mode_replay_once(
"approval_required_before_apply": False,
"owner_review_required": False,
"runtime_apply_executed": False,
"check_mode_executed": not stale_retry_terminalized,
"check_mode_replay_performed": not stale_retry_terminalized,
"stale_pending_retry_terminalized": stale_retry_terminalized,
"bounded_execution_scope": "retry_check_mode_only",