@@ -205,41 +205,37 @@ function getErrorCauseCandidates(err: Error): unknown[] {
205205 return candidates ;
206206}
207207
208+ function isTerminalAbortCandidate ( candidate : unknown ) : boolean {
209+ if ( typeof candidate === "string" ) {
210+ return isTerminalAbortReasonString ( candidate ) ;
211+ }
212+ if ( ! ( candidate instanceof Error ) ) {
213+ return false ;
214+ }
215+ if ( isAgentRunRestartAbortReason ( candidate ) ) {
216+ return true ;
217+ }
218+ if ( candidate . name === "TimeoutError" ) {
219+ return true ;
220+ }
221+ if ( candidate . name === "ClientDisconnectError" ) {
222+ return true ;
223+ }
224+ return isTerminalAbortReasonString ( candidate . message ) ;
225+ }
226+
208227function isTerminalAbort ( signal : AbortSignal | undefined ) : boolean {
209228 if ( ! signal ?. aborted ) {
210229 return false ;
211230 }
212231 const reason = signal . reason ;
213232
214- if ( typeof reason === "string" ) {
215- return isTerminalAbortReasonString ( reason ) ;
216- }
217-
218233 if ( reason instanceof Error ) {
219- if ( isAgentRunRestartAbortReason ( reason ) ) {
220- return true ;
221- }
222234 const candidates : unknown [ ] = [ reason , ...getErrorCauseCandidates ( reason ) ] ;
223- for ( const candidate of candidates ) {
224- if ( ! ( candidate instanceof Error ) ) {
225- continue ;
226- }
227- if ( isAgentRunRestartAbortReason ( candidate ) ) {
228- return true ;
229- }
230- if ( candidate . name === "TimeoutError" ) {
231- return true ;
232- }
233- if ( candidate . name === "ClientDisconnectError" ) {
234- return true ;
235- }
236- if ( typeof candidate . message === "string" && isTerminalAbortReasonString ( candidate . message ) ) {
237- return true ;
238- }
239- }
235+ return candidates . some ( isTerminalAbortCandidate ) ;
240236 }
241237
242- return false ;
238+ return isTerminalAbortCandidate ( reason ) ;
243239}
244240
245241function isTerminalAbortFromError ( err : unknown ) : boolean {
@@ -261,30 +257,7 @@ function isTerminalAbortFromError(err: unknown): boolean {
261257 if ( ! isOpenClawAbortableWrapper ( err ) ) {
262258 return false ;
263259 }
264- for ( const candidate of causeCandidates ) {
265- if ( typeof candidate === "string" ) {
266- if ( isTerminalAbortReasonString ( candidate ) ) {
267- return true ;
268- }
269- continue ;
270- }
271- if ( ! ( candidate instanceof Error ) ) {
272- continue ;
273- }
274- if ( isAgentRunRestartAbortReason ( candidate ) ) {
275- return true ;
276- }
277- if ( candidate . name === "TimeoutError" ) {
278- return true ;
279- }
280- if ( candidate . name === "ClientDisconnectError" ) {
281- return true ;
282- }
283- if ( typeof candidate . message === "string" && isTerminalAbortReasonString ( candidate . message ) ) {
284- return true ;
285- }
286- }
287- return false ;
260+ return causeCandidates . some ( isTerminalAbortCandidate ) ;
288261}
289262
290263function isCallerAbortSignal ( signal : AbortSignal | undefined ) : boolean {
0 commit comments