Skip to content

AI Issue Triage โ€‹

Date: 2026-01-15 Status: โœ… Live workflow operational (uses Claude / api.anthropic.com per .github/workflows/issue-triage.yml)

โš ๏ธ Doc partially stale (2026-05-26): most of the sections below describe the previous OpenAI-based testing harness, including a npm run test:workflows:real script and apps/web/src/__tests__/workflows/ai-issue-triage-{mock,real}.test.js files that were removed in #522. The live workflow itself still works (it calls Claude) โ€” only the local-test surface around it is outdated. Sections that mention OPENAI_API_KEY, test:workflows:real, or ai-issue-triage-{mock,real} are no longer applicable. A full rewrite tracking the current Anthropic-based pipeline is tracked separately.


Table of Contents โ€‹

  1. Quick Start
  2. What It Does
  3. Testing
  4. Configuration Validation
  5. Implementation Details

Quick Start โ€‹

See AI Triage in Action (30 seconds) โ€‹

bash
# Option 1: Mock tests (free, no setup needed)
npm run test:workflows:run -- ai-issue-triage-mock

# Option 2: Real OpenAI API (requires API key)
echo "OPENAI_API_KEY=sk-proj-YOUR_KEY_HERE" >> .env.local
npm run test:workflows:real

Expected Output:

โœ“ Bug Report: labels=['bug','help wanted'], priority='high', cost=$0.0001
โœ“ Feature: labels=['enhancement'], priority='medium'
โœ“ Docs: labels=['documentation'], priority='low'
โœ“ Question: labels=['question'], priority='low'

What It Does โ€‹

Core Workflows โ€‹

issue-triage.yml - Main AI Auto-Apply Workflow

  • Triggers: When ANY new issue is created
  • Process:
    1. Sends issue title + body to OpenAI GPT-4o-mini
    2. AI suggests 1-3 labels + priority level + reasoning
    3. Validates labels against allowed list
    4. Automatically applies labels to the issue
    5. Posts comment explaining what was applied and why
  • Fallback: If API fails, posts warning and continues
  • Philosophy: Something is better than nothing - auto-apply immediately

apply-triage.yml - Legacy Apply Workflow (Backward Compatibility)

  • Triggers: When someone comments /apply-triage on an issue
  • Status: Kept for backward compatibility but mostly redundant now

User Experience โ€‹

1. Create issue normally
   โ†“
2. Wait ~30 seconds
   โ†“
3. Labels AUTO-APPLIED by AI
   โ†“
4. AI posts comment explaining reasoning
   โ†“
5. Issue is ready for work!

Cost Analysis โ€‹

Model: GPT-4o-mini

VolumeCost per IssueMonthly Cost
100 issues$0.00006~$0.01
500 issues$0.00006~$0.03
1000 issues$0.00006~$0.06

Total cost: Less than $1/month even at high volume


Testing โ€‹

Test Commands (npm-based) โ€‹

CommandTypeCostSpeedWhen to Use
npm run test:workflows:runUnit + MockFree<1sEvery commit
npm run test:workflows:run -- ai-issue-triage-mockMock onlyFree~400msDevelopment
npm run test:workflows:realReal API~$0.0002~8sBefore deploy
npm run test:workflowsAll (with real tests in watch mode)~$0.0002~10sFull validation
bash
npm run test:workflows:run -- ai-issue-triage-mock

Coverage:

  • โœ… Bug report triage
  • โœ… Feature request triage
  • โœ… Documentation request triage
  • โœ… Question triage
  • โœ… Invalid label filtering
  • โœ… API key errors
  • โœ… Rate limit errors
  • โœ… Network failures (timeout, DNS)
  • โœ… Token usage tracking
  • โœ… Cost estimation

Best for: Daily development, rapid iteration, no API key needed

bash
# 1. Get OpenAI API key
# Go to: https://platform.openai.com/api-keys
# Click: "Create new secret key"
# Copy: Your key (starts with sk-proj-...)

# 2. Add to .env.local
echo "OPENAI_API_KEY=sk-proj-YOUR_KEY_HERE" >> .env.local

# 3. Run real API tests
npm run test:workflows:real

# Or explicitly enable:
export RUN_REAL_API_TESTS=true
npm run test:workflows -- ai-issue-triage-real

Coverage:

  • โœ… Real bug report with OpenAI
  • โœ… Real feature request with OpenAI
  • โœ… Real documentation request with OpenAI
  • โœ… Real question with OpenAI

