fix(conductor): Apply review suggestions for track 'mma_data_architecture_dag_engine'
This commit is contained in:
@@ -73,9 +73,11 @@ class ConductorEngine:
|
||||
except KeyError as e:
|
||||
print(f"Missing required field in ticket definition: {e}")
|
||||
|
||||
async def run(self):
|
||||
async def run(self, md_content: str = ""):
|
||||
"""
|
||||
Main execution loop using the DAG engine.
|
||||
Args:
|
||||
md_content: The full markdown context (history + files) for AI workers.
|
||||
"""
|
||||
await self._push_state(status="running", active_tier="Tier 2 (Tech Lead)")
|
||||
|
||||
@@ -91,7 +93,7 @@ class ConductorEngine:
|
||||
await self._push_state(status="done", active_tier=None)
|
||||
else:
|
||||
# Check if any tasks are in-progress or could be ready
|
||||
if any(t.status == "running" for t in self.track.tickets):
|
||||
if any(t.status == "in_progress" for t in self.track.tickets):
|
||||
# Wait for async tasks to complete
|
||||
await asyncio.sleep(1)
|
||||
continue
|
||||
@@ -101,14 +103,12 @@ class ConductorEngine:
|
||||
break
|
||||
|
||||
# 3. Process ready tasks
|
||||
loop = asyncio.get_event_loop()
|
||||
for ticket in ready_tasks:
|
||||
# If auto_queue is on and step_mode is off, engine.tick() already marked it 'running'
|
||||
# If auto_queue is on and step_mode is off, engine.tick() already marked it 'in_progress'
|
||||
# but we need to verify and handle the lifecycle.
|
||||
if ticket.status != "running" and not ticket.step_mode and self.engine.auto_queue:
|
||||
# This shouldn't happen with current ExecutionEngine.tick() but for safety:
|
||||
ticket.status = "running"
|
||||
|
||||
if ticket.status == "running":
|
||||
if ticket.status == "in_progress" or (not ticket.step_mode and self.engine.auto_queue):
|
||||
ticket.status = "in_progress"
|
||||
print(f"Executing ticket {ticket.id}: {ticket.description}")
|
||||
await self._push_state(active_tier=f"Tier 3 (Worker): {ticket.id}")
|
||||
|
||||
@@ -117,8 +117,20 @@ class ConductorEngine:
|
||||
model_name="gemini-2.5-flash-lite",
|
||||
messages=[]
|
||||
)
|
||||
# Note: In a fully async version, we would wrap this in a task
|
||||
run_worker_lifecycle(ticket, context, event_queue=self.event_queue, engine=self)
|
||||
|
||||
# Offload the blocking lifecycle call to a thread to avoid blocking the async event loop.
|
||||
# We pass the md_content so the worker has full context.
|
||||
context_files = ticket.context_requirements if ticket.context_requirements else None
|
||||
await loop.run_in_executor(
|
||||
None,
|
||||
run_worker_lifecycle,
|
||||
ticket,
|
||||
context,
|
||||
context_files,
|
||||
self.event_queue,
|
||||
self,
|
||||
md_content
|
||||
)
|
||||
await self._push_state(active_tier="Tier 2 (Tech Lead)")
|
||||
|
||||
elif ticket.status == "todo" and (ticket.step_mode or not self.engine.auto_queue):
|
||||
@@ -126,7 +138,6 @@ class ConductorEngine:
|
||||
print(f"Ticket {ticket.id} is ready and awaiting approval.")
|
||||
await self._push_state(active_tier=f"Awaiting Approval: {ticket.id}")
|
||||
# In a real UI, this would wait for a user event.
|
||||
# For headless/linear run, we might need a signal.
|
||||
# For now, we'll treat it as a pause point if not auto-queued.
|
||||
pass
|
||||
|
||||
@@ -170,10 +181,17 @@ def confirm_execution(payload: str, event_queue: events.AsyncEventQueue, ticket_
|
||||
|
||||
return False
|
||||
|
||||
def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files: List[str] = None, event_queue: events.AsyncEventQueue = None, engine: Optional['ConductorEngine'] = None):
|
||||
def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files: List[str] = None, event_queue: events.AsyncEventQueue = None, engine: Optional['ConductorEngine'] = None, md_content: str = ""):
|
||||
"""
|
||||
Simulates the lifecycle of a single agent working on a ticket.
|
||||
Calls the AI client and updates the ticket status based on the response.
|
||||
Args:
|
||||
ticket: The ticket to process.
|
||||
context: The worker context.
|
||||
context_files: List of files to include in the context.
|
||||
event_queue: Queue for pushing state updates and receiving approvals.
|
||||
engine: The conductor engine.
|
||||
md_content: The markdown context (history + files) for AI workers.
|
||||
"""
|
||||
# Enforce Context Amnesia: each ticket starts with a clean slate.
|
||||
ai_client.reset_session()
|
||||
@@ -183,6 +201,11 @@ def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files:
|
||||
parser = ASTParser(language="python")
|
||||
for i, file_path in enumerate(context_files):
|
||||
try:
|
||||
abs_path = Path(file_path)
|
||||
if not abs_path.is_absolute() and engine:
|
||||
# Resolve relative to project base if possible
|
||||
# (This is a bit simplified, but helps)
|
||||
pass
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
if i == 0:
|
||||
@@ -206,8 +229,6 @@ def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files:
|
||||
"start your response with 'BLOCKED' and explain why."
|
||||
)
|
||||
|
||||
# In a real scenario, we would pass md_content from the aggregator
|
||||
# and manage the conversation history in the context.
|
||||
# HITL Clutch: pass the queue and ticket_id to confirm_execution
|
||||
def clutch_callback(payload: str) -> bool:
|
||||
if not event_queue:
|
||||
@@ -215,7 +236,7 @@ def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files:
|
||||
return confirm_execution(payload, event_queue, ticket.id)
|
||||
|
||||
response = ai_client.send(
|
||||
md_content="",
|
||||
md_content=md_content,
|
||||
user_message=user_message,
|
||||
base_dir=".",
|
||||
pre_tool_callback=clutch_callback if ticket.step_mode else None,
|
||||
|
||||
Reference in New Issue
Block a user