From 9fe6153c22afb88576710284c9e22ea4c202177f Mon Sep 17 00:00:00 2001 From: alorig <220087330+alorig@users.noreply.github.com> Date: Mon, 10 Nov 2025 00:13:11 +0500 Subject: [PATCH] fg --- .../igny8_core/ai/functions/generate_ideas.py | 24 +++++++-- backend/igny8_core/modules/planner/tasks.py | 52 ++++++++++++++++++- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/backend/igny8_core/ai/functions/generate_ideas.py b/backend/igny8_core/ai/functions/generate_ideas.py index e973d6e0..c159d0df 100644 --- a/backend/igny8_core/ai/functions/generate_ideas.py +++ b/backend/igny8_core/ai/functions/generate_ideas.py @@ -199,6 +199,13 @@ def generate_ideas_core(cluster_id: int, account_id: int = None, progress_callba Returns: Dict with 'success', 'idea_created', 'message', etc. """ + import sys + print("=" * 80, flush=True, file=sys.stdout) + print("[GENERATE IDEAS CORE] Function started", flush=True, file=sys.stdout) + print(f"[GENERATE IDEAS CORE] cluster_id: {cluster_id}", flush=True, file=sys.stdout) + print(f"[GENERATE IDEAS CORE] account_id: {account_id}", flush=True, file=sys.stdout) + print("=" * 80, flush=True, file=sys.stdout) + tracker = ConsoleStepTracker('generate_ideas') tracker.init("Task started") @@ -279,7 +286,18 @@ def generate_ideas_core(cluster_id: int, account_id: int = None, progress_callba } except Exception as e: - tracker.error('Exception', str(e), e) - logger.error(f"Error in generate_ideas_core: {str(e)}", exc_info=True) - return {'success': False, 'error': str(e)} + import sys + import traceback + error_msg = str(e) + error_type = type(e).__name__ + + print("=" * 80, flush=True, file=sys.stdout) + print(f"[GENERATE IDEAS CORE] ERROR: {error_type}: {error_msg}", flush=True, file=sys.stdout) + print("[GENERATE IDEAS CORE] Full traceback:", flush=True, file=sys.stdout) + traceback.print_exc(file=sys.stdout) + print("=" * 80, flush=True, file=sys.stdout) + + tracker.error('Exception', error_msg, e) + logger.error(f"Error in generate_ideas_core: {error_msg}", exc_info=True) + return {'success': False, 'error': error_msg, 'error_type': error_type} diff --git a/backend/igny8_core/modules/planner/tasks.py b/backend/igny8_core/modules/planner/tasks.py index 9130e6c2..4be35c2c 100644 --- a/backend/igny8_core/modules/planner/tasks.py +++ b/backend/igny8_core/modules/planner/tasks.py @@ -926,15 +926,63 @@ def auto_generate_ideas_task(self, cluster_ids: List[int], account_id: int = Non # Use new framework - always use generate_ideas_core for proper console logging try: + import sys + print(f"[CELERY TASK] Calling generate_ideas_core for cluster {cluster_id}...", flush=True, file=sys.stdout) + # Use generate_ideas_core which has ConsoleStepTracker built in result = generate_ideas_core(cluster_id, account_id=account_id) + + print(f"[CELERY TASK] generate_ideas_core returned: success={result.get('success')}, error={result.get('error')}", flush=True, file=sys.stdout) + if result.get('success'): ideas_created += result.get('idea_created', 0) logger.info(f"✓ Successfully generated idea for cluster {cluster_id}") + print(f"[CELERY TASK] ✓ Successfully generated idea for cluster {cluster_id}", flush=True, file=sys.stdout) else: - logger.error(f"✗ Failed to generate idea for cluster {cluster_id}: {result.get('error')}") + error_msg = result.get('error', 'Unknown error') + logger.error(f"✗ Failed to generate idea for cluster {cluster_id}: {error_msg}") + print(f"[CELERY TASK] ✗ Failed to generate idea for cluster {cluster_id}: {error_msg}", flush=True, file=sys.stdout) + # Update task state with error for this cluster + self.update_state( + state='PROGRESS', + meta={ + 'current': idx + 1, + 'total': total_clusters, + 'percentage': progress_pct, + 'message': f'Error generating idea for cluster "{cluster.name}": {error_msg}', + 'phase': 'error', + 'current_item': cluster.name, + 'error': error_msg, + 'error_type': result.get('error_type', 'GenerationError') + } + ) except Exception as e: - logger.error(f"✗ Error generating idea for cluster {cluster_id}: {str(e)}", exc_info=True) + import sys + import traceback + error_msg = str(e) + error_type = type(e).__name__ + + print("=" * 80, flush=True, file=sys.stdout) + print(f"[CELERY TASK] EXCEPTION in generate_ideas_core call: {error_type}: {error_msg}", flush=True, file=sys.stdout) + print("[CELERY TASK] Full traceback:", flush=True, file=sys.stdout) + traceback.print_exc(file=sys.stdout) + print("=" * 80, flush=True, file=sys.stdout) + + logger.error(f"✗ Error generating idea for cluster {cluster_id}: {error_msg}", exc_info=True) + # Update task state with exception + self.update_state( + state='PROGRESS', + meta={ + 'current': idx + 1, + 'total': total_clusters, + 'percentage': progress_pct, + 'message': f'Exception generating idea for cluster "{cluster.name}": {error_msg}', + 'phase': 'error', + 'current_item': cluster.name, + 'error': error_msg, + 'error_type': error_type + } + ) # Ideas are already saved by the new framework, just log results logger.info("=" * 80)