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
This commit is contained in:
Octopus
2026-04-04 11:23:41 +08:00
parent 7cde1549b2
commit 872d01f8e5
2 changed files with 4 additions and 3 deletions
+4 -1
View File
@@ -278,8 +278,11 @@ async def process_query(request: QueryRequest):
return JSONResponse(status_code=200, content=query_resp.jsonify()) return JSONResponse(status_code=200, content=query_resp.jsonify())
except Exception as e: except Exception as e:
logger.error(f"An error occurred: {str(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: finally:
is_generating = False
logger.info("Processing finished") logger.info("Processing finished")
if config.getboolean('MAIN', 'save_session'): if config.getboolean('MAIN', 'save_session'):
interaction.save_session() interaction.save_session()
-2
View File
@@ -264,8 +264,6 @@ class PlannerAgent(Agent):
agents_tasks = [] agents_tasks = []
required_infos = None required_infos = None
agents_work_result = dict() agents_work_result = dict()
answer = ""
self.stop = False
self.status_message = "Making a plan..." self.status_message = "Making a plan..."
agents_tasks = await self.make_plan(goal) agents_tasks = await self.make_plan(goal)