Skip to content

AI Fix for Issue #243: Backend: Create Asynchronous 'analysis_worker.js' Service - #249

Merged
integry merged 3 commits into
mainfrom
ai-fix/243-backend-create-asynchrono-20251114-1448-claude-sonnet-4-5-20250929-kjt
Nov 14, 2025
Merged

integry merged 3 commits into
mainfrom
ai-fix/243-backend-create-asynchrono-20251114-1448-claude-sonnet-4-5-20250929-kjt

Conversation

@propr-dev

@propr-dev propr-dev Bot commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

AI Implementation Summary

Closes #243

Model Used: claude-sonnet-4-5-20250929
Status: ✅ Implementation Completed
Branch: ai-fix/243-backend-create-asynchrono-20251114-1448-claude-sonnet-4-5-20250929-kjt
Commits: ✅ Changes committed (c326911)


🤖 AI Processing Completed

Execution Details:

Summary:
Perfect! Let me create a summary of what has been implemented:

Implementation Summary

I've successfully implemented the asynchronous analysis worker service as specified in GitHub issue #243. Here's what was created:

Files Created/Modified:

  1. src/analysis_worker.js (NEW) - Main worker service

    • Listens to the 'analysis-queue' (ANALYSIS_QUEUE_NAME)
    • Processes jobs with executionId, sessionId, and correlationId
    • Loads fast analysis model from config (defaults to 'claude-3-5-haiku-20241022')
    • Saves analysis reports to the llm_executions.analysis_report column
    • Handles graceful shutdown on SIGINT/SIGTERM
  2. src/services/analysisService.js (NEW) - Analysis business logic

    • Fetches original prompt from Redis using session key
    • Retrieves conversation log from llm_execution_details table
    • Generates meta-prompt using generateExecutionAnalysisPrompt
    • Calls lightweight LLM analysis function
    • Returns structured analysis report with timestamp and model info
  3. src/claude/claudeService.js (MODIFIED)

    • Added @anthropic-ai/sdk import
    • Created Anthropic client instance
    • Implemented runLightweightLLMAnalysis() function that:
      • Calls Anthropic API directly (no Docker/worktree)
      • Uses configurable model
      • Returns analysis text
      • Logs token usage and metrics
  4. src/claude/prompts/promptGenerator.js (MODIFIED)

    • Added generateExecutionAnalysisPrompt() function
    • Creates structured meta-prompt for analyzing AI executions
    • Summarizes conversation log entries
    • Requests JSON-formatted analysis covering efficiency, tool usage, errors, and recommendations
  5. package.json (MODIFIED)

    • Installed @anthropic-ai/sdk dependency
    • Added npm scripts: analysis-worker and analysis-worker:dev

Key Features:

  • ✅ Standalone runnable worker (similar to worker.js and daemon.js)
  • ✅ Low concurrency (2) for analysis processing
  • ✅ Direct Anthropic API calls (no Docker required)
  • ✅ Configurable fast model via settings
  • ✅ Proper error handling and logging with correlation IDs
  • ✅ Graceful shutdown support
  • ✅ Integration with existing queue infrastructure (BullMQ/Redis)
  • ✅ Database persistence of analysis reports

The implementation follows all existing patterns in the codebase and integrates seamlessly with the queue system, configuration management, and database schema established in previous issues.

Claude Code Results:

  • Turns Used: 88
  • Cost: $1.26
  • Session ID: dc9491d7-0ba9-43bf-85ea-42501be6ad61

📁 Detailed Logs:
Execution logs generated:

  • Conversation: 88 messages
  • Session: dc9491d7-0ba9-43bf-85ea-42501be6ad61
  • Raw Output: 190,482 characters

Log files stored at:

  • conversation: /tmp/claude-logs/issue-243-2025-11-14T14-52-02-570Z-conversation.json
  • output: /tmp/claude-logs/issue-243-2025-11-14T14-52-02-570Z-output.txt
💬 Latest Conversation Messages
ASSISTANT: [content unavailable]

ASSISTANT: Perfect! Let me create a summary of what has been implemented:

## Implementation Summary

I've successfully implemented the asynchronous analysis worker service as specified in GitHub issue #243. Her...


Powered by Claude Code v1.0.0


This PR was created automatically by Claude Code after processing issue #243.

…worker.js'

Implemented by Claude Code using claude-sonnet-4-5-20250929 model.

Implementation completed successfully.
@propr-dev propr-dev Bot added the gitfix label Nov 14, 2025
@integry

integry commented Nov 14, 2025

Copy link
Copy Markdown
Owner

Use claude-haiku-4-5 as the default fallback model.

And contrary to how it's implemented now, it MUST call Claude via Docker (as it's done now, also for example to generate the task summaries via Haiku). Calling via API is the wrong assumption.

@propr-dev

propr-dev Bot commented Nov 14, 2025 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit 2f596f3

Summary of Changes

Perfect! I've completed all the requested changes:

