You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Backend: Create Asynchronous 'analysis_worker.js' Service #243
This task involves creating a new standalone worker service responsible for processing jobs from the 'analysis-queue'.
This worker must:
Be a new runnable script, similar to 'src/worker.js' or 'src/daemon.js'.
Listen to the 'ANALYSIS_QUEUE_NAME' ('analysis-queue').
On receiving a job, it should:
a. Extract the 'executionId', 'sessionId', and 'correlationId'.
b. Load the fast analysis model name from the new configuration (see Issue Epic: Claude-Powered GitHub Issue Processor - Stage 3: Task Queue and Worker Infrastructure #3).
c. Fetch the original prompt from Redis (e.g., 'execution:prompt:session:SESSION_ID').
d. Fetch the full conversation log from the database ('llm_execution_details' table).
e. Create a "meta-prompt" using 'generateExecutionAnalysisPrompt' (from 'src/claude/prompts/promptGenerator.js').
f. Call a new, lightweight LLM function in 'src/claude/claudeService.js' that calls the Anthropic API directly (no Docker/worktree needed).
g. Save the resulting analysis text to the 'analysis_report' column in the 'llm_executions' table.
import'dotenv/config';import{createWorker,ANALYSIS_QUEUE_NAME}from'./queue/taskQueue.js';importloggerfrom'./utils/logger.js';import{db}from'./db/postgres.js';import{getExecutionAnalysis}from'./services/analysisService.js';// To be createdimport{loadSettings}from'./config/configRepoManager.js';asyncfunctionprocessAnalysisJob(job){const{ executionId, sessionId, correlationId }=job.data;constcorrelatedLogger=logger.withCorrelation(correlationId);correlatedLogger.info({ executionId },'Starting execution analysis job...');try{// 1. Load fast analysis model from configconstsettings=awaitloadSettings();constfastModel=settings.analysis_model_fast||'claude-3-5-haiku-20241022';// 2. Get analysis (this function will do the heavy lifting)constanalysisReport=awaitgetExecutionAnalysis({
executionId,
sessionId,
correlationId,model: fastModel,});// 3. Save to databaseawaitdb('llm_executions').where({execution_id: executionId}).update({analysis_report: JSON.stringify(analysisReport)});correlatedLogger.info({ executionId },'Execution analysis complete and saved.');return{success: true};}catch(error){correlatedLogger.error({ executionId,error: error.message},'Execution analysis job failed');throwerror;}}functionstartAnalysisWorker(){logger.info({queue: ANALYSIS_QUEUE_NAME,concurrency: 2,// Keep analysis low-concurrency},'Starting Analysis Worker...');createWorker(ANALYSIS_QUEUE_NAME,processAnalysisJob,{concurrency: 2});}startAnalysisWorker();
2. New file: 'src/services/analysisService.js' (Skeleton)
importRedisfrom'ioredis';import{db}from'../db/postgres.js';import{generateExecutionAnalysisPrompt}from'../claude/prompts/promptGenerator.js';import{runLightweightLLMAnalysis}from'../claude/claudeService.js';// To be createdimportloggerfrom'../utils/logger.js';constredis=newRedis({host: process.env.REDIS_HOST||'redis',port: process.env.REDIS_PORT||6379,});exportasyncfunctiongetExecutionAnalysis({ executionId, sessionId, correlationId, model }){constcorrelatedLogger=logger.withCorrelation(correlationId);// 1. Fetch prompt from RedisconstpromptKey=`execution:prompt:session:${sessionId}`;constpromptData=JSON.parse(awaitredis.get(promptKey)||'{}');constoriginalPrompt=promptData.prompt||'Original prompt not found.';// 2. Fetch conversation log from DBconstconversationLog=awaitdb('llm_execution_details').where({execution_id: executionId}).orderBy('sequence_number','asc');if(conversationLog.length===0){correlatedLogger.warn({ executionId },'No execution details found for analysis.');return{error: 'No execution details found.'};}// 3. Generate the meta-prompt// This function needs to be created in src/claude/prompts/promptGenerator.jsconstmetaPrompt=generateExecutionAnalysisPrompt(originalPrompt,conversationLog,model);// 4. Call lightweight LLM serviceconstanalysisText=awaitrunLightweightLLMAnalysis(metaPrompt,model,correlationId);// 5. TODO: Parse analysisText into structured JSON if desiredconstanalysisReport={generatedAt: newDate().toISOString(),modelUsed: model,report: analysisText,// Store raw text for now};returnanalysisReport;}
3. New function in 'src/claude/claudeService.js'
// ... existing imports// Import Anthropic SDK// import Anthropic from '@anthropic-ai/sdk';// const anthropic = new Anthropic(); // API key from process.env.ANTHROPIC_API_KEYexportasyncfunctionrunLightweightLLMAnalysis(prompt,model,correlationId){constcorrelatedLogger=logger.withCorrelation(correlationId);correlatedLogger.info({ model },'Running lightweight LLM analysis...');// This is a placeholder. Implement with the actual LLM SDK (e.g., Anthropic's)// This call does NOT use Docker.// Example (needs Anthropic SDK installed):/* try { const response = await anthropic.messages.create({ model: model, max_tokens: 4096, messages: [{ role: 'user', content: prompt }], }); return response.content[0].text; } catch (error) { correlatedLogger.error({ error: error.message, model }, 'Lightweight LLM analysis failed'); throw error; } */// Placeholder implementation:awaitnewPromise(resolve=>setTimeout(resolve,1000));return`This is a placeholder analysis report for model '${model}'.\n\n- Efficiency: Good\n- Prompt Improvement: None needed.`;}
Activity
integry commentedon Nov 14, 2025
Suggested Implementation
1. New file: 'src/analysis_worker.js' (Skeleton)
2. New file: 'src/services/analysisService.js' (Skeleton)
3. New function in 'src/claude/claudeService.js'
propr-dev commentedon Nov 14, 2025
🤖 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:
claude-sonnet-4-5-20250929ai-fix/243-backend-create-asynchrono-20251114-1448-claude-sonnet-4-5-20250929-kjtmainissue-243-20251114-1448-claude-sonnet-4-5-20250929-kjtfix(ai): Resolve issue #243 - Backend: Create Asynchronous 'analysis_…
Merge pull request #249 from integry/ai-fix/243-backend-create-asynch…