Ketika AI Code Go Wrong: Post-Mortem dari 3 Incident Production
Gue bukan cherry-picking worst case. Ini incident yang terjadi di startup/scale-up tertentu karena terlalu aggressive pake vibe coding tanpa proper review. Names dan dates di-anonymize, tapi konteks 100% real.
Incident 1: Silent Data Corruption (48 jam downtime partial)
Context: SaaS product dengan 10K active users, database migration dari MongoDB ke PostgreSQL.
Apa yang terjadi:
Prompt: "Buat script untuk migrate data dari MongoDB ke PostgreSQL dengan transformation rules X, Y, Z."
AI generate script yang work di staging. Deploy ke production. Everything seemed fine for 6 hours.
Kemudian user report: beberapa data hilang, beberapa data duplikat. Bug hunting show: script punya race condition saat concurrent inserts.
Root cause: Developer tidak read kode, assume AI tahu best practice transaction handling. Kode syntactically correct, tapi missing critical piece dari production database operation.
Lesson: Database operation HARUS manual review. Jangan pernah delegate ini 100% ke AI. Risk terlalu high.
Incident 2: Authentication Bypass (Security, Critical)
Context: B2B SaaS, multi-tenant architecture.
Apa yang terjadi:
Prompt: "Buat middleware untuk check apakah user punya permission untuk access resource ini. User punya role (admin, editor, viewer)."
AI generate middleware yang check role. Code look reasonable. Deploy.
Security audit 2 bulan kemudian: vulnerability — user bisa access other tenant data dengan manipulating query parameter.
Root cause: Developer assume AI faham context multi-tenant requirement. Prompt tidak spesifik enough. Security review di-skip karena "AI generated anyway".
Lesson: Authorization logic adalah business-critical. Never skip security review. Minta AI explain setiap line, especially yang involve permission check.
Incident 3: Memory Leak yang Creeping (Performance degradation)
Context: Real-time collaboration app, websocket server yang handle 50K concurrent connections.
Apa yang terjadi:
Prompt: "Buat event listener untuk user connection, simpan user state dalam memory dengan map, dan cleanup saat disconnect."
AI generate code yang work fine di testing. Production pun fine untuk first 2 weeks.
Kemudian: server memory usage gradually climb. Setelah 1 month, OOM crash.
Root cause: Developer code review hanya check "does it work" tidak check "does it handle memory efficiently". Vibe coding context length limitation mean AI tidak lihat full codebase dan potential circular reference.
Lesson: Performance test harus part dari CI. Memory profiling dengan tool seperti Clinic.js atau Node.js --inspect. Load test sebelum production.
Common Pattern di 3 Incident
- Prompt tidak specific enough — tidak mention constraint (transaction, multi-tenant, memory efficiency)
- Code review terlalu surface-level — check "compile? test pass?" bukan check "is this production-ready?"
- Testing tidak comprehensive — pass unit test, fail under real load atau complex scenario
- False confidence — "AI generated jadi harus fine" vs "AI generated jadi harus double-check"
How to Avoid This
Checklist sebelum deploy AI-generated code ke production:
- Prompt spesifik mention SEMUA constraint (perf, security, multi-tenancy, etc)
- Code review manual by person yang understand domain
- Test coverage > 80%
- Load test / stress test pass
- Security review (especially auth, data access, input validation)
- Performance profiling (memory, CPU, throughput)
- Rollback plan ready
- Monitoring alert set up
Kalau ada yang skip dari list ini, jangan deploy. Tidak worth it.