Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ async def websocket_endpoint(websocket: WebSocket):
await manager.connect(websocket)

# Start keepalive task if not already running
if not hasattr(app, 'keepalive_task'):
if not hasattr(app, 'keepalive_task') or app.keepalive_task.done():
if hasattr(app, 'keepalive_task') and not app.keepalive_task.done():
app.keepalive_task.cancel()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Dead Code Prevents Proper Task Cancellation

The app.keepalive_task.cancel() line is unreachable dead code. The outer if condition allows entry if app.keepalive_task does not exist or is already done. However, the nested if condition, which contains the cancellation logic, requires the task to exist and not be done. These conditions are mutually exclusive, preventing the cancellation from ever executing and potentially leading to uncanceled tasks.

Fix in Cursor Fix in Web

app.keepalive_task = asyncio.create_task(keepalive_task())

while True:
Expand All @@ -213,10 +215,18 @@ async def websocket_endpoint(websocket: WebSocket):
await manager.send_message(client_id, json.dumps({"type": "pong"}))
continue

# Parse JSON message to extract content
try:
parsed_message = json.loads(message)
message_content = parsed_message.get("content", message)
except json.JSONDecodeError:
# If not JSON, treat as plain text
message_content = message

# Process message with RAG agent
try:
response = await asyncio.wait_for(
asyncio.to_thread(rag_agent.chat, message),
asyncio.to_thread(rag_agent.chat, message_content),
timeout=30 # 30 second timeout for RAG processing
)
except asyncio.TimeoutError:
Expand Down
13 changes: 8 additions & 5 deletions mobile/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,14 @@ export default function App() {
}
};

const sendMessage = () => {
if (inputText.trim() && ws.current && ws.current.readyState === WebSocket.OPEN) {
setMessages(prev => [...prev, { type: 'user', content: inputText }]);
ws.current.send(JSON.stringify({ type: 'message', content: inputText }));
setInputText('');
const sendMessage = (message = null) => {
const messageToSend = message || inputText.trim();
if (messageToSend && ws.current && ws.current.readyState === WebSocket.OPEN) {
setMessages(prev => [...prev, { type: 'user', content: messageToSend }]);
ws.current.send(JSON.stringify({ type: 'message', content: messageToSend }));
if (!message) {
setInputText('');
}
setIsTyping(true);
} else {
Alert.alert('Connection Error', 'Cannot send message. Please check your connection.');
Expand Down