Code Room
Vibe codingMediumvc-g181
Subject Ai code reviewLevel Mid–Senior~18 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You asked an AI to write a TypeScript batch job (runs every minute on cron) that picks up unsent notifications and dispatches them. It looks clean. Review it for safety under overlapping runs.

typescript
async function dispatchPending() {  const pending = await db.query(    `SELECT id, user_id, body FROM notifications WHERE sent = false LIMIT 100`  );  for (const n of pending) {    await sendPush(n.user_id, n.body);    await db.query(`UPDATE notifications SET sent = true WHERE id = $1`, [n.id]);  }}

The cron sometimes runs slowly. What's the failure mode and how do you fix it?

What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.