@@ -384,8 +384,11 @@ async def handle_slack_message(
384384 LOGGER .info (f"Existing session { existing_editing_id } status: { session_status } " )
385385
386386 if session_status and session_status .value == "interrupted" :
387- LOGGER .info (f"Session { existing_editing_id } is INTERRUPTED, message already queued" )
388- info_text = "⏳ Previous edit is being interrupted, your request will be processed next."
387+ LOGGER .info (f"Session { existing_editing_id } is INTERRUPTED, queuing new request via RESUME message" )
388+
389+ await send_resume_message (existing_editing_id , [context .text ])
390+
391+ info_text = "⏳ Previous edit is being interrupted, your request has been queued."
389392 return SlackMessageResponse (
390393 response_text = info_text ,
391394 channel = context .channel ,
@@ -396,13 +399,11 @@ async def handle_slack_message(
396399 )
397400
398401 if session_status and session_status .value in ["startup" , "active" , "waiting" ]:
399- if session_status .value in ["startup" , "active" ]:
400- LOGGER .info (
401- f"Interrupting { session_status .value } session { existing_editing_id } for new edit request"
402- )
402+ if session_status .value == "active" :
403+ LOGGER .info (f"Interrupting active session { existing_editing_id } for new edit request" )
403404 interrupt_success = await interrupt_editing_session (existing_editing_id )
404405
405- if not interrupt_success and session_status . value != "waiting" :
406+ if not interrupt_success :
406407 LOGGER .error (f"Failed to interrupt session { existing_editing_id } " )
407408 error_text = "❌ Failed to interrupt the previous edit session. Please try again."
408409 return SlackMessageResponse (
@@ -415,24 +416,83 @@ async def handle_slack_message(
415416 )
416417
417418 if integration .slack_bot_token :
418- if session_status .value == "startup" :
419- interruption_msg = "⚠️ Queued interrupt for starting session - will apply when ready"
420- else :
421- interruption_msg = "⚠️ Interrupted previous edit session to process new request"
422419 try :
423420 await send_slack_message (
424421 channel = context .channel ,
425- text = interruption_msg ,
422+ text = "⚠️ Interrupted previous edit session to process new request" ,
426423 bot_token = integration .slack_bot_token ,
427424 thread_ts = context .thread_ts ,
428425 )
429426 LOGGER .info (f"Posted interruption message to thread { context .thread_ts } " )
430427 except Exception as e :
431428 LOGGER .error (f"Failed to post interruption message: { e } " , exc_info = True )
432- else :
433- LOGGER .info (f"Session { existing_editing_id } is WAITING and ready to resume" )
434429
435- await send_resume_message (existing_editing_id , [context .text ])
430+ await send_resume_message (existing_editing_id , [context .text ])
431+
432+ elif session_status .value == "startup" :
433+ LOGGER .info (f"Interrupting STARTUP session { existing_editing_id } for new edit request" )
434+ interrupt_success = await interrupt_editing_session (existing_editing_id )
435+
436+ if not interrupt_success :
437+ LOGGER .error (f"Failed to interrupt STARTUP session { existing_editing_id } " )
438+ error_text = "❌ Failed to interrupt the previous edit session. Please try again."
439+ return SlackMessageResponse (
440+ response_text = error_text ,
441+ channel = context .channel ,
442+ thread_ts = context .thread_ts ,
443+ bot_token = integration .slack_bot_token ,
444+ query_id = None ,
445+ user_id = context .user ,
446+ )
447+
448+ if integration .slack_bot_token :
449+ try :
450+ await send_slack_message (
451+ channel = context .channel ,
452+ text = "⚠️ Interrupted previous edit session to process new request" ,
453+ bot_token = integration .slack_bot_token ,
454+ thread_ts = context .thread_ts ,
455+ )
456+ LOGGER .info (f"Posted interruption message to thread { context .thread_ts } " )
457+ except Exception as e :
458+ LOGGER .error (f"Failed to post interruption message: { e } " , exc_info = True )
459+
460+ await send_resume_message (existing_editing_id , [context .text ])
461+
462+ return SlackMessageResponse (
463+ response_text = "" ,
464+ channel = context .channel ,
465+ thread_ts = context .thread_ts ,
466+ bot_token = integration .slack_bot_token ,
467+ query_id = None ,
468+ user_id = context .user ,
469+ )
470+
471+ elif session_status .value == "waiting" :
472+ LOGGER .info (f"Session { existing_editing_id } is WAITING, " f"queuing request without interrupting" )
473+
474+ await send_resume_message (existing_editing_id , [context .text ])
475+
476+ if integration .slack_bot_token :
477+ try :
478+ await send_slack_message (
479+ channel = context .channel ,
480+ text = "⏳ Previous edit is waiting - your request has been queued" ,
481+ bot_token = integration .slack_bot_token ,
482+ thread_ts = context .thread_ts ,
483+ )
484+ LOGGER .info (f"Posted queued message to thread { context .thread_ts } " )
485+ except Exception as e :
486+ LOGGER .error (f"Failed to post queued message: { e } " , exc_info = True )
487+
488+ return SlackMessageResponse (
489+ response_text = "" ,
490+ channel = context .channel ,
491+ thread_ts = context .thread_ts ,
492+ bot_token = integration .slack_bot_token ,
493+ query_id = None ,
494+ user_id = context .user ,
495+ )
436496
437497 else :
438498 status_str = session_status .value if session_status else "unknown"
0 commit comments