Cost: ~$0.0002 per run (~$0.01 per 50 runs)
Best for: Local validation before deployment

Path 3: Unit Tests Only (Free, Fast) โ€‹

bash
npm run test:workflows:run

Coverage: 25 unit tests (pure logic validation)
Speed: <1ms
Best for: CI/CD, quick validation

Expected Output โ€‹

Test Files  2 passed | 1 skipped (3)
     Tests  37 passed | 4 skipped (41)
   Duration  453ms

โœ… 25 unit tests (pure logic, free)
โœ… 12 mock integration tests (simulated API, free)
โœ… 4 real API tests (actual OpenAI, ~$0.0002)

Troubleshooting Tests โ€‹

Tests are skipped?

  • Real API tests skip if OPENAI_API_KEY is not set OR RUN_REAL_API_TESTS is not true
  • This prevents accidental API costs

"Invalid API key" error?

Need verbose output?

bash
npm run test:workflows -- ai-issue-triage-mock --reporter=verbose

Run specific test?

bash
npm run test:workflows -- ai-issue-triage-mock -t "should triage a bug"

Watch mode (re-run on changes)?

bash
npm run test:workflows -- ai-issue-triage-mock --watch

Test Files โ€‹

src/__tests__/workflows/
โ”œโ”€โ”€ ai-issue-triage.test.js           # 25 unit tests
โ”œโ”€โ”€ ai-issue-triage-mock.test.js      # 12 mock integration tests
โ””โ”€โ”€ ai-issue-triage-real.test.js      # 4 real API tests

Configuration Validation โ€‹

Purpose โ€‹

