|
| 1 | +--- |
| 2 | +title: "The Silent Migration" |
| 3 | +description: A database migration CLI silently reads the wrong directory. Institutional memory catches it before production gets corrupted. |
| 4 | +--- |
| 5 | + |
| 6 | +# The Silent Migration |
| 7 | + |
| 8 | +A migration CLI runs without error — but it's reading the wrong directory. No warning, no failure, just the wrong migrations applied to a production database. This is the kind of bug that doesn't announce itself until the damage is done. |
| 9 | + |
| 10 | +## The Situation |
| 11 | + |
| 12 | +A team manages a monorepo with two services that share the same database: |
| 13 | + |
| 14 | +``` |
| 15 | +my-project/ |
| 16 | +├── backend/ |
| 17 | +│ └── migrations/ # 12 migration files |
| 18 | +└── services/ |
| 19 | + └── migrations/ # 3 migration files |
| 20 | +``` |
| 21 | + |
| 22 | +Both directories contain migrations targeting the same database. The migration CLI determines which migrations to apply based on the current working directory — it looks for a `migrations/` folder relative to where you run the command. |
| 23 | + |
| 24 | +An agent working on a deployment task ran: |
| 25 | + |
| 26 | +```bash |
| 27 | +cd /workspace/my-project/services |
| 28 | +db-migrate push --linked |
| 29 | +``` |
| 30 | + |
| 31 | +The CLI found 3 migrations in `services/migrations/` and compared them against the 12 remote migrations already applied. It printed: |
| 32 | + |
| 33 | +``` |
| 34 | +Error: Remote migration versions not found in local migrations directory |
| 35 | +``` |
| 36 | + |
| 37 | +The agent spent 20 minutes investigating — checking remote state, comparing version hashes, verifying database connectivity. The actual problem? It was running from the wrong directory. The 12 migrations it needed were in `backend/migrations/`, not `services/migrations/`. |
| 38 | + |
| 39 | +The fix was one command: |
| 40 | + |
| 41 | +```bash |
| 42 | +cd /workspace/my-project/backend |
| 43 | +db-migrate push --linked |
| 44 | +# ✅ All 12 migrations found, push successful |
| 45 | +``` |
| 46 | + |
| 47 | +## The Scar |
| 48 | + |
| 49 | +After the incident, the agent created this scar: |
| 50 | + |
| 51 | +```json |
| 52 | +{ |
| 53 | + "learning_type": "scar", |
| 54 | + "title": "db-migrate push from wrong CWD silently reads the wrong migrations directory", |
| 55 | + "description": "When backend/migrations/ and services/migrations/ both target the same database, running db-migrate push from the wrong directory causes it to read the wrong migrations. The CLI uses migrations/ relative to CWD, not an absolute path. This produced a confusing 'Remote migration versions not found' error. The fix was simply running from the correct directory.", |
| 56 | + "severity": "medium", |
| 57 | + "scar_type": "process", |
| 58 | + "counter_arguments": [ |
| 59 | + "You might think db-migrate push uses the linked project ref to determine which migrations to read — but the project ref only determines the remote target. Local migration discovery is purely CWD-based.", |
| 60 | + "You might think the error message 'Remote versions not found' means the remote has unknown migrations — but it can also mean you're looking at the wrong local directory." |
| 61 | + ] |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +Two things make this scar effective: |
| 66 | + |
| 67 | +1. **The counter-arguments pre-empt the exact wrong assumptions** the agent made during the incident. "You might think the project ref determines which migrations to read" — that's exactly what it thought, and exactly what's wrong. |
| 68 | + |
| 69 | +2. **The title includes the mechanism** (`from wrong CWD`) not just the symptom. This makes it findable when a future agent plans any migration-related work. |
| 70 | + |
| 71 | +## The Save |
| 72 | + |
| 73 | +Three weeks later, a different session picked up a database migration task. The agent called `recall` before starting: |
| 74 | + |
| 75 | +``` |
| 76 | +recall({ plan: "run database migration for new user fields" }) |
| 77 | +``` |
| 78 | + |
| 79 | +GitMem surfaced the scar: |
| 80 | + |
| 81 | +``` |
| 82 | +🧠 INSTITUTIONAL MEMORY ACTIVATED |
| 83 | +
|
| 84 | +Found 2 relevant scars for your plan: |
| 85 | +
|
| 86 | +🟡 db-migrate push from wrong CWD silently reads the wrong |
| 87 | + migrations directory (medium, score: 0.74) |
| 88 | + When backend/migrations/ and services/migrations/ both target |
| 89 | + the same database, running db-migrate push from the wrong |
| 90 | + directory causes it to read the wrong migrations... |
| 91 | +``` |
| 92 | + |
| 93 | +The agent confirmed the scar before proceeding: |
| 94 | + |
| 95 | +``` |
| 96 | +confirm_scars([{ |
| 97 | + scar_id: "...", |
| 98 | + decision: "APPLYING", |
| 99 | + evidence: "Verified CWD is /workspace/my-project/backend before running db-migrate push. Confirmed 12 migration files visible in backend/migrations/.", |
| 100 | + relevance: "high" |
| 101 | +}]) |
| 102 | +``` |
| 103 | + |
| 104 | +The agent explicitly checked its working directory, confirmed the right migrations were visible, and then ran the command. No 20-minute debugging session. No risk of applying the wrong migrations to production. |
| 105 | + |
| 106 | +## The Takeaway |
| 107 | + |
| 108 | +This example shows three properties of effective institutional memory: |
| 109 | + |
| 110 | +**Silent failures are the most valuable scars.** The migration CLI didn't crash — it ran successfully against the wrong data. These bugs don't leave stack traces. They leave corrupted databases. A scar is the only thing standing between "it worked" and "it worked on the wrong thing." |
| 111 | + |
| 112 | +**Counter-arguments encode the debugging dead ends.** The two counter-arguments in this scar document the exact wrong mental models that led to the 20-minute investigation. Future agents skip those dead ends entirely because the scar says "you might think X — but actually Y." |
| 113 | + |
| 114 | +**The confirm protocol forces verification.** The agent didn't just see the scar and move on. The `APPLYING` decision required past-tense evidence: "Verified CWD is `/workspace/my-project/backend`." This turns a warning into a checklist item with proof of compliance. |
0 commit comments