Autonomous code repair only works if it's integrated into your existing deployment infrastructure. A beautiful AI-generated fix stuck in a PR that no one reviews is useless. The real power comes when autonomous repair is embedded in your CI/CD pipeline, detecting errors in production, generating fixes, validating them against your test suite, and optionally deploying them automatically.
This guide walks you through integrating bugstack.ai into a real CI/CD workflow. We cover GitHub integration, SDK installation for JavaScript and Python, configuration of auto-merge thresholds, and monitoring.
Prerequisites
Before you start, make sure you have:
- A GitHub repository with at least one test suite (unit, integration, or end-to-end)
- A CI/CD system (GitHub Actions, GitLab CI, CircleCI, Jenkins, etc.) already configured for your repo
- Production monitoring already sending errors somewhere (error logs, APM tool, exception tracking)
- Basic familiarity with environment variables and secrets management
If you're not sure whether your team has test coverage, that's actually a good question to answer first. Autonomous code repair relies on tests to validate that fixes don't introduce regressions. More on this later.
Step 1: Create a GitHub Token for bugstack.ai
bugstack.ai needs permission to:
- Read your code and error logs
- Create branches and pull requests
- Update pull request statuses based on CI results
Generate a personal access token:
- Go to GitHub, then Settings, then Developer settings, then Personal access tokens
- Click "Generate new token (classic)"
- Name it something like
bugstack-autonomous-repair - Grant these scopes:
repo(full repository access),workflow(if you use GitHub Actions) - Click "Generate token"
- Copy the token immediately. You won't be able to see it again
If your team uses organization-level settings or needs more restricted permissions, ask your GitHub org admin about creating a service account with minimal required permissions.
Step 2: Sign Up for bugstack.ai and Connect Your Repository
- Go to bugstack.ai and create an account (Pro tier: $29/mo, Business tier: $99/mo)
- In the dashboard, click "Connect Repository"
- Paste your GitHub token
- Select the repository you want to monitor
- Choose a branch to target for auto-repairs (typically
mainordevelop)
Step 3: Install the SDK for Your Language
For JavaScript/Node.js
Install the package:
npm install --save bugstack
# or with yarn
yarn add bugstack
Initialize in your main entry point (e.g., src/index.js or app.js):
const bugstack = require('bugstack');
bugstack.init({
apiKey: process.env.BUGSTACK_API_KEY,
environment: process.env.NODE_ENV || 'development',
repository: 'your-username/your-repo',
branch: 'main',
version: process.env.APP_VERSION || '1.0.0',
});
bugstack.enableAutoRepair({
nullReferences: true,
unhandledPromises: true,
typeErrors: true,
configurationErrors: false,
});
Environment variables needed:
BUGSTACK_API_KEY=your_api_key_from_dashboard
NODE_ENV=production
APP_VERSION=1.0.0
For Python
Install the package:
pip install bugstack
Initialize early in your application:
import bugstack
bugstack.init(
api_key=os.environ.get('BUGSTACK_API_KEY'),
environment=os.environ.get('ENVIRONMENT', 'development'),
repository='your-username/your-repo',
branch='main',
version=os.environ.get('APP_VERSION', '1.0.0'),
)
bugstack.enable_auto_repair({
'none_references': True,
'unhandled_exceptions': True,
'type_errors': True,
'async_errors': True,
})
For Django, add the middleware:
# In settings.py
import bugstack
bugstack.init(...)
MIDDLEWARE = [
'bugstack.django.BugstackMiddleware',
# ... rest of middleware
]
For Flask:
from flask import Flask
import bugstack
app = Flask(__name__)
bugstack.init(...)
@app.errorhandler(Exception)
def handle_error(error):
bugstack.capture_exception(error)
return {'error': str(error)}, 500
Step 4: Configure Your CI/CD Pipeline
GitHub Actions Example
Create (or update) .github/workflows/ci.yml:
name: CI with Autonomous Repair
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
env:
BUGSTACK_API_KEY: ${{ secrets.BUGSTACK_API_KEY }}
NODE_ENV: test
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Check for new errors in this PR
if: github.event_name == 'pull_request'
run: npx bugstack check-pr
- name: Trigger autonomous repair on main
if: github.ref == 'refs/heads/main' && always()
run: npx bugstack trigger-repair
auto-merge:
needs: test
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check if PR is from bugstack
id: check-bugstack
run: |
if [[ "${{ github.event.pull_request.user.login }}" == "bugstack" ]]; then
echo "is_bugstack=true" >> $GITHUB_OUTPUT
fi
- name: Approve bugstack PR if tests pass
if: steps.check-bugstack.outputs.is_bugstack == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
event: 'APPROVE'
})
Key Configuration Points
1. Error Reporting Threshold: Not every error warrants an automatic fix. Configure which errors trigger repair: min_occurrences: 2, confidence_level: 0.85, environment_filter: production, staging.
2. Auto-Merge Thresholds: If your team wants full automation, configure when bugstack PRs can auto-merge: all_tests_pass: true, coverage_maintained: true, coverage_threshold: 0.80.
3. Exclude Certain Files or Patterns: Some code shouldn't be auto-repaired (cryptography, security-sensitive code, business logic).
Step 5: Test the Integration End-to-End
Verify that errors are captured, fixes are generated, and CI passes before going live.
For JavaScript:
// This null reference error should be detectable and auto-fixable
function processUser(user) {
return user.email.toLowerCase();
}
// bugstack will:
// 1. Capture this error
// 2. Generate a fix: add null check
// 3. Create a PR with the fix
// 4. Run your tests against it
// 5. Optionally auto-merge if all tests pass
Verify in Dashboard:
- Go to bugstack.ai dashboard
- Look for "Recent Repairs" section
- Should see PRs created and test results
- Check GitHub repo for bugstack PRs
- Verify tests run and pass
Step 6: Set Auto-Merge Policies
Auto-merge should be earned, not given. Start conservative:
Week 1-2: Approval Required. Your team reviews every PR, gives feedback to improve the system.
Week 3-4: Auto-Merge with Manual Override. Auto-merge enabled with high confidence (0.90), but manual approval still required for changes to critical paths or coverage decreases.
After 1 month: Full Autonomy (if desired). Auto-merge enabled for all fixes that pass CI with confidence above 0.85.
Monitoring and Troubleshooting
What to Monitor
- Repair Success Rate: what % of auto-generated fixes pass CI? Target: >90% on first attempt.
- PR Merge Latency: how long from error to fix in production? Expect: 5-15 minutes for simple errors.
- False Positive Rate: what % of fixes don't actually address the root cause? Target: <5%.
- Developer Satisfaction: are engineers happy with auto-repairs?
Common Issues and Solutions
"bugstack creates PRs but they don't merge": Check that GitHub Actions runs to completion, tests pass in CI, auto-merge thresholds aren't too strict, and bugstack bot has merge permission.
"The fixes don't actually fix the problems": Usually means test coverage is too low, the error pattern is too complex, or confidence level is too low.
"We're getting too many PRs": Configure higher error thresholds (min_occurrences: 5) or disable auto-repair for specific error types.
Moving to Production: A Phased Rollout
Don't flip on full autonomy overnight.
Phase 1 (Week 1): Manual review only. bugstack creates PRs for all detected errors. Team reviews and approves manually.
Phase 2 (Week 2-3): Selective auto-merge. Auto-merge only for highest-confidence fixes (>95%). Monitor merge quality closely.
Phase 3 (Week 4+): Full autonomy. Auto-merge for all fixes that pass CI. Configure alerting if success rate drops below threshold.
Ready to set this up? Start with the free trial at bugstack.ai. Questions about configuration? Check the documentation.