From 57efca4f9bc949e7baad03f7cbb8787b694511d9 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 2 Mar 2026 10:37:33 -0500 Subject: [PATCH] fix(thread-safety): lock disc_entries reads/writes in HookServer, remove debug logs --- api_hook_client.py | 1 - api_hooks.py | 7 +++++-- gui_2.py | 2 -- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api_hook_client.py b/api_hook_client.py index 79ef6e4..32ef359 100644 --- a/api_hook_client.py +++ b/api_hook_client.py @@ -74,7 +74,6 @@ class ApiHookClient: def get_session(self) -> dict | None: res = self._make_request('GET', '/api/session') - print(f"RAW SESSION RESPONSE: {res}") return res def get_mma_status(self) -> dict | None: diff --git a/api_hooks.py b/api_hooks.py index 2229b21..53a4383 100644 --- a/api_hooks.py +++ b/api_hooks.py @@ -34,8 +34,10 @@ class HookHandler(BaseHTTPRequestHandler): self.send_response(200) self.send_header('Content-Type', 'application/json') self.end_headers() + with app._disc_entries_lock: + entries_snapshot = list(app.disc_entries) self.wfile.write( - json.dumps({'session': {'entries': app.disc_entries}}). + json.dumps({'session': {'entries': entries_snapshot}}). encode('utf-8')) elif self.path == '/api/performance': self.send_response(200) @@ -211,7 +213,8 @@ class HookHandler(BaseHTTPRequestHandler): self.send_response(500) self.end_headers() elif self.path == '/api/session': - app.disc_entries = data.get('session', {}).get('entries', app.disc_entries) + with app._disc_entries_lock: + app.disc_entries = data.get('session', {}).get('entries', app.disc_entries) self.send_response(200) self.send_header('Content-Type', 'application/json') self.end_headers() diff --git a/gui_2.py b/gui_2.py index ea06d4c..fa4aad6 100644 --- a/gui_2.py +++ b/gui_2.py @@ -792,7 +792,6 @@ class App: with self._disc_entries_lock: self.disc_entries = _parse_history_entries(disc_data.get("history", []), self.disc_roles) self.ai_status = f"discussion: {name}" - sys.stderr.write(f'[DEBUG] Switched to {name}. disc_entries len: {len(self.disc_entries)}\n') def _flush_disc_entries_to_project(self) -> None: history_strings = [project_manager.entry_to_str(e) for e in self.disc_entries] @@ -1069,7 +1068,6 @@ class App: disc_data["last_updated"] = project_manager.now_ts() with self._disc_entries_lock: self.disc_entries.append(item) - print(f'[DEBUG] Added to disc_entries. Current len: {len(self.disc_entries)}') def _handle_approve_script(self) -> None: """Logic for approving a pending script via API hooks."""