AOSSIE-Org / AOSSIE-Org/Ell-ena

BUG:AI requests can hang indefinitely due to missing timeout handling

Abierto
#269 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Dart
Estrellas
54
Forks
110
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

Description

The Gemini API requests in lib/services/ai_service.dart currently do not implement timeout handling for HTTP requests.

If the network becomes unstable or the Gemini API becomes unresponsive, the application may continue waiting indefinitely for a response.

This issue affects the following methods:

generateChatResponse()
handleToolResponse()
Expected Behavior

AI requests should fail gracefully after a reasonable timeout duration and provide an appropriate error message to the user.

Actual Behavior

Requests may remain pending indefinitely under unstable or interrupted network conditions, potentially causing:

infinite loading states
frozen AI chat interactions
blocked user workflow
repeated retry attempts by users
Steps to Reproduce
Open the AI chat feature
Send a message to trigger a Gemini API request
Disable or interrupt the internet connection while the request is in progress
Observe that the request may never complete
Root Cause

The HTTP requests use http.post() without a .timeout() constraint, allowing requests to wait indefinitely if the server or network does not respond.

Suggested Fix

Add timeout handling to the HTTP requests:

await http.post(...).timeout(
const Duration(seconds: 30),
);

Additionally, handle TimeoutException separately to provide graceful error feedback to the user.

Possible Impact
Poor user experience during unstable connectivity
Infinite loading indicators
Unresponsive AI chat behavior
Increased likelihood of duplicate retry requests

### Record

- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.