One Simple Trick Let Copilot Solve My Impossible Bug!

One Simple Trick Let Copilot Solve My Impossible Bug!

• 271 views
vlogvloggervloggingmercedesmercedes AMGMercedes AMG GTAMG GTbig techsoftware engineeringsoftware engineercar vlogvlogssoftware developmentsoftware engineersmicrosoftprogrammingtips for developerscareer in techfaangwork vlogdevleaderdev leadernick cosentinoengineering managerleadershipmsftsoftware developercode commutecodecommutecommutegithub copilotcopilotgitgit diffhow to use copilotgithub copilot agentcursor ai

I was stuck on this bug for almost two days straight with no end in sight. I couldn't figure out what the HECK I was doing wrong, but I know my most recent change must have broken production.

But Copilot was able to solve it all for me... but only after I gave it one critical piece of information!

📄 Auto-Generated Transcript

Transcript is auto-generated and may contain errors.

Hey folks, I'm just leaving CrossFit. The sun is shining. It might be too bright. Might be too bright. Um, we got the week off work, which is sweet. So, we're going to be talking about some AI tool usage in this video. Um, sorry, I'm just left cross, so I'm like completely out of breath. But yeah, week off work. If you've been watching the other videos and stuff, you know that I had a really big project that was wrapping up and uh I just wanted to get to the end of the month and then take the first like full week off of May. Um so that's what I'm doing. Today's the first day of that. Started bright and early. I'm going to go home and sleep. I'm going to take all of our We got three dogs and two cats. I'm going to see who wants a nap with me.

Probably none of them. They're all like, "Screw you, man. We're we're content without you." Um, but I got to go back and sleep a little bit, but I got a full week ahead of me of like of things that I want to be productive doing. And that might sound a little bit like ass backwards that I just left a period. Well, who knows? Like obviously I'm still going to be feeling effects of burnout, but the stuff that I get to work on that I'm interested in outside of work, that's like some other type of work arguably, but like it's what I want to do. So I want to get more YouTube content out on my main channel. I want to spend more time building brand ghost. I, you know, there's I want to make more code commute videos. Like all this stuff I like doing. So, it's uh not actually more work.

It's more time spent doing things, of course, but um I enjoy it. So, going to try to get a lot done this week. I have a lot of catching up to do, but I I'm I'll I'll pay attention to it, right? If I'm like halfway through the week and I'm like, "Hey, you're not feeling like refreshed, you're just feeling more stressed out," then it is what it is. And I'll try to rest the second half. But I'm like excited to go do this stuff. So, I wanted to talk about AI tooling a little bit because I had a a scenario I shared on LinkedIn and uh I feel like it's a pretty common one that people run into and I felt like it was a pretty good use for AI. I'm going to talk through that. And a friendly reminder, if you're new to the channel, leave comments below if you want your software engineering and career questions answered.

Try my best. Otherwise, you can send messages into Dev Leader. That's my main YouTube channel with uh more like polished tutorials and C general programming topics. Uh podcast as well as Monday nights at 7:00 p.m. Pacific. I do a live stream. It's also just the handle I use on all my social media. So, send me a message if you're interested in having something answered and you don't want it to be public. Okay. So the scenario I will start from the beginning because this is a common one. Okay. The uh scenario I had was I was building out some functionality and working on this feature and I happened to break production and the break and prod was not like a build break and it also was not 100% consistent which is a little spooky, right? So, I got something that doesn't seem consistent. Is it a race condition?

Is it something else? We don't know yet. But, um, it's very, very coincidental that things seem to stop working after I pushed changes up to production. Okay. So, for clarity, it wasn't a new feature that's not working. I pushed up a new feature and something else broke. So, in my head, I'm going, it seems far too coincidental. Now, the thing I didn't write about on LinkedIn was that after I reverted this and I started debugging it, um, it turns out the, uh, first symptom I noticed was actually because the public API that I was hitting, like that I don't own, they actually had an outage. So, that part was literally an extreme coincidence. So, I pushed up a change, things stopped working, and I was like, "Uh, what's going on here?" But their API had an outage. I checked at downdetector.com, and sure enough, it was listed there.

