fix: 3 critical autonomous engine & mood system bugs

1. Momentum cliff at 10 messages (P0): The conversation momentum formula
   had a discontinuity where the 10th message caused momentum to DROP from
   0.9 to 0.5. Replaced with a smooth log1p curve that monotonically
   increases (0→0→0.20→0.32→...→0.70→0.89→1.0 at 30 msgs).

2. Neutral keywords overriding all moods (P0): detect_mood_shift() checked
   neutral early with generic keywords (okay, sure, hmm) that matched
   almost any response, constantly resetting mood to neutral. Now: all
   specific moods are scored by match count first (best-match wins),
   neutral is only checked as fallback and requires 2+ keyword matches.

3. Uncancellable delayed_wakeup tasks (P0): Fire-and-forget sleep tasks
   could stack and overwrite mood state after manual wake-up. Added a
   centralized wakeup task registry in ServerManager with automatic
   cancellation on manual wake or new sleep cycle.
This commit is contained in:
2026-02-20 15:37:57 +02:00
parent 2f0d430c35
commit 422366df4c
4 changed files with 97 additions and 46 deletions

View File

@@ -14,6 +14,7 @@ from api import app
from config import CONFIG, SECRETS, validate_config, print_config_summary
from server_manager import server_manager
from config_manager import config_manager
from utils.scheduled import (
send_monday_video
)
@@ -106,7 +107,6 @@ async def on_ready():
restore_bipolar_mode_on_startup()
# Restore runtime settings (language, debug flags, etc.) from config_runtime.yaml
from config_manager import config_manager
config_manager.restore_runtime_settings()
# Initialize DM interaction analyzer
@@ -709,15 +709,7 @@ async def on_message(message):
if detected == "asleep":
server_manager.set_server_sleep_state(message.guild.id, True)
# Schedule wake-up after 1 hour
async def delayed_wakeup():
await asyncio.sleep(3600) # 1 hour
server_manager.set_server_sleep_state(message.guild.id, False)
server_manager.set_server_mood(message.guild.id, "neutral")
await update_server_nickname(message.guild.id)
logger.info(f"🌅 Server {message.guild.name} woke up from auto-sleep")
globals.client.loop.create_task(delayed_wakeup())
server_manager.schedule_wakeup_task(message.guild.id, delay_seconds=3600)
else:
logger.error(f"No server config found for guild {message.guild.id}, skipping mood detection")
except Exception as e: