perf(entropy): Fix nested imports in hot paths
Hoisted imports from inside frequently-called functions to module level: app_controller.py: - Added traceback and inspect at module level - Removed 3 nested traceback imports from exception handlers gui_2.py: - Added traceback at module level - Removed nested traceback import from _gui_func exception handler - Kept uvicorn lazy-loaded (only for --headless mode) multi_agent_conductor.py: - Removed unused 'import sys' from run() - Removed redundant nested imports (already at module level) Also adds audit scripts and entropy findings documentation.
This commit is contained in:
@@ -2,8 +2,10 @@ import threading
|
||||
import time
|
||||
import copy
|
||||
import sys
|
||||
import traceback
|
||||
import os
|
||||
import re
|
||||
import inspect
|
||||
from typing import Any, List, Dict, Optional, Callable
|
||||
from pathlib import Path
|
||||
from src import workspace_manager
|
||||
@@ -865,7 +867,6 @@ class AppController:
|
||||
elif item == "btn_mma_load_track":
|
||||
self._cb_load_track(str(user_data or ""))
|
||||
elif item in self._clickable_actions:
|
||||
import inspect
|
||||
func = self._clickable_actions[item]
|
||||
try:
|
||||
sig = inspect.signature(func)
|
||||
@@ -974,7 +975,6 @@ class AppController:
|
||||
self.mma_streams[stream_id] = ""
|
||||
self.mma_streams[stream_id] += f"[BEAD UPDATE] {bead_id} -> status: {status}\n"
|
||||
except Exception as e:
|
||||
import traceback
|
||||
sys.stderr.write(f"[DEBUG] Error executing GUI task: {e}\n{traceback.format_exc()}\n")
|
||||
sys.stderr.flush()
|
||||
print(f"Error executing GUI task: {e}")
|
||||
@@ -1642,7 +1642,6 @@ class AppController:
|
||||
sys.stderr.flush()
|
||||
self.event_queue.put("response", {"text": e.ui_message(), "status": "error", "role": "Vendor API"})
|
||||
except Exception as e:
|
||||
import traceback
|
||||
sys.stderr.write(f"[DEBUG] _handle_request_event ERROR: {e}\n{traceback.format_exc()}\n")
|
||||
sys.stderr.flush()
|
||||
self.event_queue.put("response", {"text": f"ERROR: {e}", "status": "error", "role": "System"})
|
||||
@@ -2642,7 +2641,6 @@ class AppController:
|
||||
sys.stderr.write("[DEBUG] Enqueued user_request event\n")
|
||||
sys.stderr.flush()
|
||||
except Exception as e:
|
||||
import traceback
|
||||
sys.stderr.write(f"[DEBUG] _do_generate ERROR: {e}\n{traceback.format_exc()}\n")
|
||||
sys.stderr.flush()
|
||||
self._set_status(f"generate error: {e}")
|
||||
|
||||
+1
-1
@@ -35,6 +35,7 @@ from src import thinking_parser
|
||||
import re
|
||||
import difflib
|
||||
import subprocess
|
||||
import traceback
|
||||
if sys.platform == "win32":
|
||||
import win32gui
|
||||
import win32con
|
||||
@@ -1319,7 +1320,6 @@ class App:
|
||||
imgui.end_popup()
|
||||
except Exception as e:
|
||||
print(f"ERROR in _gui_func: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
if pushed_prior_tint:
|
||||
|
||||
@@ -218,7 +218,6 @@ class ConductorEngine:
|
||||
md_content: The full markdown context (history + files) for AI workers.
|
||||
max_ticks: Optional limit on number of iterations (for testing).
|
||||
"""
|
||||
import sys
|
||||
tick_count = 0
|
||||
while True:
|
||||
if self._pause_event.is_set():
|
||||
@@ -282,10 +281,7 @@ class ConductorEngine:
|
||||
else:
|
||||
# Check if ticket has a persona with preferred_models
|
||||
if ticket.persona_id:
|
||||
# Try to load preferred_models from persona
|
||||
try:
|
||||
from src.personas import PersonaManager
|
||||
from src import paths
|
||||
pm = PersonaManager(Path(paths.get_project_personas_path(Path.cwd())) if paths.get_project_personas_path(Path.cwd()).exists() else None)
|
||||
personas = pm.load_all()
|
||||
if ticket.persona_id in personas:
|
||||
|
||||
Reference in New Issue
Block a user