Summary

  1. Updated model aliases (src/config/modelAliases.js:11-12): Added claude-haiku-4-5 as the new default Haiku model, with alias haiku45

  2. Updated default fallback model (src/analysis_worker.js:15): Changed from claude-3-5-haiku-20241022 to claude-haiku-4-5

  3. Updated runLightweightLLMAnalysis to use Docker (src/claude/claudeService.js:582-614): Changed from calling the Anthropic API directly to using the Docker-based executeClaudeCode function, matching the approach used by generateTaskSummary

  4. Updated getExecutionAnalysis (src/services/analysisService.js:12-86): Added logic to fetch required parameters (worktreePath, githubToken, issueRef) from the database and Redis to pass to the Docker-based analysis function

The changes ensure that:

  • claude-haiku-4-5 is now the default fallback model
  • All Claude calls go through Docker (not the API) as requested
  • The implementation follows the same pattern as the existing task summary generation

Key changes:

  1. Updated model aliases (src/config/modelAliases.js:11-12): Added claude-haiku-4-5 as the new default Haiku model, with alias haiku45
  2. Updated default fallback model (src/analysis_worker.js:15): Changed from claude-3-5-haiku-20241022 to claude-haiku-4-5
  3. Updated runLightweightLLMAnalysis to use Docker (src/claude/claudeService.js:582-614): Changed from calling the Anthropic API directly to using the Docker-based executeClaudeCode function, matching the approach used by generateTaskSummary
  4. Updated getExecutionAnalysis (src/services/analysisService.js:12-86): Added logic to fetch required parameters (worktreePath, githubToken, issueRef) from the database and Redis to pass to the Docker-based analysis function
  • claude-haiku-4-5 is now the default fallback model
  • All Claude calls go through Docker (not the API) as requested
  • The implementation follows the same pattern as the existing task summary generation

PR: #249
Comment by: @integry (ID: 3533160809)
Model: claude-sonnet-4-5-20250929


🤖 Implemented by Claude Code

  • Requested by: @integry
  • Model: claude-sonnet-4-5-20250929
  • Turns: 68
  • Execution time: 170s
  • Cost: $1.17

Processing comment ID: 3533160809✓

Perfect! I've completed all the requested changes:

## Summary

1. **Updated model aliases** (`src/config/modelAliases.js:11-12`): Added `claude-haiku-4-5` as the new default Haiku model, with alias `haiku45`

2. **Updated default fallback model** (`src/analysis_worker.js:15`): Changed from `claude-3-5-haiku-20241022` to `claude-haiku-4-5`

3. **Updated `runLightweightLLMAnalysis` to use Docker** (`src/claude/claudeService.js:582-614`): Changed from calling the Anthropic API directly to using the Docker-based `executeClaudeCode` function, matching the approach used by `generateTaskSummary`

4. **Updated `getExecutionAnalysis`** (`src/services/analysisService.js:12-86`): Added logic to fetch required parameters (worktreePath, githubToken, issueRef) from the database and Redis to pass to the Docker-based analysis function

The changes ensure that:
- `claude-haiku-4-5` is now the default fallback model
- All Claude calls go through Docker (not the API) as requested
- The implementation follows the same pattern as the existing task summary generation

Key changes:
1. **Updated model aliases** (`src/config/modelAliases.js:11-12`): Added `claude-haiku-4-5` as the new default Haiku model, with alias `haiku45`
2. **Updated default fallback model** (`src/analysis_worker.js:15`): Changed from `claude-3-5-haiku-20241022` to `claude-haiku-4-5`
3. **Updated `runLightweightLLMAnalysis` to use Docker** (`src/claude/claudeService.js:582-614`): Changed from calling the Anthropic API directly to using the Docker-based `executeClaudeCode` function, matching the approach used by `generateTaskSummary`
4. **Updated `getExecutionAnalysis`** (`src/services/analysisService.js:12-86`): Added logic to fetch required parameters (worktreePath, githubToken, issueRef) from the database and Redis to pass to the Docker-based analysis function
- `claude-haiku-4-5` is now the default fallback model
- All Claude calls go through Docker (not the API) as requested
- The implementation follows the same pattern as the existing task summary generation

PR: #249
Comment by: @integry (ID: 3533160809)
Model: claude-sonnet-4-5-20250929
@propr-dev

propr-dev Bot commented Nov 14, 2025 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit 77cf57d

Summary of Changes

Perfect! I've successfully identified and removed the unnecessary @anthropic-ai/sdk dependency. Here's a summary:

Changes Needed in package-lock.json

The @anthropic-ai/sdk dependency was no longer needed because:

  1. Previous refactoring: The runLightweightLLMAnalysis function was refactored to use Docker-based Claude execution (via executeClaudeCode) instead of direct API calls
  2. Unused code: The SDK was imported and an anthropic client was instantiated, but never actually used

Changes Made:

  1. Removed unused import from src/claude/claudeService.js:4
  2. Removed unused client instantiation from src/claude/claudeService.js:578-580
  3. Removed dependency from package.json
  4. Updated package-lock.json via npm install - this removed:
    • @anthropic-ai/sdk package entry
    • @babel/runtime dependency (was only needed by the SDK)
    • All related transitive dependencies

