🔧 Bug Helper & Patch Service API

Comprehensive API documentation for bug reproduction, patch creation, and testing workflows

🔧 Bug Helper Service

Bug reproduction and fixing service providing REST APIs for managing complete software bug workflows.

Base URL: http://localhost:8000 | Version: 1.0.0

GET /projects
Retrieve all available projects
Returns list of project names for bug reproduction and fixing operations
POST /reproduce
Initiate bug reproduction
Start bug reproduction process with environment setup and test execution
POST /fix
Apply patch and test fix
Apply patch file and run tests with caching for performance
POST /fix_with_patch
Alternative fix implementation
Alternative fix approach with different configuration options
POST /extract_anchor_patch
Generate and apply patches
Create patches from LLM responses with multiple strategies and intelligent extraction

Get Projects

GET http://localhost:8000/projects

Retrieve all available projects for bug reproduction and fixing. This endpoint provides the foundation for other operations by listing valid project names that can be used with the bug_id parameter.

Parameters

No parameters required. This endpoint accepts no input parameters and returns all available projects.

Returns

Response Format
  • Type: dict
  • Structure: {"projects": List[str]}
Dictionary containing list of available project names for bug reproduction.
Error Codes
  • 500 - Internal server error if projects cannot be loaded
Example request
curl http://localhost:8000/projects
import requests

response = requests.get("http://localhost:8000/projects")
print(response.json())
const response = await fetch('http://localhost:8000/projects');
const data = await response.json();
console.log(data);
Response
{
  "projects": [
    "libxml2",
    "openssl",
    "curl",
    "nginx",
    "apache"
  ]
}

Reproduce Bug

POST http://localhost:8000/reproduce

Initiate bug reproduction for a specific bug ID. This endpoint queues a background task to reproduce the bug environment, set up dependencies, and run tests. The bug reproduction process includes environment setup, dependency installation, and test execution.

Request body

bug_id
string
Required
Bug identifier in format "project@commit_sha". The project must be one of the available projects from /projects endpoint.
is_force_cleanup
boolean
Optional
Force cleanup before reproduction. When true, removes any existing build artifacts. Default: true

Returns

Response Format
  • Type: dict
  • Structure: {"handle": str}
Dictionary containing task handle for status tracking. Use this handle with /status/{handle} to monitor progress.
Error Codes
  • 400 - Invalid bug_id format
  • 404 - Project not found
  • 500 - Reproduction fails to start
Example request
import requests

response = requests.post(
    "http://localhost:8000/reproduce",
    json={
        "bug_id": "libxml2@a1b2c3d4e5f6789012345678901234567890abcd",
        "is_force_cleanup": True
    }
)
print(response.json())
curl http://localhost:8000/reproduce \
  -H "Content-Type: application/json" \
  -d '{
    "bug_id": "libxml2@a1b2c3d4e5f6789012345678901234567890abcd",
    "is_force_cleanup": true
  }'
const response = await fetch('http://localhost:8000/reproduce', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    bug_id: "libxml2@a1b2c3d4e5f6789012345678901234567890abcd",
    is_force_cleanup: true
  })
});
const data = await response.json();
console.log(data);
Response
{
  "handle": "abc123def456789012345678901234567890uvwx"
}

Fix Bug

POST http://localhost:8000/fix

Apply a patch to fix a bug and test the fix. This endpoint uses caching to avoid redundant processing of the same patch. Results are cached based on the combination of bug_id and patch_path, making subsequent requests with identical parameters return immediately.

Request body

bug_id
string
Required
Bug identifier in format "project@commit_sha". Must match a valid project from /projects.
patch_path
string
Required
File system path to the patch file. The patch file must exist and be readable.

Returns

Response Format
  • Type: dict
  • Structure: {"handle": str, "redis_key": str}
Dictionary containing task handle and cache key for status tracking.
Error Codes
  • 400 - Invalid bug_id format or patch_path doesn't exist
  • 500 - Patch application fails
Example request
import requests

response = requests.post(
    "http://localhost:8000/fix",
    json={
        "bug_id": "openssl@f1e2d3c4b5a6789012345678901234567890cdef",
        "patch_path": "/patches/openssl_security_fix.patch"
    }
)
print(response.json())
curl http://localhost:8000/fix \
  -H "Content-Type: application/json" \
  -d '{
    "bug_id": "openssl@f1e2d3c4b5a6789012345678901234567890cdef",
    "patch_path": "/patches/openssl_security_fix.patch"
  }'
const response = await fetch('http://localhost:8000/fix', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    bug_id: "openssl@f1e2d3c4b5a6789012345678901234567890cdef",
    patch_path: "/patches/openssl_security_fix.patch"
  })
});
const data = await response.json();
console.log(data);
Response
{
  "handle": "cGF0Y2hfZjFlMmQzYzRiNWE2XzEyMzQ1Njc4LmxvZw==",
  "redis_key": "patch_f1e2d3c4b5a6_12345678.log"
}

Fix Bug (Alternative)

POST http://localhost:8000/fix_with_patch

Alternative implementation for applying patches to fix bugs. This endpoint provides different configuration options and processing strategies compared to the standard /fix endpoint.

