@@ -3505,6 +3505,7 @@ def _check_signal_id_duplicate(signal_id: str, signal: str, request_id: str) ->
35053505def webhook (payload : WebhookPayload ):
35063506 """Main webhook endpoint for TradingView alerts."""
35073507 request_id = str (uuid .uuid4 ())[:8 ]
3508+ confirmed_conf_key = None
35083509
35093510 try :
35103511 global last_slot , _duplicate_signals_count
@@ -3586,6 +3587,8 @@ def webhook(payload: WebhookPayload):
35863587 # confirmed -> continue pipeline
35873588 if status == "confirmed" :
35883589 logger .info (f"[{ request_id } ] confirmation_passed: key={ conf_key } " )
3590+ # remember confirmed key for potential cleanup if later blocked
3591+ confirmed_conf_key = conf_key
35893592 except Exception :
35903593 logger .exception (f"[{ request_id } ] confirmation_store error, continuing without confirmation" )
35913594 except Exception :
@@ -3732,6 +3735,13 @@ def webhook(payload: WebhookPayload):
37323735 global _blocked_session_ny , _blocked_ny_no_botmove
37333736 _blocked_session_ny += 1 # Legacy counter (backward compatibility)
37343737 _blocked_ny_no_botmove += 1 # New specific counter
3738+ # If this signal had previously passed confirmation, clear it to avoid stuck keys
3739+ try :
3740+ if confirmed_conf_key :
3741+ cleared = _confirmation_store .clear (confirmed_conf_key )
3742+ logger .info (f"[{ request_id } ] confirmation_cleared_after_block: key={ confirmed_conf_key } cleared={ cleared } " )
3743+ except Exception :
3744+ logger .exception (f"[{ request_id } ] error clearing confirmation key { confirmed_conf_key } " )
37353745 logger .info (
37363746 f"[{ request_id } ] BLOCKED: NY session without botMove or mr "
37373747 f"(botMove={ bot_move } , mr={ mr_flag } )"
@@ -4289,6 +4299,13 @@ def webhook(payload: WebhookPayload):
42894299 logger .info (
42904300 f"[{ request_id } ] MQ_REJECT: reason={ reason_mq } details={ details_mq } time_to_end={ time_to_end } "
42914301 )
4302+ # Clear pending confirmation if this request had already confirmed earlier
4303+ try :
4304+ if confirmed_conf_key :
4305+ cleared = _confirmation_store .clear (confirmed_conf_key )
4306+ logger .info (f"[{ request_id } ] confirmation_cleared_after_mq_reject: key={ confirmed_conf_key } cleared={ cleared } " )
4307+ except Exception :
4308+ logger .exception (f \" [{request_id }] error clearing confirmation key {confirmed_conf_key }\" )
42924309 return {
42934310 "ok" : True ,
42944311 "ignored" : True ,
0 commit comments