perf(core): Optimize DAG engine, orchestrator loop, and simulations

This commit is contained in:
2026-05-06 15:27:27 -04:00
parent d0aff71430
commit f628e0b29a
4 changed files with 109 additions and 72 deletions
+21 -5
View File
@@ -40,6 +40,8 @@ from src import models
from src.models import Ticket, Track, WorkerContext
from src.file_cache import ASTParser
from pathlib import Path
from src.personas import PersonaManager
from src import paths
from src.dag_engine import TrackDAG, ExecutionEngine
@@ -122,6 +124,7 @@ class ConductorEngine:
self._abort_events: dict[str, threading.Event] = {}
self._pause_event: threading.Event = threading.Event()
self._tier_usage_lock = threading.Lock()
self._dirty: bool = True
def update_usage(self, tier: str, input_tokens: int, output_tokens: int) -> None:
"""Updates token usage for a specific tier."""
@@ -138,6 +141,16 @@ class ConductorEngine:
"""Resumes the pipeline execution."""
self._pause_event.clear()
def approve_task(self, task_id: str) -> None:
"""Manually transition todo to in_progress and mark engine dirty."""
self.engine.approve_task(task_id)
self._dirty = True
def update_task_status(self, task_id: str, status: str) -> None:
"""Force-update ticket status and mark engine dirty."""
self.engine.update_task_status(task_id, status)
self._dirty = True
def kill_worker(self, ticket_id: str) -> None:
"""Sets the abort event for a worker and attempts to join its thread."""
if ticket_id in self._abort_events:
@@ -216,10 +229,14 @@ class ConductorEngine:
if max_ticks is not None and tick_count >= max_ticks:
break
tick_count += 1
# 1. Identify ready tasks
ready_tasks = self.engine.tick()
# 1. Identify ready tasks
if self._dirty:
self._ready_tasks = self.engine.tick()
self._dirty = False
ready_tasks = self._ready_tasks
# 2. Check for completion or blockage
if not ready_tasks:
all_done = all(t.status == "completed" for t in self.track.tickets)
if all_done:
@@ -404,8 +421,6 @@ def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files:
persona_tool_preset = None
persona = None
if context.persona_id:
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)
try:
personas = pm.load_all()
@@ -587,6 +602,7 @@ def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files:
_in_tokens = sum(e.get("payload", {}).get("usage", {}).get("input_tokens", 0) for e in _resp_entries)
_out_tokens = sum(e.get("payload", {}).get("usage", {}).get("output_tokens", 0) for e in _resp_entries)
engine.update_usage("Tier 3", _in_tokens, _out_tokens)
engine._dirty = True
if "BLOCKED" in response.upper():
ticket.mark_blocked(response)
else: