From 872d01f8e555c3f10ad27454b0fe2024788f1f3f Mon Sep 17 00:00:00 2001 From: Octopus Date: Sat, 4 Apr 2026 11:23:41 +0800 Subject: [PATCH] fix: return HTTP 500 instead of calling sys.exit(1) on query errors Previously, any unhandled exception during query processing caused the entire backend server to exit via sys.exit(1), making the frontend show 'System offline. Deploy backend first.' until the container was restarted. Also, is_generating was never reset to False on exception, permanently blocking all subsequent queries with 429 responses. - Replace sys.exit(1) with a proper HTTP 500 error response - Move is_generating = False to the finally block so it always resets Fixes #382 --- api.py | 5 ++++- sources/agents/planner_agent.py | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api.py b/api.py index 288e108..56d3154 100755 --- a/api.py +++ b/api.py @@ -278,8 +278,11 @@ async def process_query(request: QueryRequest): return JSONResponse(status_code=200, content=query_resp.jsonify()) except Exception as e: logger.error(f"An error occurred: {str(e)}") - sys.exit(1) + query_resp.answer = f"An error occurred: {str(e)}" + query_resp.reasoning = f"Error: {str(e)}" + return JSONResponse(status_code=500, content=query_resp.jsonify()) finally: + is_generating = False logger.info("Processing finished") if config.getboolean('MAIN', 'save_session'): interaction.save_session() diff --git a/sources/agents/planner_agent.py b/sources/agents/planner_agent.py index 720908c..ff6cba4 100644 --- a/sources/agents/planner_agent.py +++ b/sources/agents/planner_agent.py @@ -264,8 +264,6 @@ class PlannerAgent(Agent): agents_tasks = [] required_infos = None agents_work_result = dict() - answer = "" - self.stop = False self.status_message = "Making a plan..." agents_tasks = await self.make_plan(goal)