@@ -72,7 +72,12 @@ export async function runReachabilityStage(
7272 const concurrency = 4
7373 const queue = [ ...dependents ]
7474
75- const upsertErrorVerdict = ( dependentId : string , reasoning : string , model : string | null ) =>
75+ const upsertErrorVerdict = (
76+ dependentId : string ,
77+ reasoning : string ,
78+ model : string | null ,
79+ costUsd = 0 ,
80+ ) =>
7681 blastRadiusDal . upsertVerdict ( qx , {
7782 analysisId,
7883 dependentId,
@@ -85,7 +90,7 @@ export async function runReachabilityStage(
8590 reasoning,
8691 model,
8792 turnsUsed : null ,
88- costUsd : 0 ,
93+ costUsd,
8994 } )
9095
9196 const processOne = async ( dep : blastRadiusDal . DependentRow ) : Promise < void > => {
@@ -114,7 +119,11 @@ export async function runReachabilityStage(
114119 return
115120 }
116121
117- // Try agent up to MAX_ATTEMPTS times with exponential backoff
122+ // Try agent up to MAX_ATTEMPTS times with exponential backoff. costUsd is
123+ // accumulated across attempts — a persistent failure still spends real money
124+ // on every retry, and that spend must show up in the verdict/stage/analysis
125+ // totals even though only the last attempt's outcome is persisted.
126+ let accumulatedCost = 0
118127 for ( let attempt = 1 ; attempt <= MAX_ATTEMPTS ; attempt ++ ) {
119128 try {
120129 const systemPrompt = buildReachabilitySystemPrompt ( spec )
@@ -129,6 +138,7 @@ export async function runReachabilityStage(
129138 timeoutMs : 600_000 ,
130139 onProgress,
131140 } )
141+ accumulatedCost += agentResult . costUsd || 0
132142
133143 if ( ! agentResult . isError && agentResult . structuredOutput ) {
134144 const output = agentResult . structuredOutput
@@ -145,7 +155,7 @@ export async function runReachabilityStage(
145155 reasoning : String ( output . reasoning || '' ) ,
146156 model : 'claude-sonnet-5' ,
147157 turnsUsed : agentResult . numTurns ,
148- costUsd : agentResult . costUsd || 0 ,
158+ costUsd : accumulatedCost ,
149159 } )
150160
151161 return
@@ -161,6 +171,7 @@ export async function runReachabilityStage(
161171 dep . id ,
162172 `Agent failed: ${ err instanceof Error ? err . message : String ( err ) } ` ,
163173 'claude-sonnet-5' ,
174+ accumulatedCost ,
164175 )
165176 return
166177 }
0 commit comments