feat(mma): complete Phase 6 and finalize Comprehensive GUI UX track
- Implement Live Worker Streaming: wire ai_client.comms_log_callback to Tier 3 streams - Add Parallel DAG Execution using asyncio.gather for non-dependent tickets - Implement Automatic Retry with Model Escalation (Flash-Lite -> Flash -> Pro) - Add Tier Model Configuration UI to MMA Dashboard with project TOML persistence - Fix FPS reporting in PerformanceMonitor to prevent transient 0.0 values - Update Ticket model with retry_count and dictionary-like access - Stabilize Gemini CLI integration tests and handle script approval events in simulations - Finalize and verify all 6 phases of the implementation plan
This commit is contained in:
@@ -100,23 +100,35 @@ class ConductorEngine:
|
||||
print("No more executable tickets. Track is blocked or finished.")
|
||||
await self._push_state(status="blocked", active_tier=None)
|
||||
break
|
||||
# 3. Process ready tasks
|
||||
# 3. Process ready tasks
|
||||
to_run = [t for t in ready_tasks if t.status == "in_progress" or (not t.step_mode and self.engine.auto_queue)]
|
||||
|
||||
# Handle those awaiting approval
|
||||
for ticket in ready_tasks:
|
||||
# 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 == "in_progress" or (not ticket.step_mode and self.engine.auto_queue):
|
||||
if ticket not in to_run and ticket.status == "todo":
|
||||
print(f"Ticket {ticket.id} is ready and awaiting approval.")
|
||||
await self._push_state(active_tier=f"Awaiting Approval: {ticket.id}")
|
||||
await asyncio.sleep(1)
|
||||
|
||||
if to_run:
|
||||
tasks = []
|
||||
for ticket in to_run:
|
||||
ticket.status = "in_progress"
|
||||
print(f"Executing ticket {ticket.id}: {ticket.description}")
|
||||
await self._push_state(active_tier=f"Tier 3 (Worker): {ticket.id}")
|
||||
|
||||
# Escalation logic based on retry_count
|
||||
models = ["gemini-2.5-flash-lite", "gemini-2.5-flash", "gemini-3.1-pro-preview"]
|
||||
model_idx = min(ticket.retry_count, len(models) - 1)
|
||||
model_name = models[model_idx]
|
||||
|
||||
context = WorkerContext(
|
||||
ticket_id=ticket.id,
|
||||
model_name=self.tier_usage["Tier 3"]["model"],
|
||||
model_name=model_name,
|
||||
messages=[]
|
||||
)
|
||||
# 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(
|
||||
tasks.append(loop.run_in_executor(
|
||||
None,
|
||||
run_worker_lifecycle,
|
||||
ticket,
|
||||
@@ -126,15 +138,19 @@ class ConductorEngine:
|
||||
self,
|
||||
md_content,
|
||||
loop
|
||||
)
|
||||
await self._push_state(active_tier="Tier 2 (Tech Lead)")
|
||||
elif ticket.status == "todo" and (ticket.step_mode or not self.engine.auto_queue):
|
||||
# Task is ready but needs approval
|
||||
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 now, we'll treat it as a pause point if not auto-queued.
|
||||
await asyncio.sleep(1)
|
||||
))
|
||||
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
# 4. Retry and escalation logic
|
||||
for ticket in to_run:
|
||||
if ticket.status == 'blocked':
|
||||
if ticket.get('retry_count', 0) < 2:
|
||||
ticket.retry_count += 1
|
||||
ticket.status = 'todo'
|
||||
print(f"Ticket {ticket.id} BLOCKED. Escalating to {models[min(ticket.retry_count, len(models)-1)]} and retrying...")
|
||||
|
||||
await self._push_state(active_tier="Tier 2 (Tech Lead)")
|
||||
|
||||
def _queue_put(event_queue: events.AsyncEventQueue, loop: asyncio.AbstractEventLoop, event_name: str, payload) -> None:
|
||||
"""Thread-safe helper to push an event to the AsyncEventQueue from a worker thread."""
|
||||
@@ -220,6 +236,7 @@ def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files:
|
||||
"""
|
||||
# Enforce Context Amnesia: each ticket starts with a clean slate.
|
||||
ai_client.reset_session()
|
||||
ai_client.set_provider(ai_client.get_provider(), context.model_name)
|
||||
context_injection = ""
|
||||
if context_files:
|
||||
parser = ASTParser(language="python")
|
||||
@@ -273,15 +290,37 @@ def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files:
|
||||
if event_queue and loop:
|
||||
_queue_put(event_queue, loop, 'mma_stream', {'stream_id': f'Tier 3 (Worker): {ticket.id}', 'text': chunk})
|
||||
|
||||
comms_baseline = len(ai_client.get_comms_log())
|
||||
response = ai_client.send(
|
||||
md_content=md_content,
|
||||
user_message=user_message,
|
||||
base_dir=".",
|
||||
pre_tool_callback=clutch_callback if ticket.step_mode else None,
|
||||
qa_callback=ai_client.run_tier4_analysis,
|
||||
stream_callback=stream_callback
|
||||
)
|
||||
old_comms_cb = ai_client.comms_log_callback
|
||||
def worker_comms_callback(entry: dict) -> None:
|
||||
if event_queue and loop:
|
||||
kind = entry.get("kind")
|
||||
payload = entry.get("payload", {})
|
||||
chunk = ""
|
||||
if kind == "tool_call":
|
||||
chunk = f"\n\n[TOOL CALL] {payload.get('name')}\n{json.dumps(payload.get('script') or payload.get('args'))}\n"
|
||||
elif kind == "tool_result":
|
||||
res = str(payload.get("output", ""))
|
||||
if len(res) > 500: res = res[:500] + "... (truncated)"
|
||||
chunk = f"\n[TOOL RESULT]\n{res}\n"
|
||||
|
||||
if chunk:
|
||||
_queue_put(event_queue, loop, "response", {"text": chunk, "stream_id": f"Tier 3 (Worker): {ticket.id}", "status": "streaming..."})
|
||||
if old_comms_cb:
|
||||
old_comms_cb(entry)
|
||||
|
||||
ai_client.comms_log_callback = worker_comms_callback
|
||||
try:
|
||||
comms_baseline = len(ai_client.get_comms_log())
|
||||
response = ai_client.send(
|
||||
md_content=md_content,
|
||||
user_message=user_message,
|
||||
base_dir=".",
|
||||
pre_tool_callback=clutch_callback if ticket.step_mode else None,
|
||||
qa_callback=ai_client.run_tier4_analysis,
|
||||
stream_callback=stream_callback
|
||||
)
|
||||
finally:
|
||||
ai_client.comms_log_callback = old_comms_cb
|
||||
|
||||
if event_queue:
|
||||
# Push via "response" event type — _process_event_queue wraps this
|
||||
|
||||
Reference in New Issue
Block a user