Skip to content

Backend: Implement 'analysis-queue' and Database Schema for Execution Analysis #242

Closed

Description

@integry

This is the foundational step for the asynchronous analysis feature.

We need to:

  1. Create a new BullMQ queue named 'analysis-queue'. This should be added in 'src/queue/taskQueue.js'.
  2. Update the database schema to store the analysis results. The simplest approach is to add a new 'JSONB' column named 'analysis_report' to the 'llm_executions' table. A new migration file will be required.
  3. Modify the main worker to enqueue an analysis job. The 'recordLLMMetrics' function in 'src/utils/llmMetrics.js' is the perfect place. After successfully recording metrics, it should add a new job to the 'analysis-queue' with the 'taskId' and 'execution_id'.

Implementation Steps:

  1. Create a new migration file to add 'analysis_report JSONB' to the 'llm_executions' table.
  2. In 'src/queue/taskQueue.js', export a new 'analysisQueue' instance.
  3. In 'src/utils/llmMetrics.js', import the 'analysisQueue' and modify 'recordLLMMetrics' to add a job at the end.

Activity

  1. integry commented on Nov 14, 2025

    @integry
    OwnerAuthor

    Suggested Implementation

    1. New Migration File

    (e.g., 'src/db/migrations/20251114000000_add_analysis_report.js')

    export async function up(knex) {
      await knex.schema.table('llm_executions', (table) => {
        table.jsonb('analysis_report');
        table.index('analysis_report', 'idx_llm_executions_analysis_report', 'gin');
      });
    }
    
    export async function down(knex) {
      await knex.schema.table('llm_executions', (table) => {
        table.dropIndex('analysis_report', 'idx_llm_executions_analysis_report');
        table.dropColumn('analysis_report');
      });
    }

    2. 'src/queue/taskQueue.js'

    --- a/src/queue/taskQueue.js
    +++ b/src/queue/taskQueue.js
    @@ -35,6 +35,26 @@
         },
     });
     
    +export const ANALYSIS_QUEUE_NAME = process.env.ANALYSIS_QUEUE_NAME || 'analysis-processor';
    +
    +// Create the analysis queue
    +export const analysisQueue = new Queue(ANALYSIS_QUEUE_NAME, {
    +    connection: redisConnection,
    +    defaultJobOptions: {
    +        attempts: 2,
    +        backoff: {
    +            type: 'exponential',
    +            delay: 60000,
    +        },
    +        removeOnComplete: {
    +            age: 24 * 3600,
    +            count: 1000,
    +        },
    +        removeOnFail: true,
    +    },
    +});
    +
     issueQueue.on('error', (err) => {
         logger.error({ queue: GITHUB_ISSUE_QUEUE_NAME, err }, 'Queue error');
     });
    +
    +analysisQueue.on('error', (err) => {
    +    logger.error({ queue: ANALYSIS_QUEUE_NAME, err }, 'Analysis Queue error');
    +});

    3. 'src/utils/llmMetrics.js'

    --- a/src/utils/llmMetrics.js
    +++ b/src/utils/llmMetrics.js
    @@ -2,6 +2,7 @@
     import Redis from 'ioredis';
     import logger from './logger.js';
     import { db, isEnabled as isDbEnabled } from '../db/postgres.js';
    +import { analysisQueue } from '../queue/taskQueue.js';
     
     // Redis configuration
     const REDIS_HOST = process.env.REDIS_HOST || '127.0.0.1';
    @@ -211,6 +212,24 @@
                           .references('history_id')
                           .inTable('task_history')
                           .onDelete('SET NULL');
    +
    +                // Enqueue for analysis
    +                try {
    +                    await analysisQueue.add('analyzeExecution', {
    +                        taskId,
    +                        executionId,
    +                        sessionId,
    +                        correlationId,
    +                    }, {
    +                        jobId: `analysis-${executionId}`,
    +                        removeOnComplete: true,
    +                        removeOnFail: true,
    +                    });
    +                    logger.debug({ correlationId, taskId, executionId }, 'Enqueued task for execution analysis');
    +                } catch (queueError) {
    +                    logger.error({ error: queueError.message, correlationId, taskId }, 'Failed to enqueue task for analysis');
    +                }
                     
                     if (claudeResult.conversationLog && Array.isArray(claudeResult.conversationLog)) {
                         // Debug: log first item structure
    
  2. propr-dev commented on Nov 14, 2025

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude-sonnet-4-5-20250929 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Model: claude-sonnet-4-5-20250929
    • Branch: ai-fix/242-backend-implement-analysi-20251114-1153-claude-sonnet-4-5-20250929-o6l
    • Base Branch: main
    • Worktree: issue-242-20251114-1153-claude-sonnet-4-5-20250929-o6l
  3. added a commit that references this issue on Nov 14, 2025
  4. added a commit that references this issue on Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions