# Lint Cleanup Rollback Procedures

Emergency procedures for rolling back lint cleanup changes if production issues occur.

**Last Updated**: 2025-10-20 (Issue #159 - Documentation & Rollout)

---

## Table of Contents

- [When to Rollback](#when-to-rollback)
- [Quick Rollback (Emergency)](#quick-rollback-emergency---5-minutes)
- [Selective Rollback (Specific Project)](#selective-rollback-specific-project---15-minutes)
- [Configuration-Only Rollback](#configuration-only-rollback---10-minutes)
- [Full Rollback (Last Resort)](#full-rollback-last-resort---30-minutes)
- [Post-Rollback Actions](#post-rollback-actions)
- [Validation After Rollback](#validation-after-rollback)
- [Emergency Contacts](#emergency-contacts)

---

## When to Rollback

Consider rollback if:
- ✅ **Production service is broken** due to lint changes
- ✅ **CI pipeline is blocked** and preventing critical hotfixes
- ✅ **Multiple projects failing** with lint-related errors
- ✅ **Team is blocked** from committing/deploying

Do NOT rollback if:
- ❌ Single developer having local issues (help them fix it)
- ❌ Non-critical warnings (fix forward)
- ❌ Pre-existing issues unrelated to lint changes (validate first)

---

## Quick Rollback (Emergency - < 5 minutes)

**Scenario**: Production is broken, need immediate fix

**Impact**: Reverts ALL lint cleanup work

### Steps

```bash
# Step 1: Identify the merge/commit range to revert
git log --oneline --grep="lint" --since="2025-10-19" | head -10

# Step 2: Revert the specific commits (most recent first)
# Example commit SHAs from lint cleanup:
git revert c3e1e0e --no-edit  # CONTRIBUTING.md
git revert bae7d49 --no-edit  # CI config
# Continue for all lint-related commits...

# Step 3: Push immediately
git push origin main

# Step 4: Verify production services
curl https://slide-system.railway.app/health
# Check Railway dashboard for deployment status
```

### Alternative: Reset to Pre-Cleanup State

**WARNING**: Only if git revert fails or causes conflicts

```bash
# Find the commit before lint cleanup started
git log --oneline | grep -B1 "lint cleanup initiative" | tail -1

# Example: Reset to before cleanup
# git reset --hard <commit-before-cleanup>
# git push origin main --force  # REQUIRES TEAM APPROVAL

# This deletes all work - use revert instead if possible!
```

---

## Selective Rollback (Specific Project - < 15 minutes)

**Scenario**: One project broken, others working fine

**Impact**: Reverts changes for specific project only

### Steps

```bash
# Step 1: Identify commits for the problematic project
git log --oneline --grep="slide-system" --since="2025-10-19" | head -5

# Example output:
# f03d518 Wave 3: Production apps (voice-demo-ui, slide-system)
# ...

# Step 2: Revert specific commit
git revert f03d518 --no-edit

# OR: Restore specific files from before cleanup
git log --oneline --before="2025-10-19" -- apps/slide-system/
# Note the commit SHA before changes

git checkout <commit-sha> -- apps/slide-system/
git add apps/slide-system/
git commit -m "revert(lint): Rollback slide-system lint changes due to production issue"

# Step 3: Validate locally
pnpm nx lint slide-system
pnpm nx test slide-system
pnpm nx build slide-system --configuration=production

# Step 4: Push
git push origin main

# Step 5: Deploy to Railway
# Railway auto-deploys, or use:
# railway up --service slide-system
```

---

## Configuration-Only Rollback (< 10 minutes)

**Scenario**: New rules too strict, need to relax temporarily

**Impact**: Reverts ESLint config only, keeps code fixes

### Steps

```bash
# Step 1: Find config commit
git log --oneline -- .eslintrc.js | head -3
# Example: 394d3bc feat(lint): Apply ESLint config changes

# Step 2: Revert config changes
git revert 394d3bc --no-edit

# OR: Manual config relaxation
# Edit .eslintrc.js and change specific rules back to 'warn':
```

Edit `.eslintrc.js`:
```javascript
// Change error back to warn for specific rule
'@typescript-eslint/no-explicit-any': 'warn',  // was: 'error'
```

```bash
# Step 3: Commit config change
git add .eslintrc.js
git commit -m "revert(config): Temporarily relax no-explicit-any to warn"

# Step 4: Validate (should pass now)
pnpm nx run-many --target=lint --all --max-warnings=100

# Step 5: Push
git push origin main
```

**Note**: Code improvements remain, only enforcement level changes

---

## Full Rollback (Last Resort - < 30 minutes)

**Scenario**: Multiple projects broken, extensive issues

**Impact**: Complete removal of all lint cleanup work

**WARNING**: Requires team coordination and approval

### Steps

```bash
# Step 1: Create emergency branch
git checkout -b emergency/rollback-lint-cleanup-$(date +%Y%m%d)

# Step 2: Document current state
git log --oneline --since="2025-10-19" --grep="lint" > rollback-commits.txt
git diff main...HEAD > rollback-diff.patch

# Step 3: Find commit before cleanup started
git log --oneline | grep -B1 "Baseline Capture" | tail -1
# Example: abc1234 (commit before cleanup)

# Step 4: Reset to that commit
git reset --hard abc1234

# Step 5: Force push (DANGER - requires approval)
# DO NOT DO THIS without team lead approval!

echo "⚠️  STOP: Get approval before force push!"
echo "Contact: [Team Lead Name]"
echo "After approval:"
echo "  git push origin main --force"

# Step 6: After approval, force push
# git push origin main --force
```

### Post-Force-Push Actions

```bash
# 1. Notify team immediately
# Send Slack message to #engineering:
echo "🚨 EMERGENCY ROLLBACK - Force push to main completed
All developers: git fetch origin && git reset --hard origin/main
Reason: [explain issue]
Contact: [your name]"

# 2. Verify services
curl https://slide-system.railway.app/health
curl https://voice-demo-ui.railway.app/

# 3. Monitor CI
gh run list --workflow=ci.yml --limit 3

# 4. Create incident report (see below)
```

---

## Post-Rollback Actions

After ANY rollback, complete these steps:

### 1. Create Incident Report

Create `.claude/incidents/lint-rollback-YYYYMMDD.md`:

```markdown
# Lint Cleanup Rollback Incident Report

**Date**: YYYY-MM-DD HH:MM UTC
**Severity**: [Critical/High/Medium]
**Rolled Back By**: [Your Name]
**Rollback Type**: [Quick/Selective/Config/Full]

## Timeline

- HH:MM - Issue detected: [description]
- HH:MM - Decision to rollback
- HH:MM - Rollback executed
- HH:MM - Services restored

## Root Cause

[What went wrong? Be specific]

## Impact

- Services affected: [list]
- Duration of outage: [X minutes]
- Users impacted: [estimate]

## Actions Taken

[Step-by-step what was done]

## Lessons Learned

[What should we do differently?]

## Follow-up Actions

- [ ] Fix root cause
- [ ] Update baseline validation
- [ ] Re-test before re-applying
- [ ] Team post-mortem scheduled
```

### 2. Identify Root Cause

```bash
# Compare pre/post states
git diff <before-commit> <after-commit>

# Check which file/change caused issue
git bisect start
git bisect bad HEAD
git bisect good <commit-before-cleanup>
# Test at each step until bad commit found
```

### 3. Update Baseline

If pre-existing issues were misidentified:

```bash
# Create new baseline
mkdir -p baseline/$(date +%Y%m%d)
pnpm nx run-many --target=lint --all > baseline/lint-actual.txt
pnpm nx run-many --target=test --all > baseline/test-actual.txt
pnpm nx run-many --target=build --all > baseline/build-actual.txt

# Document in epic
echo "Updated baseline after rollback - see baseline/$(date +%Y%m%d)/" >> .claude/epics/clean-up-lints/epic.md
```

### 4. Plan Fix

Before re-attempting cleanup:

1. **Validate assumption**: Why did we think this was safe?
2. **Test thoroughly**: What testing did we miss?
3. **Incremental approach**: Can we apply changes more gradually?
4. **Team review**: Get second opinions on plan

### 5. Team Post-Mortem

Schedule within 24 hours:
- **What happened?** (timeline)
- **Why?** (root cause)
- **What can we improve?** (process, testing, validation)
- **Action items** (assign owners and deadlines)

---

## Validation After Rollback

Ensure system is healthy after rollback:

### Production Services

```bash
# Check all production endpoints
curl -f https://slide-system.railway.app/health || echo "❌ FAILED"
curl -f https://voice-demo-ui.railway.app/ || echo "❌ FAILED"

# Check Railway deployments
# Visit Railway dashboard or:
# railway status --service slide-system
```

### CI Pipeline

```bash
# Check recent CI runs
gh run list --workflow=ci.yml --limit 3

# Verify latest run passed
gh run view $(gh run list --limit 1 --json databaseId --jq '.[0].databaseId')
```

### Developer Workflow

```bash
# Test that developers can commit
git commit -m "test: verify rollback successful" --allow-empty
git push origin main

# Verify pre-commit hooks work
# (should pass with old rules)
```

### Production Metrics

- Monitor error rates (Sentry, Datadog, etc.)
- Check API response times
- Verify customer-facing features work
- Monitor for increased error logs

---

## Emergency Contacts

**NOTE**: Fill in actual contacts for your team

### On-Call Rotation
- **Primary**: [Name, Phone, Slack]
- **Secondary**: [Name, Phone, Slack]

### Specialized Contacts
- **Lint Initiative Lead**: [Name, Slack: @handle]
- **DevOps Lead**: [Name, Slack: @handle] (Railway/CI issues)
- **Engineering Manager**: [Name, Phone, Slack]

### Escalation Path
1. Try to resolve (< 15 min)
2. Contact lint initiative lead (< 30 min)
3. Escalate to on-call (< 45 min)
4. Page engineering manager (critical only)

### Communication Channels
- **Slack**: #engineering (public) or #incidents (critical)
- **PagerDuty**: [If configured]
- **Status Page**: [If applicable]

---

## Rollback Decision Tree

```
Is production broken?
├─ Yes
│  ├─ Multiple services down? → Full Rollback
│  ├─ One service down? → Selective Rollback
│  └─ Can we fix forward quickly (< 30 min)? → Fix Forward
└─ No
   ├─ CI blocking critical hotfixes? → Config Rollback
   ├─ Team completely blocked? → Config Rollback
   └─ Single developer issue? → Help Developer Fix
```

---

## Prevention

To avoid needing rollbacks:

1. **Comprehensive baseline** - Know pre-existing state
2. **Incremental rollout** - Change one project at a time
3. **Validation at each step** - Lint, test, build after each change
4. **Staged deployment** - Test in dev/staging before production
5. **Rollback plan ready** - Document before you need it (this doc!)
6. **Team communication** - Everyone knows what's changing
7. **Monitoring** - Watch metrics during/after rollout

---

**Questions or Issues?**
- Check [LINT_TROUBLESHOOTING.md](./LINT_TROUBLESHOOTING.md) first
- Contact lint initiative lead
- Create incident if critical

---

*Generated as part of Issue #159 - Documentation & Rollout*
*Epic: clean-up-lints (#154)*
