fix: asyncio.Lock on channel create + PROJECT_NAME in .env.example
This commit is contained in:
@@ -10,5 +10,8 @@ BRAIN_PATH=C:\Users\Certes\.gemini\antigravity\brain
|
||||
# 세션 활성 판단: 마지막 파일 변경으로부터 이 시간(초) 이내면 활성
|
||||
ACTIVE_TIMEOUT_SECONDS=300
|
||||
|
||||
# Project name (used for Discord channel: AG-{PROJECT_NAME})
|
||||
PROJECT_NAME=gravity_control
|
||||
|
||||
# Watcher Settings
|
||||
DEBOUNCE_SECONDS=2
|
||||
|
||||
10
bot.py
10
bot.py
@@ -97,6 +97,7 @@ class GravityBot(commands.Bot):
|
||||
self.session_status_messages: dict[str, int] = {} # conv_id → msg_id
|
||||
self._sent_approval_ids: set[str] = set()
|
||||
self._ready_event = asyncio.Event()
|
||||
self._channel_lock = asyncio.Lock() # Prevents double-create race
|
||||
self.bridge = BridgeProtocol()
|
||||
self.session_category: discord.CategoryChannel | None = None
|
||||
self.guild: discord.Guild | None = None
|
||||
@@ -187,12 +188,17 @@ class GravityBot(commands.Bot):
|
||||
async def _get_project_channel(self) -> discord.TextChannel:
|
||||
"""Get the project channel. Create if it doesn't exist yet.
|
||||
|
||||
Thread-safe: only ONE channel will ever be created because
|
||||
self.project_channel acts as a singleton guard.
|
||||
Uses asyncio.Lock to prevent race between event processor
|
||||
and approval scanner both creating channels simultaneously.
|
||||
"""
|
||||
if self.project_channel:
|
||||
return self.project_channel
|
||||
|
||||
async with self._channel_lock:
|
||||
# Double-check after acquiring lock
|
||||
if self.project_channel:
|
||||
return self.project_channel
|
||||
|
||||
# Create the channel
|
||||
try:
|
||||
self.project_channel = await self.guild.create_text_channel(
|
||||
|
||||
Reference in New Issue
Block a user