So, I said, you know what? Screw it. We're putting it back, right? Like, that's a pretty conclusive thing when you're like, it's not working and down detectors literally reporting an outage. So pushed my change back up and uh success was higher, but I still had an inter intermittent issue. But this one was a little different. And I said, "Okay, that's like not quite two for two, like one out of two, cuz the first one wasn't actually me." But I said, "It's time. I got to go through this code again and I got to find this issue." So what I was doing was uh I like using git extensions for the visual. Like I like clicking through the files. I like seeing the visual diff. I don't like using a command line for that kind of stuff. I I don't know why. Like if you like using command lines that's totally cool, but like I feel like we're using asy art to try and do stuff that we have rich UIs for.

So like give me the rich UI. I don't know why people are so hellbent on like, oh, you got to stick to the terminal and oh, you're so much better. I'm like, okay, they're just you like living in ASI art land. That's cool. Um, so clicking through and I'm going, okay, like I touched these files, but the part that was broken seemed to be a file that I didn't touch. Now, the problem is that it's not like an obvious like it's not like one obvious spot in the code where I'm I'm kind of have to make an assumption about where the symptoms are, but it seems like it has to do with authentication. The problem is that I have some parameters that are being mixed up and I'm going I didn't I'm looking through the code looking through the diff and I'm like look it must be my change because it was working before my change.

That's the difference. But why do these parameters seem like they're swapped? So I'm going through and as I'm navigating every time I get down to a spot I'm like but I didn't change this. Right? So if I want to go revert the change, I'm like this file wasn't touched. So has this and then I'm starting to guess like has this problem just always been here, right? But this is the kind of thing that I think most people do when you have like a breaking change. Obviously I reverted it, but you're going through the delta and you're going like what part of this delta is responsible for this braking behavior, right? you have a list of changes. So, I'm doing this and I'm like, this is not making any sense. So, I'm like, you know what? I'm going to I'm going to try I'm going to try using co-pilot and chat GBT for this.

So, by the way, this has been like two days, not straight, but of my own personal time, two days like carved out to look at this, and I'm not getting anywhere, but I'm pretty confident it is my change. So, okay, time for co-pilot and um I'm thinking I think originally I was going to go to Chad GPT, but I'm like it's not really going to make sense because I want to make sure that it has the full context of my repository cuz I have full context and I can't figure it out. And I wrote the code with full context. So, I'm like, I'm going to go to Copilot in Visual Studio. I'm going to ask it. And sure enough, I'm asking co-pilot what's up. And it's like looking at the right spots or what I feel like are the right spots. So, I didn't tell it here's exactly all the files I looked at, but I described the problem.

I explained the changes that I had made, like I was adding this feature, blah blah blah, and here's the symptoms I'm observing. And so it started to go down the same path as me, which is interesting. Like I'm like, "Okay, like we're at least it seems like it's like logical if this thing's also arriving at that." But I'm like, "That's not helpful because I just did that." Like it's it's speculating, right? It can't um I'm not saying I shouldn't say it can't. it was unable to like pinpoint and say clearly it's this but um it's kind of speculating like I would check these areas like here are some things to look out for over here and over here and you know if the you know if this assumption is true this might be a reason you see X behavior so cool like again good to

know that it was able to kind of arrive at some types of conclusions like that or speculation but unfortunately for me I had already spent all that time doing the exact same thing. So, quick little lesson for me was, hey, um, if you can give it a little bit of direction, it might be able to help you kind of think about areas to troubleshoot. So, helpful, just not in my particular case. So, now I'm frustrated cuz I'm like, I don't I need to get this change landed, but I can't understand how I broke things. And then I was thinking, you know what? I had some extra context that Co-Pilot didn't. And even though it had full access to my codebase, I don't think Copilot is able, and maybe it's able to and it just wasn't, but I don't think it's able to look through my git history.

So I said I have a visual of the git history but I said why don't I give it literally the git diff and see if it can go figure it out cuz I'm confident the change introduce the problem. So I don't know how to do it in git extensions but on the command line it says just get space diff then your two commit hashes and then you can basically output that to a file. So I created a diff like simple command like that I just told you bit off the top of my head and I get this file. So I have this diff and I said okay co-pilot same thing right here's the symptoms I'm observing and here's why it's a problem. I'm pretty sure it's related to my change. Here is the git diff between when it was working and when it's not. And basically within seconds it pointed out something that I hadn't realized before.

