diff --git a/agent.py b/agent.py index 0246f25..e451f5a 100644 --- a/agent.py +++ b/agent.py @@ -496,6 +496,12 @@ RESPOND WITH ONLY THE JSON, NO OTHER TEXT. # If queue is enabled, submit to queue and wait if self.use_queue and self.ollama_queue: try: + # Check if there's already an AUTONOMOUS request pending/processing + if self.priority_level.value == 1: # AUTONOMOUS + if self.ollama_queue.has_pending_with_priority(self.priority_level): + print("[Queue] Skipping request - AUTONOMOUS check already in queue") + return "System check already in progress - skipping duplicate request" + payload = { "model": self.model, "prompt": prompt, @@ -794,6 +800,12 @@ Provide unified summary (max 800 chars) covering all key points.""" # Use queue if enabled if self.use_queue and self.ollama_queue: try: + # Check if there's already an AUTONOMOUS request pending/processing + if self.priority_level.value == 1: # AUTONOMOUS + if self.ollama_queue.has_pending_with_priority(self.priority_level): + print("[Queue] Skipping request - AUTONOMOUS check already in queue") + return "System check already in progress - skipping duplicate request" + payload = { "model": self.model, "messages": pruned_messages, diff --git a/ollama_queue.py b/ollama_queue.py index 70153cf..9d207b5 100644 --- a/ollama_queue.py +++ b/ollama_queue.py @@ -102,6 +102,28 @@ class OllamaQueue: return i + 1 return 0 + def has_pending_with_priority(self, priority: Priority) -> bool: + """Check if there are any pending or processing requests with the given priority""" + # Check pending requests + for req_file in self.pending_dir.glob("*.json"): + try: + data = json.loads(req_file.read_text()) + if data.get("priority") == priority.value: + return True + except: + pass + + # Check processing requests + for req_file in self.processing_dir.glob("*.json"): + try: + data = json.loads(req_file.read_text()) + if data.get("priority") == priority.value: + return True + except: + pass + + return False + def wait_for_result( self, request_id: str, diff --git a/orchestrator.py b/orchestrator.py index 32f635c..550b504 100644 --- a/orchestrator.py +++ b/orchestrator.py @@ -725,6 +725,11 @@ class MachaOrchestrator: git_context=self.git_context if hasattr(self, 'git_context') else None ) + # Check if analysis was skipped due to queue already being busy + if isinstance(analysis, str) and "already in progress" in analysis.lower(): + self._log("⏭️ Analysis skipped - autonomous check already in queue") + return + self._log(f"\n{'='*60}") self._log("AI ANALYSIS RESULTS") self._log(f"{'='*60}")