Fix logical bugs in event bus and bulk session deletion

This commit is contained in:
Muhammad-Ikhwan-Fathulloh
2026-06-07 01:38:33 +07:00
parent eb840459f5
commit e8106f7c7c
2 changed files with 10 additions and 13 deletions
+10 -7
View File
@@ -543,22 +543,25 @@ def setup_session_routes(session_manager: SessionManager, config: dict, webhook_
ids = body.get("ids", [])
except Exception:
ids = []
deleted_count = 0
for sid in ids:
try:
_verify_session_owner(request, sid, session_manager)
session_manager.delete_session(sid)
# Enforce "starred" protection consistent with single-session delete
db = SessionLocal()
try:
db.query(_CM).filter(_CM.session_id == sid).delete()
db.query(DbSession).filter(DbSession.id == sid).delete()
db.commit()
except Exception:
db.rollback()
db_sess = db.query(DbSession).filter(DbSession.id == sid).first()
if db_sess and db_sess.is_important:
continue
finally:
db.close()
if session_manager.delete_session(sid):
deleted_count += 1
except Exception:
pass
return {"deleted": len(ids)}
return {"deleted": deleted_count}
@router.delete("/session/{sid}")
def delete_session(request: Request, sid: str):
-6
View File
@@ -105,12 +105,6 @@ async def _handle_event(event_name: str, owner: Optional[str] = None):
db.commit()
# Fire the task
if _task_scheduler:
if task.next_run and task.next_run > datetime.utcnow():
logger.info(
f"Event '{event_name}' reached task '{task.name}', "
f"but it is already deferred until {task.next_run}"
)
continue
logger.info(f"Event '{event_name}' triggered task '{task.name}' (every {threshold})")
await _task_scheduler.run_task_now(task.id)
else: