AI Janitor PR Workflow
AI Janitor generates pull requests to remove stale feature flags from your codebase. Each PR is structured, reviewable, and follows your team's existing code review process — because AI writes the diff, but humans make the final call.
PR Lifecycle
Detect
AI identifies stale flags and confirms they can be safely removed.
Generate
AI creates a branch, removes flag checks, and opens a PR.
Review
Your team reviews the PR like any other code change.
Merge
PR passes CI and review, then merges. Flag is cleaned up.
What the PR Looks Like
Every AI Janitor PR follows a consistent, review-friendly template. Here's an example of what your team will see:
PR Title: chore: remove stale flag "new-checkout"
🤖 AI Janitor — Automated Flag Cleanup
| Flag | new-checkout |
| Status | always_on — flag has been enabled at 100% for 45 days with no evaluations in the last 30 days |
| Confidence | 94% — high confidence this flag is safe to remove |
| Files Changed | 3 files across 1 repository |
| Active Path | The flag was always ON. The PR removes the flag check and keeps the enabled code path. |
⚠️ Review Checklist
- Verify the flag is indeed no longer needed in production
- Confirm the preserved code path is the correct one
- Check that no tests rely on the flag being configurable
- Ensure the flag key is also removed from the FeatureSignals dashboard
1. AI analyzes the flag
For each stale candidate, AI Janitor examines the flag's evaluation history, the source code references, and the surrounding code context to determine:
- Which code path is always taken (the "active" branch)
- Whether the flag check can be removed without side effects
- If any imports, variables, or functions become unused after removal
- Whether the removal affects test coverage
2. Branch is created
AI Janitor creates a new branch in your repository following the naming convention:
Bash12345# Branch naming pattern (configurable) ai-janitor/remove-{flag-key}-{timestamp} # Example ai-janitor/remove-new-checkout-20260115The branch is created from the default branch (main/master) at the time of scan. If the default branch has advanced significantly since the scan, you may need to update the branch before merging.
3. Flag check is removed from each file
AI Janitor surgically removes the flag evaluation while preserving the active code path. Here's an example of what the diff looks like:
Example diffDiff12345678910111213141516// Before (with flag check) async function checkout(user: User) { - const useNewCheckout = await client.boolVariation( - 'new-checkout', - { key: user.id }, - false, - ); - - if (useNewCheckout) { - return renderNewCheckout(user); - } - return renderLegacyCheckout(user); + return renderNewCheckout(user); } // After (flag removed, active path preserved)4. PR is opened
The PR includes all the information your team needs to review with confidence:
- Automated labels (configurable via
pr_labels) - Link back to the AI Janitor scan report
- Confidence score and reasoning
- Checklist for human reviewers
- Diff for each changed file
- Automated labels (configurable via
Review Process
AI Janitor PRs integrate with your existing code review workflow:
Human Review Required
AI Janitor PRs are not special — they go through the same review process as any other PR. Required reviewers, CODEOWNERS, and branch protection rules all apply.
CI/CD Gates
Your existing CI checks run on AI Janitor PRs just like any other PR. If tests fail, the PR won't merge. AI Janitor can be configured to monitor CI status and comment on the PR when checks pass.
Auto-Merge (Optional)
For teams with high confidence in AI Janitor results, you can enable auto-merge. When enabled, PRs that pass CI and have a confidence score ≥ the configured threshold are automatically merged. This is NOT recommended without extensive testing.
Auto-Merge Configuration
Use with caution
To enable auto-merge, configure these options in your .ai-janitor.json:
{
"auto_create_prs": true,
"auto_merge_prs": true,
"min_confidence_score": 90,
"auto_merge_conditions": {
"require_ci_pass": true,
"require_no_conflicts": true,
"require_approved_review": false,
"max_files_changed": 10,
"max_lines_changed": 200
}
}