(data: StreamErrorPayload)
| 4409 | } |
| 4410 | |
| 4411 | private async handleStreamError(data: StreamErrorPayload): Promise<void> { |
| 4412 | this.setTurnPhase(TurnPhase.COMPLETING); |
| 4413 | |
| 4414 | this.clearLiveUsageState(); |
| 4415 | const hadCompactionRequest = this.activeCompactionRequest !== undefined; |
| 4416 | if ( |
| 4417 | await this.maybeRetryCompactionOnContextExceeded({ |
| 4418 | messageId: data.messageId, |
| 4419 | errorType: data.errorType, |
| 4420 | }) |
| 4421 | ) { |
| 4422 | return; // retry set PREPARING |
| 4423 | } |
| 4424 | |
| 4425 | if ( |
| 4426 | await this.maybeRetryWithoutPostCompactionOnContextExceeded({ |
| 4427 | messageId: data.messageId, |
| 4428 | errorType: data.errorType, |
| 4429 | }) |
| 4430 | ) { |
| 4431 | return; // retry set PREPARING |
| 4432 | } |
| 4433 | |
| 4434 | if ( |
| 4435 | await this.maybeHardRestartExecSubagentOnContextExceeded({ |
| 4436 | messageId: data.messageId, |
| 4437 | errorType: data.errorType, |
| 4438 | }) |
| 4439 | ) { |
| 4440 | return; // retry set PREPARING |
| 4441 | } |
| 4442 | |
| 4443 | // Terminal error — no retry succeeded |
| 4444 | const failedUserMessageId = this.activeStreamUserMessageId; |
| 4445 | const failureType = data.errorType ?? "unknown"; |
| 4446 | const streamErrorMessage = createStreamErrorMessage(data); |
| 4447 | this.setTerminalStreamLifecycle("failed"); |
| 4448 | this.terminalStreamError = streamErrorMessage; |
| 4449 | await this.restoreGoalAccountingSnapshot(); |
| 4450 | this.activeCompactionRequest = undefined; |
| 4451 | this.resetActiveStreamState(); |
| 4452 | |
| 4453 | if (hadCompactionRequest && !this.disposed) { |
| 4454 | this.clearQueue(); |
| 4455 | } |
| 4456 | |
| 4457 | await this.handleStreamFailureForAutoRetry({ |
| 4458 | type: failureType, |
| 4459 | message: data.error, |
| 4460 | }); |
| 4461 | await this.updateStartupAutoRetryAbandonFromFailure(failureType, failedUserMessageId); |
| 4462 | this.resolveStreamErrorRecoveryDecision(); |
| 4463 | |
| 4464 | this.emitChatEvent(streamErrorMessage); |
| 4465 | this.setTurnPhase(TurnPhase.IDLE); |
| 4466 | } |
| 4467 | |
| 4468 | private attachAiListeners(): void { |
no test coverage detected