fix(acp): handle all InvalidStreamError types gracefully in prompt (#24540)

This commit is contained in:
Sri Pasumarthi
2026-04-02 10:16:36 -07:00
committed by GitHub
parent efbddcbf98
commit b80234aa3e
2 changed files with 30 additions and 1 deletions

View File

@@ -875,6 +875,32 @@ describe('Session', () => {
expect(result).toMatchObject({ stopReason: 'end_turn' });
});
it('should handle prompt with no finish reason (InvalidStreamError)', async () => {
mockChat.sendMessageStream.mockRejectedValue(
new InvalidStreamError('No finish reason', 'NO_FINISH_REASON'),
);
const result = await session.prompt({
sessionId: 'session-1',
prompt: [{ type: 'text', text: 'Hi' }],
});
expect(mockChat.sendMessageStream).toHaveBeenCalled();
expect(result).toMatchObject({ stopReason: 'end_turn' });
});
it('should handle prompt with no finish reason (NO_FINISH_REASON anomaly)', async () => {
mockChat.sendMessageStream.mockRejectedValue({ type: 'NO_FINISH_REASON' });
const result = await session.prompt({
sessionId: 'session-1',
prompt: [{ type: 'text', text: 'Hi' }],
});
expect(mockChat.sendMessageStream).toHaveBeenCalled();
expect(result).toMatchObject({ stopReason: 'end_turn' });
});
it('should handle /memory command', async () => {
const handleCommandSpy = vi
.spyOn(

View File

@@ -863,7 +863,10 @@ export class Session {
(error &&
typeof error === 'object' &&
'type' in error &&
error.type === 'NO_RESPONSE_TEXT')
(error.type === 'NO_RESPONSE_TEXT' ||
error.type === 'NO_FINISH_REASON' ||
error.type === 'MALFORMED_FUNCTION_CALL' ||
error.type === 'UNEXPECTED_TOOL_CALL'))
) {
// The stream ended with an empty response or malformed tool call.
// Treat this as a graceful end to the model's turn rather than a crash.