The role that didn't exist yet
A comparison said two lists of permissions were the same. They weren't. One of them mentioned a role that was about to be created, and a thing with no id yet is very easy to leave out.
This is a small bug with a shape I keep meeting.
My bot can change a Discord server it built earlier. You flip a switch, and it works out what is different: which channels to add, which to edit, which to leave alone. Leaving things alone matters. Nobody wants every channel touched because one option changed.
To decide if a channel needs an edit, it compares two lists of permission lines: the ones the channel should have had before, and the ones it should have now.
The switch
One switch turns on a bot check. With it on, a new Member role is created, and newcomers only get in after they pass. Several channels mention that role in their permissions: staff channels say “Member: can’t see this”, the rules channel says “Member: can’t post”.
So turning the bot check on later should edit those channels.
It didn’t. The comparison said: same before, same now, nothing to do.
Why
A permission line needs the role’s id. Discord gives you the id when the role is created.
When the comparison ran, the Member role wasn’t created yet. It was going to be, a few steps later, in the same change. The code that turns “Member” into a real id found none and did the reasonable thing with a line it couldn’t write: it dropped it.
So both lists were built without the Member line. Both were missing the same thing. They matched.
The edit that should have added the line was never planned, because the only difference between “before” and “now” was the one thing neither list could express.
The fix
For the comparison only, a role that is about to be created gets a stand-in id. Now the “now” list has a line the “before” list doesn’t, the lists differ, and the channel is edited. The edit itself runs after the role exists, so it uses the real id.
The opposite case needed the opposite care. If a role is about to be removed, its lines shouldn’t count as a difference, because Discord removes them along with the role. Otherwise turning the bot check off would edit every channel for nothing.
The shape
The bug wasn’t in the comparison. Comparing was correct. The bug was that both sides were built by the same code with the same blind spot, so they agreed.
I see this in tests too. A test that builds its expected value with the function it’s testing will pass forever.
What caught it was a different kind of check: build the server one way, build it another way, and compare the two real results. That check doesn’t share the blind spot, because it never asks the planning code what it thinks.