Skip to content

Worker: Implement Self-Correction Loop for FAILED Tasks #247

Closed

Description

@integry

This is the "self-correcting" part of the loop. When a task in 'src/jobs/processGitHubIssueJob.js' or 'src/jobs/processPullRequestCommentJob.js' fails, the worker should not give up immediately.

It should:

  1. Inside the 'catch' block (but before the 'UsageLimitError' check), call the 'analysisService.getExecutionAnalysis' function.
  2. Use the fast analysis model for this (loaded from config).
  3. The 'generateExecutionAnalysisPrompt' needs to be updated to output a specific, parseable suggestion, e.g., in an '' XML tag.
  4. The worker parses this suggestion.
  5. If a concrete suggestion exists (e.g., "Inject file 'X'", "Add 'ls -R' output"), the worker:
    a. Gathers the new context.
    b. Builds an 'augmentedPrompt'.
    c. Calls 'executeClaudeCode' a second time with this new prompt.
  6. If the retry succeeds, the job can proceed.
  7. If the retry also fails, or if no suggestion was provided, then it throws the original error to be marked as 'FAILED'.

This requires refactoring the job files to be able to call the analysis service and potentially re-run the 'executeClaudeCode' step.

Activity

  1. integry commented on Nov 14, 2025

    @integry
    OwnerAuthor

    This is the "self-correcting" part of the loop. When a task in 'src/jobs/processGitHubIssueJob.js' or 'src/jobs/processPullRequestCommentJob.js' fails, the worker should not give up immediately.

    It should:

    1. Inside the 'catch' block (but before the 'UsageLimitError' check), call the 'analysisService.getExecutionAnalysis' function.
    2. Use the fast analysis model for this (loaded from config).
    3. The 'generateExecutionAnalysisPrompt' needs to be updated to output a specific, parseable suggestion, e.g., in an '' XML tag.
    4. The worker parses this suggestion.
    5. If a concrete suggestion exists (e.g., "Inject file 'X'", "Add 'ls -R' output"), the worker:
      a. Gathers the new context.
      b. Builds an 'augmentedPrompt'.
      c. Calls 'executeClaudeCode' a second time with this new prompt.
    6. If the retry succeeds, the job can proceed.
    7. If the retry also fails, or if no suggestion was provided, then it throws the original error to be marked as 'FAILED'.

    This requires refactoring the job files to be able to call the analysis service and potentially re-run the 'executeClaudeCode' step.

    Suggested Implementation

    1. Update src/claude/prompts/promptGenerator.js

    Modify 'generateExecutionAnalysisPrompt' to add the structured suggestion output.

    // ... existing prompt ...
    Your analysis must be in Markdown and should answer the following questions:
    
    1.  **Efficiency Analysis:** ...
    2.  **Prompt Improvement:** ...
    3.  **Context Injection:** ...
    4.  **Overall Rating:** ...
    
    **Self-Correction Suggestion (MOST IMPORTANT):**
    Based on your analysis, provide a *single, actionable* suggestion for the worker to *immediately* retry the task. Format this suggestion inside '<suggestion>' tags. If no retry is possible, write '<suggestion>none</suggestion>'.
    
    The suggestion should be one of:
    * **FILE:** '<suggestion>FILE:src/utils/logger.js</suggestion>' (The worker will read this file and inject it)
    * **COMMAND:** '<suggestion>COMMAND:ls -R</suggestion>' (The worker will run this command and inject the output)
    * **PROMPT_CHANGE:** '<suggestion>PROMPT_CHANGE:You must not use 'git commit'.</suggestion>' (The worker will append this to the *next* prompt)
    * **NONE:** '<suggestion>none</suggestion>'
    
    Example:
    <suggestion>COMMAND:ls -R</suggestion>
  2. integry commented on Nov 16, 2025

    @integry
    OwnerAuthor

    not relevant for now, but enriching the prompts could be something that would work for all tasks at some point

  3. added a commit that references this issue on Nov 17, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions