Reproducing a bug

I was integrating some AI featured into wyd.chat, an app I made that gives you Spotify wrapped type analytics for your iMessage. Most texted person, most popular group chat – that kinda stuff. You should go download it.

The ChatGPT integration would allow you to ask "What should I get my friend for their birthday", have GPT comb through your texts and (hopefully?) make some stellar recommendations.

While doing the integration, I ran into a very interesting bug and I thought it would be fun to outline my debugging process to illustrate how real bugs get solved.

The Setup

To set some context:

  • The app is built on Tauri (which I love) so everything is running in a Safari webview
  • I wanted to use the Vercel ai sdk ( npm i ai ) with it's (currently) experimental function support.

I wired everything up according to instruction, and..

... it didn't work lol.

The function handler I provided just would not be called.

This is where things got interesting. A younger me would have given up, thinking some weird combination of Tauri + the ai sdk is not compatible. Wiser Fardeem knows better. I know that it's javascript all the way down. It's literally only some network requests – stuff I feel very comfortable with.

Time to get coffee and get to the bottom of this.

  • There is a server component and a client component to this whole mess. Within the client side, I know that Safari can be janky at times so maybe the streaming stuff vercel is doing isn't supported
  • I tried first keeping the api same and making a small app that consumes the api on Safari. It works ✅
  • If Safari is not the issue, maybe Tauri is the issue. I make a completely new Tauri repository, integrating everything and it works! ✅ I am now more confused.
  • At this point, I know that neither Tauri or the sdk is the issue. The problem has to be within my project.
  • Except the code between the sample tauri app I made and my project is identical.
  • Sadly, this next step just comes with experience. I was using vite and wondered if the bundler had messed up somewhere.
  • I upgrade Vite and everything works perfectly!

This is obviously shortened for clarity and with a lot of hindsight and the process was pretty confusing when I was in it. But, the key principle is the same.

The lesson.

You don't want to debug by changing things and hoping things "fix" themselves. It's code all the way down. Try to figure out the distict areas where the problem might be and scope down until you get to a point where things work. Then, diff your checkpoint to your project. Systematic debugging is the only way to go.