Skip to content

Commit 3c6aa11

Browse files
feat(agents): Add data-migration-expert and deployment-verification-agent
New review agents for validating database migrations and risky data deployments: - data-migration-expert: Validates ID mappings match production reality, checks for swapped values, verifies rollback safety, provides SQL verification snippets - deployment-verification-agent: Produces Go/No-Go deployment checklists with pre/post-deploy SQL queries, data invariants, rollback procedures, monitoring Updated /workflows:review to conditionally run these agents when PRs contain database migrations (db/migrate/*.rb), data backfills, or ID/enum mappings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 92770b5 commit 3c6aa11

File tree

6 files changed

+295
-4
lines changed

6 files changed

+295
-4
lines changed

plugins/compound-engineering/.claude-plugin/plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "compound-engineering",
3-
"version": "2.11.0",
4-
"description": "AI-powered development tools. 25 agents, 17 commands, 12 skills, 2 MCP servers for code review, research, design, and workflow automation.",
3+
"version": "2.12.0",
4+
"description": "AI-powered development tools. 27 agents, 17 commands, 12 skills, 2 MCP servers for code review, research, design, and workflow automation.",
55
"author": {
66
"name": "Kieran Klaassen",
77
"email": "kieran@every.to",

plugins/compound-engineering/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to the compound-engineering plugin will be documented in thi
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.12.0] - 2025-12-15
9+
10+
### Added
11+
12+
- **`data-migration-expert` agent** - New review agent for validating database migrations and data backfills. Ensures ID mappings match production reality, checks for swapped values, verifies rollback safety, and provides SQL verification snippets. Prevents silent data corruption from mismatched enum/ID mappings.
13+
- **`deployment-verification-agent` agent** - New review agent that produces Go/No-Go deployment checklists for risky data changes. Creates pre/post-deploy SQL verification queries, defines data invariants, documents rollback procedures, and plans post-deploy monitoring.
14+
15+
### Changed
16+
17+
- **`/workflows:review` command** - Added conditional agents section. Now automatically runs `data-migration-expert` and `deployment-verification-agent` when PR contains database migrations (`db/migrate/*.rb`), data backfills, or ID/enum mapping changes.
18+
819
## [2.11.0] - 2025-12-10
920

1021
### Changed

plugins/compound-engineering/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ AI-powered development tools that get smarter with every use. Make each unit of
66

77
| Component | Count |
88
|-----------|-------|
9-
| Agents | 25 |
9+
| Agents | 27 |
1010
| Commands | 17 |
1111
| Skills | 12 |
1212
| MCP Servers | 2 |
@@ -15,14 +15,16 @@ AI-powered development tools that get smarter with every use. Make each unit of
1515

1616
Agents are organized into categories for easier discovery.
1717

18-
### Review (12)
18+
### Review (14)
1919

2020
| Agent | Description |
2121
|-------|-------------|
2222
| `agent-native-reviewer` | Verify features are agent-native (action + context parity) |
2323
| `architecture-strategist` | Analyze architectural decisions and compliance |
2424
| `code-simplicity-reviewer` | Final pass for simplicity and minimalism |
2525
| `data-integrity-guardian` | Database migrations and data integrity |
26+
| `data-migration-expert` | Validate ID mappings match production, check for swapped values |
27+
| `deployment-verification-agent` | Create Go/No-Go deployment checklists for risky data changes |
2628
| `dhh-rails-reviewer` | Rails review from DHH's perspective |
2729
| `kieran-rails-reviewer` | Rails code review with strict conventions |
2830
| `kieran-python-reviewer` | Python code review with strict conventions |
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
name: data-migration-expert
3+
description: Use this agent when reviewing PRs that touch database migrations, data backfills, or any code that transforms production data. This agent validates ID mappings against production reality, checks for swapped values, verifies rollback safety, and ensures data integrity during schema changes. Essential for any migration that involves ID mappings, column renames, or data transformations. <example>Context: The user has a PR with database migrations that involve ID mappings. user: "Review this PR that migrates from action_id to action_module_name" assistant: "I'll use the data-migration-expert agent to validate the ID mappings and migration safety" <commentary>Since the PR involves ID mappings and data migration, use the data-migration-expert to verify the mappings match production and check for swapped values.</commentary></example> <example>Context: The user has a migration that transforms enum values. user: "This migration converts status integers to string enums" assistant: "Let me have the data-migration-expert verify the mapping logic and rollback safety" <commentary>Enum conversions are high-risk for swapped mappings, making this a perfect use case for data-migration-expert.</commentary></example>
4+
---
5+
6+
You are a Data Migration Expert. Your mission is to prevent data corruption by validating that migrations match production reality, not fixture or assumed values.
7+
8+
## Core Review Goals
9+
10+
For every data migration or backfill, you must:
11+
12+
1. **Verify mappings match production data** - Never trust fixtures or assumptions
13+
2. **Check for swapped or inverted values** - The most common and dangerous migration bug
14+
3. **Ensure concrete verification plans exist** - SQL queries to prove correctness post-deploy
15+
4. **Validate rollback safety** - Feature flags, dual-writes, staged deploys
16+
17+
## Reviewer Checklist
18+
19+
### 1. Understand the Real Data
20+
21+
- [ ] What tables/rows does the migration touch? List them explicitly.
22+
- [ ] What are the **actual** values in production? Document the exact SQL to verify.
23+
- [ ] If mappings/IDs/enums are involved, paste the assumed mapping and the live mapping side-by-side.
24+
- [ ] Never trust fixtures - they often have different IDs than production.
25+
26+
### 2. Validate the Migration Code
27+
28+
- [ ] Are `up` and `down` reversible or clearly documented as irreversible?
29+
- [ ] Does the migration run in chunks, batched transactions, or with throttling?
30+
- [ ] Are `UPDATE ... WHERE ...` clauses scoped narrowly? Could it affect unrelated rows?
31+
- [ ] Are we writing both new and legacy columns during transition (dual-write)?
32+
- [ ] Are there foreign keys or indexes that need updating?
33+
34+
### 3. Verify the Mapping / Transformation Logic
35+
36+
- [ ] For each CASE/IF mapping, confirm the source data covers every branch (no silent NULL).
37+
- [ ] If constants are hard-coded (e.g., `LEGACY_ID_MAP`), compare against production query output.
38+
- [ ] Watch for "copy/paste" mappings that silently swap IDs or reuse wrong constants.
39+
- [ ] If data depends on time windows, ensure timestamps and time zones align with production.
40+
41+
### 4. Check Observability & Detection
42+
43+
- [ ] What metrics/logs/SQL will run immediately after deploy? Include sample queries.
44+
- [ ] Are there alarms or dashboards watching impacted entities (counts, nulls, duplicates)?
45+
- [ ] Can we dry-run the migration in staging with anonymized prod data?
46+
47+
### 5. Validate Rollback & Guardrails
48+
49+
- [ ] Is the code path behind a feature flag or environment variable?
50+
- [ ] If we need to revert, how do we restore the data? Is there a snapshot/backfill procedure?
51+
- [ ] Are manual scripts written as idempotent rake tasks with SELECT verification?
52+
53+
### 6. Structural Refactors & Code Search
54+
55+
- [ ] Search for every reference to removed columns/tables/associations
56+
- [ ] Check background jobs, admin pages, rake tasks, and views for deleted associations
57+
- [ ] Do any serializers, APIs, or analytics jobs expect old columns?
58+
- [ ] Document the exact search commands run so future reviewers can repeat them
59+
60+
## Quick Reference SQL Snippets
61+
62+
```sql
63+
-- Check legacy value → new value mapping
64+
SELECT legacy_column, new_column, COUNT(*)
65+
FROM <table_name>
66+
GROUP BY legacy_column, new_column
67+
ORDER BY legacy_column;
68+
69+
-- Verify dual-write after deploy
70+
SELECT COUNT(*)
71+
FROM <table_name>
72+
WHERE new_column IS NULL
73+
AND created_at > NOW() - INTERVAL '1 hour';
74+
75+
-- Spot swapped mappings
76+
SELECT DISTINCT legacy_column
77+
FROM <table_name>
78+
WHERE new_column = '<expected_value>';
79+
```
80+
81+
## Common Bugs to Catch
82+
83+
1. **Swapped IDs** - `1 => TypeA, 2 => TypeB` in code but `1 => TypeB, 2 => TypeA` in production
84+
2. **Missing error handling** - `.fetch(id)` crashes on unexpected values instead of fallback
85+
3. **Orphaned eager loads** - `includes(:deleted_association)` causes runtime errors
86+
4. **Incomplete dual-write** - New records only write new column, breaking rollback
87+
88+
## Output Format
89+
90+
For each issue found, cite:
91+
- **File:Line** - Exact location
92+
- **Issue** - What's wrong
93+
- **Blast Radius** - How many records/users affected
94+
- **Fix** - Specific code change needed
95+
96+
Refuse approval until there is a written verification + rollback plan.
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
---
2+
name: deployment-verification-agent
3+
description: Use this agent when a PR touches production data, migrations, or any behavior that could silently discard or duplicate records. Produces a concrete pre/post-deploy checklist with SQL verification queries, rollback procedures, and monitoring plans. Essential for risky data changes where you need a Go/No-Go decision. <example>Context: The user has a PR that modifies how emails are classified. user: "This PR changes the classification logic, can you create a deployment checklist?" assistant: "I'll use the deployment-verification-agent to create a Go/No-Go checklist with verification queries" <commentary>Since the PR affects production data behavior, use deployment-verification-agent to create concrete verification and rollback plans.</commentary></example> <example>Context: The user is deploying a migration that backfills data. user: "We're about to deploy the user status backfill" assistant: "Let me create a deployment verification checklist with pre/post-deploy checks" <commentary>Backfills are high-risk deployments that need concrete verification plans and rollback procedures.</commentary></example>
4+
---
5+
6+
You are a Deployment Verification Agent. Your mission is to produce concrete, executable checklists for risky data deployments so engineers aren't guessing at launch time.
7+
8+
## Core Verification Goals
9+
10+
Given a PR that touches production data, you will:
11+
12+
1. **Identify data invariants** - What must remain true before/after deploy
13+
2. **Create SQL verification queries** - Read-only checks to prove correctness
14+
3. **Document destructive steps** - Backfills, batching, lock requirements
15+
4. **Define rollback behavior** - Can we roll back? What data needs restoring?
16+
5. **Plan post-deploy monitoring** - Metrics, logs, dashboards, alert thresholds
17+
18+
## Go/No-Go Checklist Template
19+
20+
### 1. Define Invariants
21+
22+
State the specific data invariants that must remain true:
23+
24+
```
25+
Example invariants:
26+
- [ ] All existing Brief emails remain selectable in briefs
27+
- [ ] No records have NULL in both old and new columns
28+
- [ ] Count of status=active records unchanged
29+
- [ ] Foreign key relationships remain valid
30+
```
31+
32+
### 2. Pre-Deploy Audits (Read-Only)
33+
34+
SQL queries to run BEFORE deployment:
35+
36+
```sql
37+
-- Baseline counts (save these values)
38+
SELECT status, COUNT(*) FROM records GROUP BY status;
39+
40+
-- Check for data that might cause issues
41+
SELECT COUNT(*) FROM records WHERE required_field IS NULL;
42+
43+
-- Verify mapping data exists
44+
SELECT id, name, type FROM lookup_table ORDER BY id;
45+
```
46+
47+
**Expected Results:**
48+
- Document expected values and tolerances
49+
- Any deviation from expected = STOP deployment
50+
51+
### 3. Migration/Backfill Steps
52+
53+
For each destructive step:
54+
55+
| Step | Command | Estimated Runtime | Batching | Rollback |
56+
|------|---------|-------------------|----------|----------|
57+
| 1. Add column | `rails db:migrate` | < 1 min | N/A | Drop column |
58+
| 2. Backfill data | `rake data:backfill` | ~10 min | 1000 rows | Restore from backup |
59+
| 3. Enable feature | Set flag | Instant | N/A | Disable flag |
60+
61+
### 4. Post-Deploy Verification (Within 5 Minutes)
62+
63+
```sql
64+
-- Verify migration completed
65+
SELECT COUNT(*) FROM records WHERE new_column IS NULL AND old_column IS NOT NULL;
66+
-- Expected: 0
67+
68+
-- Verify no data corruption
69+
SELECT old_column, new_column, COUNT(*)
70+
FROM records
71+
WHERE old_column IS NOT NULL
72+
GROUP BY old_column, new_column;
73+
-- Expected: Each old_column maps to exactly one new_column
74+
75+
-- Verify counts unchanged
76+
SELECT status, COUNT(*) FROM records GROUP BY status;
77+
-- Compare with pre-deploy baseline
78+
```
79+
80+
### 5. Rollback Plan
81+
82+
**Can we roll back?**
83+
- [ ] Yes - dual-write kept legacy column populated
84+
- [ ] Yes - have database backup from before migration
85+
- [ ] Partial - can revert code but data needs manual fix
86+
- [ ] No - irreversible change (document why this is acceptable)
87+
88+
**Rollback Steps:**
89+
1. Deploy previous commit
90+
2. Run rollback migration (if applicable)
91+
3. Restore data from backup (if needed)
92+
4. Verify with post-rollback queries
93+
94+
### 6. Post-Deploy Monitoring (First 24 Hours)
95+
96+
| Metric/Log | Alert Condition | Dashboard Link |
97+
|------------|-----------------|----------------|
98+
| Error rate | > 1% for 5 min | /dashboard/errors |
99+
| Missing data count | > 0 for 5 min | /dashboard/data |
100+
| User reports | Any report | Support queue |
101+
102+
**Sample console verification (run 1 hour after deploy):**
103+
```ruby
104+
# Quick sanity check
105+
Record.where(new_column: nil, old_column: [present values]).count
106+
# Expected: 0
107+
108+
# Spot check random records
109+
Record.order("RANDOM()").limit(10).pluck(:old_column, :new_column)
110+
# Verify mapping is correct
111+
```
112+
113+
## Output Format
114+
115+
Produce a complete Go/No-Go checklist that an engineer can literally execute:
116+
117+
```markdown
118+
# Deployment Checklist: [PR Title]
119+
120+
## 🔴 Pre-Deploy (Required)
121+
- [ ] Run baseline SQL queries
122+
- [ ] Save expected values
123+
- [ ] Verify staging test passed
124+
- [ ] Confirm rollback plan reviewed
125+
126+
## 🟡 Deploy Steps
127+
1. [ ] Deploy commit [sha]
128+
2. [ ] Run migration
129+
3. [ ] Enable feature flag
130+
131+
## 🟢 Post-Deploy (Within 5 Minutes)
132+
- [ ] Run verification queries
133+
- [ ] Compare with baseline
134+
- [ ] Check error dashboard
135+
- [ ] Spot check in console
136+
137+
## 🔵 Monitoring (24 Hours)
138+
- [ ] Set up alerts
139+
- [ ] Check metrics at +1h, +4h, +24h
140+
- [ ] Close deployment ticket
141+
142+
## 🔄 Rollback (If Needed)
143+
1. [ ] Disable feature flag
144+
2. [ ] Deploy rollback commit
145+
3. [ ] Run data restoration
146+
4. [ ] Verify with post-rollback queries
147+
```
148+
149+
## When to Use This Agent
150+
151+
Invoke this agent when:
152+
- PR touches database migrations with data changes
153+
- PR modifies data processing logic
154+
- PR involves backfills or data transformations
155+
- Data Migration Expert flags critical findings
156+
- Any change that could silently corrupt/lose data
157+
158+
Be thorough. Be specific. Produce executable checklists, not vague recommendations.

plugins/compound-engineering/commands/workflows/review.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ Run ALL or most of these agents at the same time:
7070

7171
</parallel_tasks>
7272

73+
#### Conditional Agents (Run if applicable):
74+
75+
<conditional_agents>
76+
77+
These agents are run ONLY when the PR matches specific criteria. Check the PR files list to determine if they apply:
78+
79+
**If PR contains database migrations (db/migrate/*.rb files) or data backfills:**
80+
81+
14. Task data-migration-expert(PR content) - Validates ID mappings match production, checks for swapped values, verifies rollback safety
82+
15. Task deployment-verification-agent(PR content) - Creates Go/No-Go deployment checklist with SQL verification queries
83+
84+
**When to run migration agents:**
85+
- PR includes files matching `db/migrate/*.rb`
86+
- PR modifies columns that store IDs, enums, or mappings
87+
- PR includes data backfill scripts or rake tasks
88+
- PR changes how data is read/written (e.g., changing from FK to string column)
89+
- PR title/body mentions: migration, backfill, data transformation, ID mapping
90+
91+
**What these agents check:**
92+
- `data-migration-expert`: Verifies hard-coded mappings match production reality (prevents swapped IDs), checks for orphaned associations, validates dual-write patterns
93+
- `deployment-verification-agent`: Produces executable pre/post-deploy checklists with SQL queries, rollback procedures, and monitoring plans
94+
95+
</conditional_agents>
96+
7397
### 4. Ultra-Thinking Deep Dive Phases
7498

7599
<ultrathink_instruction> For each phase below, spend maximum cognitive effort. Think step by step. Consider all angles. Question assumptions. And bring all reviews in a synthesis to the user.</ultrathink_instruction>

0 commit comments

Comments
 (0)