fix(agent-office): 코드 리뷰 Critical/Important 이슈 수정

- REST 404 응답을 HTTPException으로 변경 (tuple 반환 버그)
- MusicAgent 폴링을 asyncio.create_task로 비동기화 (이벤트 루프 블로킹 해소)
- WebSocket JSON 파싱 에러 핸들링 추가
- StockAgent add_alert 파라미터 검증 추가
- 미사용 의존성 제거 (requests, python-telegram-bot)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 09:08:58 +09:00
parent 3a63bfac15
commit 6922217da6
4 changed files with 16 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
import os
import json
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect
from fastapi.middleware.cors import CORSMiddleware
from .config import CORS_ALLOW_ORIGINS
@@ -48,7 +48,10 @@ async def websocket_endpoint(ws: WebSocket):
}, ensure_ascii=False))
while True:
data = await ws.receive_text()
msg = json.loads(data)
try:
msg = json.loads(data)
except json.JSONDecodeError:
continue
await _handle_ws_message(msg)
except WebSocketDisconnect:
pass
@@ -86,7 +89,7 @@ def list_agents():
def agent_detail(agent_id: str):
config = get_agent_config(agent_id)
if not config:
return {"error": "Agent not found"}, 404
raise HTTPException(status_code=404, detail="Agent not found")
agent = get_agent(agent_id)
state_info = {"state": agent.state, "detail": agent.state_detail} if agent else {}
return {**config, **state_info}
@@ -114,7 +117,7 @@ def pending_tasks():
def task_detail(task_id: str):
task = get_task(task_id)
if not task:
return {"error": "Task not found"}, 404
raise HTTPException(status_code=404, detail="Task not found")
return task
@app.post("/api/agent-office/command")