Fix logical bugs in event bus and bulk session deletion (#3139)

This commit is contained in:
Muhammad Ikhwan Fathulloh
2026-06-07 22:08:50 +07:00
committed by GitHub
parent b8463e3ac2
commit 2a6921a455
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", []) ids = body.get("ids", [])
except Exception: except Exception:
ids = [] ids = []
deleted_count = 0
for sid in ids: for sid in ids:
try: try:
_verify_session_owner(request, sid, session_manager) _verify_session_owner(request, sid, session_manager)
session_manager.delete_session(sid)
# Enforce "starred" protection consistent with single-session delete
db = SessionLocal() db = SessionLocal()
try: try:
db.query(_CM).filter(_CM.session_id == sid).delete() db_sess = db.query(DbSession).filter(DbSession.id == sid).first()
db.query(DbSession).filter(DbSession.id == sid).delete() if db_sess and db_sess.is_important:
db.commit() continue
except Exception:
db.rollback()
finally: finally:
db.close() db.close()
if session_manager.delete_session(sid):
deleted_count += 1
except Exception: except Exception:
pass pass
return {"deleted": len(ids)} return {"deleted": deleted_count}
@router.delete("/session/{sid}") @router.delete("/session/{sid}")
def delete_session(request: Request, sid: str): 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() db.commit()
# Fire the task # Fire the task
if _task_scheduler: 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})") logger.info(f"Event '{event_name}' triggered task '{task.name}' (every {threshold})")
await _task_scheduler.run_task_now(task.id) await _task_scheduler.run_task_now(task.id)
else: else: