@@ -21,6 +21,7 @@ import {
2121 assertBatchRuntimeCommandAllowed ,
2222 normalizeBatchCommandName ,
2323} from './batch-policy.ts' ;
24+ import { resolveCommandRecordingEffect } from './registry.ts' ;
2425
2526const batchAllowedStepKeys = new Set < string > ( BATCH_DAEMON_STEP_KEYS ) ;
2627
@@ -115,31 +116,11 @@ export async function runBatch(
115116 } ) ) ,
116117 } ) ;
117118 if ( ! stepResponse . ok ) {
118- return {
119- ok : false ,
120- error : {
121- code : stepResponse . error . code ,
122- message : `Batch failed at step ${ stepResponse . step } (${ step . command } ): ${ stepResponse . error . message } ` ,
123- hint : stepResponse . error . hint ,
124- diagnosticId : stepResponse . error . diagnosticId ,
125- logPath : stepResponse . error . logPath ,
126- ...( stepResponse . error . retriable === undefined
127- ? { }
128- : { retriable : stepResponse . error . retriable } ) ,
129- ...( stepResponse . error . supportedOn === undefined
130- ? { }
131- : { supportedOn : stepResponse . error . supportedOn } ) ,
132- details : {
133- ...( stepResponse . error . details ?? { } ) ,
134- step : stepResponse . step ,
135- command : step . command ,
136- positionals : step . positionals ,
137- executed : index ,
138- total : steps . length ,
139- partialResults,
140- } ,
141- } ,
142- } ;
119+ return batchStepFailure ( stepResponse , step , {
120+ executedSteps : steps . slice ( 0 , index ) ,
121+ total : steps . length ,
122+ partialResults,
123+ } ) ;
143124 }
144125 partialResults . push ( stepResponse . result ) ;
145126 }
@@ -159,6 +140,47 @@ export async function runBatch(
159140 }
160141}
161142
143+ type BatchStepFailure = Extract < Awaited < ReturnType < typeof runBatchStep > > , { ok : false } > ;
144+
145+ function batchStepFailure (
146+ stepResponse : BatchStepFailure ,
147+ step : NormalizedBatchStep ,
148+ progress : {
149+ executedSteps : readonly NormalizedBatchStep [ ] ;
150+ total : number ;
151+ partialResults : BatchStepResult [ ] ;
152+ } ,
153+ ) : Extract < BatchRunResponse , { ok : false } > {
154+ const { error } = stepResponse ;
155+ return {
156+ ok : false ,
157+ error : {
158+ code : error . code ,
159+ message : `Batch failed at step ${ stepResponse . step } (${ step . command } ): ${ error . message } ` ,
160+ hint : error . hint ,
161+ diagnosticId : error . diagnosticId ,
162+ logPath : error . logPath ,
163+ ...( error . retriable === undefined ? { } : { retriable : error . retriable } ) ,
164+ ...( error . supportedOn === undefined ? { } : { supportedOn : error . supportedOn } ) ,
165+ details : {
166+ ...( error . details ?? { } ) ,
167+ ...( progress . executedSteps . some ( stepMutatesApp ) ? { dispatched : 'unknown' } : { } ) ,
168+ step : stepResponse . step ,
169+ command : step . command ,
170+ positionals : step . positionals ,
171+ executed : progress . executedSteps . length ,
172+ total : progress . total ,
173+ partialResults : progress . partialResults ,
174+ } ,
175+ } ,
176+ } ;
177+ }
178+
179+ /** A batch that executed a mutating step cannot promise that a resend repeats nothing. */
180+ function stepMutatesApp ( step : NormalizedBatchStep ) : boolean {
181+ return resolveCommandRecordingEffect ( step ) === 'mutates-app' ;
182+ }
183+
162184export function validateAndNormalizeBatchSteps (
163185 steps : unknown ,
164186 maxSteps : number ,
0 commit comments