Demo, all content is generated
Question

Big refactor touched 40 files and appointment reminders stopped sending, how do I find which change did it

Solved · 2153 views · asked by dental_dave · edited

My practice's booking app. Last week I let Claude Code do a "cleanup refactor" over 3 days, maybe 25 commits, 40 files. Everything looked fine. Now patients stopped getting the SMS reminder the day before. No errors in the logs, the cron runs, it just finds 0 appointments to remind.

I can't read through 40 files of diff. How do developers find this kind of thing?

What I’ve tried

Asked Claude to find the bug (it found three 'possible causes', fixed them, still 0 reminders). Checked the cron logs, the job runs at 18:00 as before.

Comment
Do you have the commit from before the refactor? That's all you need for bisect. diego_mx · edited
Yes, I tagged it 'before-cleanup' because I was nervous. Good instinct I guess. dental_dave · edited

3 answers

Marked as helpful by the asker
kofi_mensah · edited

git bisect. It does a binary search through the 25 commits for you: about 5 checks instead of 25.

First you need a quick way to check "does it work", e.g. a script that runs the reminder query for tomorrow and prints the count:

git bisect start
git bisect bad                 # current version: 0 reminders
git bisect good <sha-before-refactor>
# git checks out a commit in the middle. Run your check:
npx tsx scripts/count-reminders.ts
git bisect good   # or: git bisect bad
# repeat ~5 times, then git prints "<sha> is the first bad commit"
git bisect reset

If your check exits non-zero on failure, git bisect run npx tsx scripts/count-reminders.ts does all of it automatically.

Then you read ONE commit instead of 25.

Comment
Classic. Glad bisect pointed you straight at it. kofi_mensah · edited
4 steps. First bad commit changed the date filter from >= tomorrow 00:00 to a toISOString() call, which is UTC. We're UTC+2, so the window was off and missed everything before 02:00. Wait, that doesn't explain all of them... dental_dave · edited
...it also swapped the gte/lt around. So it was two bugs in one commit. Fixed both, 14 reminders for tomorrow. dental_dave · edited
Saving this for the next time someone says 'I can't debug AI code'. sarah_k_dev · edited
katja_s · edited

After the fix, write the check you made for bisect as a real test and keep it. "A booking for tomorrow at 09:00 Amsterdam time appears in the reminder list" is exactly the kind of test that would have blocked this refactor.

Then for the next refactor: tests first, refactor after, run tests after every commit. That's what makes refactors boring, and boring is the goal.

Comment
Added it plus one for a booking at 00:30. Both would have failed on the bad commit. dental_dave · edited
chidi_eze · edited

For the date part: do the 'tomorrow' calculation in the clinic's timezone explicitly (date-fns-tz or Temporal), then convert to UTC for the query. toISOString() anywhere near a date range is a red flag in review.

Comment