And that was the problem. So the problem had nothing to do with the areas that I was looking in. I still think logically those were the right places to look, but as I was saying, I didn't touch them. They're like logically the right places, but they were untouched. So correct, it's not going to be in those files, but those files, the behavior of those files was affected. And how was it affected? Well, I changed something in dependency injection. And I thought that what I had done was I have like some factory objects. They're responsible for making other objects. And I had registered the I thought registered the factory as a single instance. I don't need multiple factories. I just need one. There's no state. So give me one factory and then it will make me new instances. It turns out the way I did this registration meant that the instance of the object was going to be a singleton.

And that instance, the reason it worked sometimes is because the first call into it, if I was ever using that scenario, it would always work. Every other scenario would be broken. So basically co-pilot called out within seconds of me giving it the get diff. It was like your problem is this. And that's a really good lesson for me because the next time that I have a problem, what I'll probably do is I'm going to reverse the order that I did my troubleshooting in. if I have a weird change in functionality like broken behavior or something unless it's very obvious like oh no reference exception and I'm like yes I can see the object that's null it shouldn't be don't do that um if it's not immediately obvious I mean always what I shouldn't say always generally what I will do is revert unbreak the thing

but if it's not immediately obvious I'm going to get the git diff I'm going I feed it to co-pilot and say this is what I did and here's the new symptom I'm observing. So that was my little uh kind of encounter or cool little thing that I learned that I can trust uh co-pilot a little bit more with. I didn't try it in chat GPT. I don't know if co-pilot was relying on the extra context in the codebase. Maybe, but given that those lines were touched in the diff, I wonder if CO um Chad GPT could do it. Okay, so that was one thing. The other thing I wanted to talk about was cursor. Uh so I tried out cursor uh for the first time actually over the weekend. I had it in I had it installed before. I think I gave it a brief try and like it totally sucked when I used it for whatever.

I just like tried one thing and was like, "Oh man, I'm frustrated." And this is because I tried uh Visual Studio Code and agent mode and was very disappointed. Never was like, "Oh, cursor, cursor, you have to use cursor." So, I tried cursor, gave it the same thing, and it was equally a So, I was like, "Okay, like maybe it isn't just me. I don't know." But um I'd given up on it and then over the weekend I decided to go back and there was a few like cleanup type things that I wanted to do. And for a little bit of context, um some of the stuff is like very trivial, but because I have it done across many plugins, the um sometimes the cost of like doing some cleanup work is greater because when people hear about like the dry principle, like don't repeat yourself.

A lot of people think like, oh, you're not allowed to have code that looks like it's copied and pasted. like you must always pull same looking code into, you know, the same spot so that you don't repeat yourself, but that's not really what it is, right? Um, these things are completely different plugins. They're decoupled from each other. It just so happens that they have some similar behaviors in certain spots, but I've been adjusting those behaviors over time in terms of best practices. In this case, it was logging. So historically my logging I wanted to make sure that I could include um some common diagnostic information. So a lot of my log messages were enhanced to have such information in them. That meant when I'm going through my logs and debugging stuff, I'm like, okay, I know which user this is. I know um sort of the scenario I'm looking at and it's it's carried through the logs.

So that worked really well for debugging. But there's um but there's another thing that you can and I think uh I should say that you should be using uh if you're using like C for logging. There's an ey logger interface but it has something called begin scope on it. And full transparency I hadn't even heard of begin scope until recently. I've been programming in C for like 13 plus years now and I didn't know about logger begin scope. So there we go, right? Like there's always something to learn and um so the idea with begin scope is that uh maybe it is kind of it seems obvious I don't know based on the naming but you're creating a scope and in that scope you can provide some extra information.

So all of those log messages that I've been enhancing with some of these details for consistency, what you can do is you can just add a begin scope and you can say for everything within this scope that's going to be logging, it will have the user ID, it will have the scenario information. So that will just automatically get carried through in the logging until you end the scope. So for me that's a huge value ad because then I don't have to go pollute all of these log messages in the code and try to slap in to this message like you know five data points I wanted to say like operation failed and then I have to be like operation failed for user with this ID in scenario X with this piece like I can just say operation failed and the structured logging thanks to begin scope scope will add in all of these other parameters.

So to be clear, depending on your formatting for your output logs, you might not see all of those things in like a single log line, but if you're looking at the structured log output, it's there. So it depends on your log viewer. So I said like that's going to be tedious. So, I don't want to go across everything like, yeah, it would be nice to do, but like, pardon my language, I got other to do that's more important. Like, I I I would rather be building out the new functionality that's going to help um versus just like enhance some blogging. But then I'm like, this is the perfect thing that I should outsource to AI. I don't want to do it. It's repetitive. It's going to be kind of weird to like write a script for programmatically because things are slightly different shape, but I just described it to to you folks as humans and I can do that a little bit more succinctly to an LLM.

