diff --git a/bot.py b/bot.py index e13f766..0cf2b2b 100644 --- a/bot.py +++ b/bot.py @@ -1475,6 +1475,8 @@ class Bot: event_id = event.reacts_to reaction_key = event.key + logger.info("Reaction received: key=%s reacts_to=%s sender=%s", reaction_key, event_id, event.sender) + # Check if this reaction is for a pipeline approval if not self.cron_scheduler: return @@ -1482,8 +1484,14 @@ class Bot: from pipelines.approval import reaction_to_response response = reaction_to_response(reaction_key) if not response: + logger.debug("Reaction key %s not an approval response", reaction_key) return + logger.info("Approval reaction: %s -> %s (tracked events: %s, active futures: %s)", + event_id, response, + list(self._pipeline_approval_events.keys()), + list(self.cron_scheduler.pipeline_engine._approval_futures.keys())) + # Look up execution by approval event ID execution_id = self._pipeline_approval_events.get(event_id) if execution_id: @@ -1492,10 +1500,13 @@ class Bot: self._pipeline_approval_events.pop(event_id, None) logger.info("Pipeline approval resolved: %s -> %s", execution_id, response) return + else: + logger.warning("Failed to resolve approval %s (future not found or already done)", execution_id) # If not in local cache, check pending approvals from portal try: pending = await self.cron_scheduler._pipeline_state.fetch_pending_approvals() + logger.info("Checking %d pending approvals from portal for event %s", len(pending), event_id) for execution in pending: if execution.get("approvalMsgId") == event_id: eid = execution["id"] @@ -1504,6 +1515,8 @@ class Bot: if resolved: self._pipeline_approval_events.pop(event_id, None) logger.info("Pipeline approval resolved (from portal): %s -> %s", eid, response) + else: + logger.warning("Portal found execution %s but future not active", eid) break except Exception: logger.debug("Failed to check pending approvals for reaction", exc_info=True)