@@ -218,7 +218,15 @@ function supplementalModelSelection(scan, body = {}, fallbackRun = null) {
218218 } ) ;
219219}
220220
221- async function createSupplementalRunRecords ( tx , scanId , postScript , vulnerabilityIds , extra , selection ) {
221+ async function createSupplementalRunRecords (
222+ tx ,
223+ scanId ,
224+ postScript ,
225+ vulnerabilityIds ,
226+ extra ,
227+ selection ,
228+ { retryOfRunId = null } = { }
229+ ) {
222230 const run = await tx . supplementalPostScriptRun . create ( {
223231 data : {
224232 scanId,
@@ -230,6 +238,7 @@ async function createSupplementalRunRecords(tx, scanId, postScript, vulnerabilit
230238 modelProvider : selection . modelProvider ,
231239 harness : selection . harness ,
232240 thinkingEffort : selection . thinkingEffort ,
241+ ...( retryOfRunId === null ? { } : { retryOfRunId } ) ,
233242 extra,
234243 targetCount : vulnerabilityIds . length ,
235244 } ,
@@ -306,6 +315,12 @@ export async function retrySupplementalPostScriptRun(tx, scanId, runId, body = {
306315 return { kind : 'run-active' , status : original . status } ;
307316 }
308317
318+ const existingRetry = await tx . supplementalPostScriptRun . findFirst ( {
319+ where : { scanId, retryOfRunId : runId } ,
320+ select : { id : true } ,
321+ } ) ;
322+ if ( existingRetry ) return { kind : 'already-retried' , retryRunId : existingRetry . id } ;
323+
309324 const failedTargets = await tx . supplementalPostScriptTarget . findMany ( {
310325 where : { runId, scanId, status : 'failed' } ,
311326 select : { vulnerabilityId : true } ,
@@ -339,7 +354,8 @@ export async function retrySupplementalPostScriptRun(tx, scanId, runId, body = {
339354 } ,
340355 vulnerabilityIds ,
341356 original . extra ,
342- selection
357+ selection ,
358+ { retryOfRunId : original . id }
343359 ) ;
344360}
345361
@@ -802,6 +818,11 @@ router.post('/:id/supplemental-post-script-runs/:runId/retry', async (req, res,
802818 if ( result . kind === 'no-failures' ) {
803819 return res . status ( 409 ) . json ( { error : 'This supplemental run has no failed findings to retry.' } ) ;
804820 }
821+ if ( result . kind === 'already-retried' ) {
822+ return res . status ( 409 ) . json ( {
823+ error : `These failed findings were already re-run as supplemental run ${ result . retryRunId } .` ,
824+ } ) ;
825+ }
805826 res . status ( 201 ) . json ( serializeSupplementalPostScriptRun ( result . run , result . targets ) ) ;
806827 } catch ( e ) {
807828 next ( e ) ;
0 commit comments