@@ -27,6 +27,7 @@ import type { ParallelLoggerOptions } from './parallel-logger.js';
2727import type { StructuredCaller } from '../../../agents/structured-caller.js' ;
2828import { runWithPhaseSpan } from '../observability/workflowSpans.js' ;
2929import type { QualityGateRunResult } from '../quality-gates/types.js' ;
30+ import { buildPhaseExecutionId } from '../../../shared/utils/phaseExecutionId.js' ;
3031
3132const log = createLogger ( 'parallel-runner' ) ;
3233
@@ -199,13 +200,21 @@ export class ParallelRunner {
199200 // Phase 1: main execution (Write excluded if sub-step has report)
200201 const baseOptions = this . deps . optionsBuilder . buildAgentOptions ( subStep , runtime ) ;
201202 let didEmitPhaseStart = false ;
203+ let resolvedPromptParts : PhasePromptParts | undefined ;
204+ const phaseExecutionId = buildPhaseExecutionId ( {
205+ step : subStep . name ,
206+ iteration : parentIteration ,
207+ phase : 1 ,
208+ sequence : 1 ,
209+ } ) ;
202210
203211 // Override onStream with parallel logger's prefixed handler (immutable)
204212 const agentOptions = parallelLogger
205213 ? { ...baseOptions , onStream : parallelLogger . createStreamHandler ( subStep . name , index ) }
206214 : { ...baseOptions } ;
207215 agentOptions . onPromptResolved = ( promptParts : PhasePromptParts ) => {
208- this . deps . onPhaseStart ?.( subStep , 1 , 'execute' , subInstruction , promptParts , undefined , parentIteration ) ;
216+ resolvedPromptParts = promptParts ;
217+ this . deps . onPhaseStart ?.( subStep , 1 , 'execute' , subInstruction , promptParts , phaseExecutionId , parentIteration ) ;
209218 didEmitPhaseStart = true ;
210219 } ;
211220 const subResponse = await runWithPhaseSpan ( {
@@ -217,8 +226,10 @@ export class ParallelRunner {
217226 phase : 1 ,
218227 phaseName : 'execute' ,
219228 instruction : subInstruction ,
229+ phaseExecutionId,
220230 sanitizeText : this . deps . sanitizeObservabilityText ,
221231 providerInfo : subPm ,
232+ getPromptParts : ( ) => resolvedPromptParts ,
222233 } , ( ) => executeAgent ( subStep . persona , subInstruction , agentOptions ) , ( result ) => ( {
223234 status : result . status ,
224235 content : result . content ,
@@ -228,7 +239,7 @@ export class ParallelRunner {
228239 throw new Error ( `Missing prompt parts for phase start: ${ subStep . name } :1` ) ;
229240 }
230241 updatePersonaSession ( subSessionKey , subResponse . sessionId ) ;
231- this . deps . onPhaseComplete ?.( subStep , 1 , 'execute' , subResponse . content , subResponse . status , subResponse . error , undefined , parentIteration ) ;
242+ this . deps . onPhaseComplete ?.( subStep , 1 , 'execute' , subResponse . content , subResponse . status , subResponse . error , phaseExecutionId , parentIteration ) ;
232243 if ( subResponse . status === 'error' || subResponse . status === 'blocked' || subResponse . status === 'rate_limited' ) {
233244 state . stepOutputs . set ( subStep . name , subResponse ) ;
234245 return { subStep, response : subResponse , instruction : subInstruction , providerInfo : subPm } ;
0 commit comments