fix: channel duplication root fix - ready gate + conv_id-first + Discord API search + hash pre-init

This commit is contained in:
2026-03-07 13:09:05 +09:00
parent de6f1c7ffd
commit 7c081e70b5
2 changed files with 44 additions and 14 deletions

View File

@@ -52,13 +52,30 @@ class BrainEventHandler(FileSystemEventHandler):
self._initialize_known_sessions()
def _initialize_known_sessions(self):
"""Scan existing brain directories to establish baseline (no events emitted)."""
"""Scan existing brain directories to establish baseline (no events emitted).
Also pre-loads content hashes for watched files to prevent spurious events.
"""
brain_path = Config.BRAIN_PATH
hash_count = 0
if brain_path.exists():
for entry in brain_path.iterdir():
if entry.is_dir() and self._is_conversation_id(entry.name):
self._known_sessions.add(entry.name)
logger.info(f"Found {len(self._known_sessions)} existing sessions at startup")
# Pre-load content hashes for watched files
for watched in Config.WATCHED_FILES:
fpath = entry / watched
if fpath.exists():
try:
content = fpath.read_text(encoding="utf-8")
h = hashlib.md5(content.encode()).hexdigest()
self._content_hashes[str(fpath)] = h
hash_count += 1
except (OSError, UnicodeDecodeError):
pass
logger.info(
f"Found {len(self._known_sessions)} existing sessions, "
f"pre-loaded {hash_count} content hashes"
)
def _is_conversation_id(self, name: str) -> bool:
parts = name.split("-")