fix(bom-costing): reset recovery budget after progress

This commit is contained in:
WuYongJie 2026-08-05 01:00:07 +08:00
parent 96a3abda1d
commit 131e83ce77

View File

@ -843,12 +843,27 @@ export class BomCostingRepository {
})
if (!run) return false
// Count any automatic recovery for this case. A finite limit prevents a
// persistent provider outage from making an invisible endless loop.
// Only count recoveries after the most recent successful synthesis batch.
// A successful batch proves the provider recovered, so older retries must
// not consume the budget for a later, unrelated short-lived timeout.
const latestSynthesisCompletion = await tx.bomCostingTaskEvent.findFirst({
where: {
caseId: input.caseId,
eventType: 'MODEL_SYNTHESIS_BATCH_COMPLETED',
},
orderBy: { createdAt: 'desc' },
select: { createdAt: true },
})
// Keep a finite limit for consecutive failures so a persistent provider
// outage still cannot make an invisible endless loop.
const recoveryCount = await tx.bomCostingTaskEvent.count({
where: {
caseId: input.caseId,
eventType: 'TASK_RECOVERY_QUEUED',
...(latestSynthesisCompletion
? { createdAt: { gt: latestSynthesisCompletion.createdAt } }
: {}),
},
})
if (recoveryCount >= maxAutoRecoveries) return false