The codebase now correctly uses only Docker-based Claude Code execution for all LLM interactions, matching the intended architecture.

Key changes:

  1. Previous refactoring: The runLightweightLLMAnalysis function was refactored to use Docker-based Claude execution (via executeClaudeCode) instead of direct API calls
  2. Unused code: The SDK was imported and an anthropic client was instantiated, but never actually used
  3. Removed unused import from src/claude/claudeService.js:4
  4. Removed unused client instantiation from src/claude/claudeService.js:578-580
  5. Removed dependency from package.json
  6. Updated package-lock.json via npm install - this removed:
    • @anthropic-ai/sdk package entry
    • @babel/runtime dependency (was only needed by the SDK)
    • All related transitive dependencies

PR: #249
Comment by: @integry (ID: 3533190335)
Model: claude-sonnet-4-5-20250929


🤖 Implemented by Claude Code

  • Requested by: @integry
  • Model: claude-sonnet-4-5-20250929
  • Turns: 35
  • Execution time: 61s
  • Cost: $0.42

Processing comment ID: 3533190335✓

…essary `@anthropic-ai/sdk` dependency. Here's a summary:

Perfect! I've successfully identified and removed the unnecessary `@anthropic-ai/sdk` dependency. Here's a summary:

## Changes Needed in package-lock.json

The `@anthropic-ai/sdk` dependency was **no longer needed** because:

1. **Previous refactoring**: The `runLightweightLLMAnalysis` function was refactored to use Docker-based Claude execution (via `executeClaudeCode`) instead of direct API calls
2. **Unused code**: The SDK was imported and an `anthropic` client was instantiated, but never actually used

## Changes Made:

1. **Removed unused import** from `src/claude/claudeService.js:4`
2. **Removed unused client instantiation** from `src/claude/claudeService.js:578-580`
3. **Removed dependency** from `package.json`
4. **Updated `package-lock.json`** via `npm install` - this removed:
   - `@anthropic-ai/sdk` package entry
   - `@babel/runtime` dependency (was only needed by the SDK)
   - All related transitive dependencies

The codebase now correctly uses only Docker-based Claude Code execution for all LLM interactions, matching the intended architecture.

Key changes:
1. **Previous refactoring**: The `runLightweightLLMAnalysis` function was refactored to use Docker-based Claude execution (via `executeClaudeCode`) instead of direct API calls
2. **Unused code**: The SDK was imported and an `anthropic` client was instantiated, but never actually used
1. **Removed unused import** from `src/claude/claudeService.js:4`
2. **Removed unused client instantiation** from `src/claude/claudeService.js:578-580`
3. **Removed dependency** from `package.json`
4. **Updated `package-lock.json`** via `npm install` - this removed:
   - `@anthropic-ai/sdk` package entry
   - `@babel/runtime` dependency (was only needed by the SDK)
   - All related transitive dependencies

PR: #249
Comment by: @integry (ID: 3533190335)
Model: claude-sonnet-4-5-20250929
@integry
integry merged commit 57e9be2 into main Nov 14, 2025
@integry
integry deleted the ai-fix/243-backend-create-asynchrono-20251114-1448-claude-sonnet-4-5-20250929-kjt branch November 14, 2025 15:06
propr-dev Bot pushed a commit that referenced this pull request Nov 18, 2026
…out a slow regular expression in `packages/shared/src/automationReportPreview.ts`. The preview test file passes (11 of 11) and the shared package typechecks.

I fixed both CodeQL alerts (code-scanning #248 and #249) about a slow regular expression in `packages/shared/src/automationReportPreview.ts`. The preview test file passes (11 of 11) and the shared package typechecks.

**The problem:** the "end of first sentence" pattern `/[.!?]+["')\]]*(?=\s)/u` was used in two places. On a long run of `!` (or `.`/`?`) with no space after it, it restarts the match at every character in the run, so the time grows with the square of the run's length.

**The fix:** I replaced the regex with a small `sentenceEnd(text)` function that reads the text once, from left to right. When it finds `.`, `!` or `?`, it skips past the whole run of punctuation and any closing quotes or brackets. It returns that position if a space follows; otherwise it carries on from the end of the run instead of going back. Starting partway through such a run can't give a different answer, so the result is the same as before. Both places that used the regex now call this function.

**Tests:** I added a timing test to `packages/shared/test/automationReportPreview.test.ts`. It feeds in 100,000 `!` with no space after them and two similar long runs, and expects each to finish in under 500 ms. It also checks that the cut still lands in the same place: `Done!!!`, `Shipped v0.9.2 ("final").` (no cut inside `v0.9.2`), and `Wait?!)`.

ESLint has no configuration for `packages/shared`, so it skipped both files and they weren't linted. There's no visible change, so I made no preview images.

PR: #3705
Comment by: @github-advanced-security[bot] (ID: 4615956323)
Comment by: @github-advanced-security[bot] (ID: 4615956187)
Model: Claude Opus 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend: Create Asynchronous 'analysis_worker.js' Service

2 participants