fix(thread-safety): lock disc_entries reads/writes in HookServer, remove debug logs

This commit is contained in:
2026-03-02 10:37:33 -05:00
parent eb293f3c96
commit 57efca4f9b
3 changed files with 5 additions and 5 deletions

View File

@@ -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:

View File

@@ -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()

View File

@@ -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."""