fix(P1): 6 priority-1 bug fixes for autonomous engine and mood system
#4 Sleep/mood desync — set_server_mood() now clears is_sleeping when mood changes away from 'asleep', preventing ghost-sleep state. #5 Race condition in _check_and_act — added per-guild asyncio.Lock so overlapping ticks + message-triggered calls cannot fire concurrently. #6 Class-level attrs on ServerConfig — sleepy_responses_left, angry_wakeup_timer, and forced_angry_until are now proper dataclass fields with defaults, so asdict()/from_dict() round-trip correctly. Also strips unknown keys in from_dict() to survive schema changes. #7 Persistence decay_factor crash — initialise decay_factor = 1.0 before the loop so empty-server or zero-downtime paths don't raise NameError. #8 Double record_action — removed the redundant call in autonomous_tick_v2(); only _check_and_act records the action now. #9 Engine mood desync — on_mood_change() is now called inside set_server_mood() (single source of truth) and removed from 4 call-sites in api.py, moods.py, and server_manager wakeup task.
This commit is contained in:
@@ -270,7 +270,7 @@ async def rotate_server_mood(guild_id: int):
|
||||
|
||||
# Check for forced angry mode and clear if expired
|
||||
if server_config.forced_angry_until:
|
||||
now = datetime.datetime.utcnow()
|
||||
now = datetime.datetime.utcnow().isoformat()
|
||||
if now < server_config.forced_angry_until: return
|
||||
else: server_config.forced_angry_until = None
|
||||
|
||||
@@ -292,13 +292,6 @@ async def rotate_server_mood(guild_id: int):
|
||||
|
||||
server_manager.set_server_mood(guild_id, new_mood_name, load_mood_description(new_mood_name))
|
||||
|
||||
# V2: Notify autonomous engine of mood change
|
||||
try:
|
||||
from utils.autonomous import on_mood_change
|
||||
on_mood_change(guild_id, new_mood_name)
|
||||
except Exception as mood_notify_error:
|
||||
logger.error(f"Failed to notify autonomous engine of mood change: {mood_notify_error}")
|
||||
|
||||
# If transitioning to asleep, set up auto-wake via centralized registry
|
||||
if new_mood_name == "asleep":
|
||||
server_manager.set_server_sleep_state(guild_id, True)
|
||||
|
||||
Reference in New Issue
Block a user