Keep triage categories in sync across:

  1. .github/workflows/config/triage-categories.json (source of truth)
  2. .github/workflows/issue-triage.yml (workflow references)
  3. src/__tests__/workflows/*.test.js (test fixtures)
  4. GitHub Projects V2 "Area" field (where labels are applied)

npm Validation Task โ€‹

bash
npm run test:workflows:validate

What it checks:

  • โœ… JSON syntax validity
  • โœ… Required fields present (id, name, description)
  • โœ… Categories in .yml files match config
  • โœ… Categories in test fixtures match config
  • โœ… GitHub Projects V2 "Area" field in sync (if GH_TOKEN set)

Local Validation (Without GitHub) โ€‹

bash
npm run test:workflows:validate

Validates JSON and cross-references but skips GitHub sync check.

With GitHub Sync Check โ€‹

bash
GH_TOKEN=$(gh auth token) npm run test:workflows:validate

Also validates against GitHub Projects V2 configuration.

Manual Validation (Shell Script) โ€‹

bash
bash .github/workflows/validate-triage-config.sh

Flags:

  • --strict - Fail on any mismatches (for CI/CD)
  • --fix - Auto-sync where possible (limited by GitHub API)
  • --help - Show help

Validation Scenarios โ€‹

Add New Category to Config โ€‹

  1. Edit .github/workflows/config/triage-categories.json
  2. Add new category with id, name, description
  3. Commit and push
  4. Validation workflow runs automatically
  5. If using GitHub Projects V2: Add option to "Area" field
  6. Run: npm run test:workflows:validate
  7. โœ… All checks pass

Update Existing Category โ€‹

  1. Edit description in config
  2. Run: npm run test:workflows:validate
  3. โœ… Passes (descriptions aren't validated against GitHub)

Fix Out-of-Sync Issues โ€‹

Config has categories GitHub doesn't:

bash
# Add them to GitHub Projects V2 manually:
# 1. Go to Lantern App project > Area field settings
# 2. Add missing options
# 3. Re-run: npm run test:workflows:validate

GitHub has categories config doesn't:

bash
# Option A: Add to config
# Option B: Remove from GitHub Projects V2
# Run: npm run test:workflows:validate

GitHub Actions Workflow โ€‹

File: .github/workflows/validate-triage-config.yml

Runs automatically on:

  • Pull requests that modify .github/workflows/config/triage-categories.json
  • Weekly schedule (Monday 9 AM UTC)
  • Manual trigger via Actions tab

Failure alert:

  • Posts Discord notification to #automation-alerts
  • Includes link to validation output
  • Suggests steps to fix

Implementation Details โ€‹

Key Features & Safeguards โ€‹

โœ… Auto-Apply for ALL Issues โ€‹

  • No bot detection - ALL issues get triaged (including bot-created ones)
  • Runs immediately on issue creation
  • Safe label application: Uses append-only --add-label (never deletes existing labels)
  • Philosophy: Something is better than nothing

โœ… Label Validation โ€‹

VALID_LABELS="bug,documentation,duplicate,enhancement,good first issue,help wanted,invalid,question,wontfix"
  • Only existing GitHub labels can be applied
  • AI cannot create new labels
  • Typos and hallucinations filtered out

โœ… Permission Checks โ€‹

PERMISSION=$(gh api repos/$REPO/collaborators/$COMMENTER/permission)
if [ "$PERMISSION" = "admin" ] || [ "$PERMISSION" = "write" ]; then
  # Allow apply-triage
fi
  • Only maintainers can use /apply-triage command
  • Contributors cannot auto-apply labels

โœ… Graceful Fallback โ€‹

  • API key missing โ†’ Warning comment posted
  • API error โ†’ Error comment posted with helpful message
  • Invalid JSON โ†’ Handled with sensible defaults
  • No issue creation is ever blocked

Setup for Production โ€‹

1. Add OpenAI API Key โ€‹

bash
# Get key from: https://platform.openai.com/api-keys
# Add to: Repository Settings โ†’ Secrets โ†’ Actions
Name: OPENAI_API_KEY
Value: sk-proj-...

2. Test Workflow โ€‹

bash
# Create test issue manually
# Wait ~30 seconds
# Verify AI comment appears and labels are applied

3. Monitor Costs โ€‹

bash
# Set budget alert in OpenAI dashboard
# Recommended: $10/month limit
# Check usage: https://platform.openai.com/usage

Cost Breakdown โ€‹

ItemCostFrequencyTotal/Month
Mock tests (local)FreeEvery commit$0
Real API tests (local)~$0.0002Before deploy<$0.01
Production triage (100 issues)~$0.006Monthly<$0.01
Totalโ€”โ€”<$0.02

Files & Locations โ€‹

Core Workflows:
.github/workflows/issue-triage.yml           # Main auto-apply workflow
.github/workflows/apply-triage.yml           # Legacy apply workflow
.github/workflows/validate-triage-config.yml # Validation workflow

Configuration:
.github/workflows/config/triage-categories.json  # Categories source of truth

Test Files:
src/__tests__/workflows/ai-issue-triage.test.js           # 25 unit tests
src/__tests__/workflows/ai-issue-triage-mock.test.js      # 12 mock tests
src/__tests__/workflows/ai-issue-triage-real.test.js      # 4 real API tests

Scripts:
scripts/validate-triage-consistency.js       # npm-based consistency checker

Documentation:
docs/engineering/github/workflows/AI_TRIAGE.md  # This file (single source of truth)

Testing Checklist (Before Production) โ€‹

  • [ ] Add OPENAI_API_KEY to repository secrets
  • [ ] Run mock tests locally: npm run test:workflows:run -- ai-issue-triage-mock
  • [ ] Run real API tests: npm run test:workflows:real
  • [ ] Create test issue via GitHub UI (human user)
  • [ ] Verify AI comment appears and labels applied within 60 seconds
  • [ ] Check OpenAI usage dashboard: https://platform.openai.com/usage
  • [ ] Set up monthly budget alert ($10 recommended)
  • [ ] Test /apply-triage command as maintainer
  • [ ] Verify non-maintainers cannot use /apply-triage
  • [ ] Run validation: npm run test:workflows:validate

Rollback Plan โ€‹

If needed, disable AI triage:

Option 1: Disable Workflows

bash
Actions โ†’ issue-triage.yml โ†’ โ‹ฏ โ†’ Disable workflow
Actions โ†’ apply-triage.yml โ†’ โ‹ฏ โ†’ Disable workflow

Option 2: Remove API Key

bash
Settings โ†’ Secrets โ†’ OPENAI_API_KEY โ†’ Delete
# Workflows will gracefully degrade with warning comments

Option 3: Delete Workflows

bash
git rm .github/workflows/issue-triage.yml
git rm .github/workflows/apply-triage.yml
git commit -m "Remove AI triage workflows"

Success Metrics โ€‹

After deployment, track:

  1. Accuracy: % of AI suggestions accepted by maintainers
  2. Coverage: % of issues triaged by AI vs. manual
  3. Time Savings: Average time to first triage
  4. Cost: Actual monthly API costs
  5. Errors: Failed API calls, invalid suggestions

References โ€‹


Status: โœ… Production Ready
Breaking Changes: โŒ None
Backward Compatible: โœ… Yes
Reversible: โœ… Yes (disable workflows or remove API key)

Built with VitePress