So, okay, cursor, it's your time to shine. I said, I need to do something with begin scope. Here's the information I want. And so, it did it. And I said, "Okay, I'm a little bit too afraid to try like a sweeping thing across like 20 plugins. Try for one." And the first one that it did, the how do I say this? The the positive changes that it did, I feel like we're good. It added the scope. It trimmed up the log messages so that it wouldn't be like these super heavy log messages. uh plus the scope the log messages became very light because the information was in the scope that's exactly what I wanted but it messed up one thing and by one thing I mean one style of thing but like three different flavors of it and it actually removed functionality that was really important.

So I have like for lack of better word like a dictionary of information and what I need to do is like in some cases that information needs to be parsed or sanitized in different ways and I have helper methods for that. So it just like deleted the code that was calling the helper methods decided we don't need that and just skip that entirely. So it would pull the information out of the dictionary, not sanitize it or parse it properly, and just go and use it. And I'm like, you you did all of this other stuff right for the logging. Why the hell did you go touch that? Like, and I was scrolling through the beginning of this change, feeling pretty good about it until I started to realize, wait a second, it's just deleting calls to these methods. So I'm like, okay, not good.

and then hey cursor like no you're changing stuff and for this particular change was super frustrating because even after I told it don't do that start again it repeated it um so I was about to give up on it and then uh I can't remember how I changed my prompt but essentially was like we're going to use the begin scope and I I told it like you're only allowed to like add. Um, no, not even add, sorry. The only other thing you're you're able to do is change the existing log methods, but preserve the log messages as much as possible except if the information is already included in the scope. And I said, change no other behavior. And it actually did it. So I said, okay, great. Now go do it across these 19 other plugins. And it did, which is really cool. Um, so that was actually in the end, was it a timesaver?

Probably not because I had to go back and forth so many times on the first one. But, um, going forward, I think going forward it will be a lot better because I can use it for some stuff like that. And I, in fact, did it for um, there's a job framework called Quartz. and I said all of my jobs that I kick off, there's some common information I want logged in the scope. Let's go build a common thing for that. And it did it and it didn't screw it up for the jobs. So, that was a pretty good win. So, overall trying out cursor um a little bit um it's not going to make me jump ship from Visual Studio. Visual Studio agent mode is coming. I'm pretty disappointed that uh they launched agent mode in VS Code and not Visual Studio. I I think I understand why because a larger audience on VS Code across many languages.

So, sure, but like why would you go put a crazy power tool like that into sort of this free product and then for the people that are paying users of your premium product not give them that? Um, like I said, I think I can understand why, but at the same time, I'm like, uh, feel I feel burned by that. And I work at Microsoft. Anyway, it's on the way. So, I will make sure to try that out because if I can stay in my my tool that I'm familiar with, I'll be more productive. But wanted to share. AI is helping. Cool stuff. Be cool to hear from you if you watch all the way to the end. If you have ways that you're using cursor, other AI tools in your development productivity, share it in the comments. See you next time. Take care.

Frequently Asked Questions

These Q&A summaries are AI-generated from the video transcript and may not reflect my exact wording. Watch the video for the full context.

How did you use Git diff with Copilot to solve an intermittent bug in production?
I generated a Git diff file between the working and broken commits and fed that diff to Copilot along with a description of the symptoms. Within seconds, Copilot pointed out that my problem was related to how I registered a factory object as a singleton in dependency injection, which caused intermittent failures. This approach helped me identify the root cause quickly when manual debugging was not productive.
What was your experience using Cursor AI tool for logging improvements in your C# projects?
I used Cursor to help refactor logging by adding 'begin scope' to include common diagnostic information automatically in logs. Initially, Cursor made some mistakes by removing important helper method calls, but after refining my prompt to restrict changes only to adding scopes and preserving log messages, it successfully applied the improvements across multiple plugins. Although it required some back and forth, I believe it will save time on similar repetitive tasks going forward.
Why do you prefer using Git Extensions over command line for code diffs and debugging?
I prefer Git Extensions because it provides a rich visual UI for clicking through files and seeing diffs, which I find more intuitive than using the command line. I feel that since we have rich UIs available, it makes sense to use them instead of sticking strictly to terminal commands. This visual approach helps me better understand the changes and troubleshoot issues effectively.