fix(bridge): 4 race condition fixes for approval lifecycle
This commit is contained in:
8
bot.py
8
bot.py
@@ -181,6 +181,7 @@ class GravityBot(commands.Bot):
|
||||
self.guild: discord.Guild | None = None
|
||||
self.auto_approve_projects: set[str] = set() # projects with auto-approve enabled
|
||||
self._processed_message_ids: set[int] = set() # dedup for Gateway event replay
|
||||
self._approval_messages: dict[str, int] = {} # FIX #4: request_id → discord message_id (for auto_resolved lookup)
|
||||
self.gateway = None # Set by main.py in gateway mode
|
||||
|
||||
def _write_command(self, project: str, text: str, **kwargs):
|
||||
@@ -615,7 +616,9 @@ class GravityBot(commands.Bot):
|
||||
try:
|
||||
data = json.loads(f.read_text(encoding="utf-8-sig"))
|
||||
if data.get("status") == "auto_resolved":
|
||||
msg_id = data.get("discord_message_id", 0)
|
||||
rid = data.get("request_id", "")
|
||||
# FIX #5: Use _approval_messages as fallback when discord_message_id is 0
|
||||
msg_id = data.get("discord_message_id", 0) or self._approval_messages.get(rid, 0)
|
||||
project = data.get("project_name", Config.PROJECT_NAME)
|
||||
if msg_id:
|
||||
channel = await self._get_channel(project)
|
||||
@@ -634,6 +637,8 @@ class GravityBot(commands.Bot):
|
||||
f.unlink()
|
||||
self._deferred_ids.pop(data.get("request_id", ""), None)
|
||||
self._sent_commands.pop(data.get("request_id", ""), None)
|
||||
self._approval_messages.pop(data.get("request_id", ""), None)
|
||||
self._sent_approval_ids.discard(data.get("request_id", ""))
|
||||
except (json.JSONDecodeError, OSError):
|
||||
pass
|
||||
|
||||
@@ -765,6 +770,7 @@ class GravityBot(commands.Bot):
|
||||
pass
|
||||
|
||||
logger.info(f"Sent approval request: {request.request_id[:12]}")
|
||||
self._approval_messages[request.request_id] = msg.id # FIX #4: Track msg_id for auto_resolved lookup
|
||||
|
||||
# ─── Discord → IDE Text Relay ─────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user