Request body

bug_id
string
Required
Bug identifier in format "project@commit_sha". Must match a valid project from /projects.
patch_path
string
Required
File system path to the patch file. The patch file must exist and be readable.
options
object
Optional
Additional configuration options for the alternative fix implementation.

Returns

Response Format
  • Type: dict
  • Structure: {"handle": str, "method": str}
Dictionary containing task handle and processing method used.
Error Codes
  • 400 - Invalid bug_id format or patch_path doesn't exist
  • 500 - Patch application fails
Example request
import requests

response = requests.post(
    "http://localhost:8000/fix_with_patch",
    json={
        "bug_id": "curl@b2c3d4e5f6a789012345678901234567890abcde",
        "patch_path": "/patches/curl_memory_fix.patch",
        "options": {
            "validation": "strict",
            "backup": True
        }
    }
)
print(response.json())
curl http://localhost:8000/fix_with_patch \
  -H "Content-Type: application/json" \
  -d '{
    "bug_id": "curl@b2c3d4e5f6a789012345678901234567890abcde",
    "patch_path": "/patches/curl_memory_fix.patch",
    "options": {
      "validation": "strict",
      "backup": true
    }
  }'
const response = await fetch('http://localhost:8000/fix_with_patch', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    bug_id: "curl@b2c3d4e5f6a789012345678901234567890abcde",
    patch_path: "/patches/curl_memory_fix.patch",
    options: {
      validation: "strict",
      backup: true
    }
  })
});
const data = await response.json();
console.log(data);
Response
{
  "handle": "ZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmNkZWZnaGk=",
  "method": "alternative_v2"
}

Build Patch

POST http://localhost:8000/extract_anchor_patch

Core endpoint for processing LLM responses and generating patches. Supports multiple patch application methods including direct replacement, unified diff application, and prefix-based patching. The service automatically detects the input format and selects appropriate processing strategies.

Request body

bug_id
string
Required
Bug identifier in format "project@commit_sha"
llm_response
string
Required
LLM-generated patch content (inline code or unified diff). Can contain markdown code blocks or raw diff content.
method
string
Optional
Patch application method. Options:
  • diff - Apply unified diff format patches
  • inline - Extract code from markdown and apply directly
  • inline+meta - Apply unified diff with metadata context
  • direct - Direct replacement of function body
  • prefix - Prefix-based replacement with context (default)
generate_diff
boolean
Optional
Whether to generate git diff patch file. Default: true
persist_flag
boolean
Optional
Whether to save files persistently vs temporary files. Default: false

Returns

Success Response
  • success: boolean - Operation success status
  • md5_hash: string - MD5 hash of patch content
  • patch_content: string - Generated git diff content
  • fix_p: string - Path to generated fix file
  • fix_p_diff: string - Path to generated patch file
Error Codes
  • err_extract_code_fail - Failed to extract code from markdown
  • err_invalid_bug_id_format - Bug ID format is invalid
  • err_bug_id_not_in_guidance - Bug ID not found in guidance database
  • err_context_mismatch_byte_range - Patch context doesn't match source
Example request
import requests

response = requests.post(
    "http://localhost:8000/extract_anchor_patch",
    json={
        "bug_id": "libxml2@a1b2c3d4e5f6789012345678901234567890abcd",
        "llm_response": "```cpp\nint validateInput(const char* input) {\n    if (!input || strlen(input) == 0) {\n        return 0;\n    }\n    return 1;\n}\n```",
        "method": "direct",
        "generate_diff": True,
        "persist_flag": False
    }
)
print(response.json())
curl http://localhost:8000/extract_anchor_patch \
  -H "Content-Type: application/json" \
  -d '{
    "bug_id": "libxml2@a1b2c3d4e5f6789012345678901234567890abcd",
    "llm_response": "```cpp\nint validateInput(const char* input) {\n    if (!input || strlen(input) == 0) {\n        return 0;\n    }\n    return 1;\n}\n```",
    "method": "direct",
    "generate_diff": true,
    "persist_flag": false
  }'
const response = await fetch('http://localhost:8000/extract_anchor_patch', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    bug_id: "libxml2@a1b2c3d4e5f6789012345678901234567890abcd",
    llm_response: "```cpp\nint validateInput(const char* input) {\n    if (!input || strlen(input) == 0) {\n        return 0;\n    }\n    return 1;\n}\n```",
    method: "direct",
    generate_diff: true,
    persist_flag: false
  })
});
const data = await response.json();
console.log(data);
Success Response
{
  "success": true,
  "md5_hash": "5d41402abc4b2a76b9719d911017c592",
  "patch_content": "diff --git a/src/validation.cpp...",
  "bug_id": "libxml2@a1b2c3d4e5f6789012345678901234567890abcd",
  "sha": "a1b2c3d4e5f6789012345678901234567890abcd",
  "fix_p": "/tmp/patches/tmp_xyz123.cpp",
  "fix_p_diff": "/tmp/patches/tmp_xyz123.patch",
  "func_start_byte": 450,
  "func_end_byte": 485
}