Basically, if the id of a defined file/folder is a prefix of a different folder id, it ends up appearing in that folder no matter how the rest of the tree is defined. I assume this isn’t intended, but someone correct me if I’m wrong on that, or if there’s a reason why this has to be the case.
Turns out I didn’t solve it. I think the bug is actually a bit more advanced - a given file will appear (in the grid) to be inside any folder who’s id is contained inside the file’s id. There’s no way this can be intentional, must be a poorly tested “is one thing contained in this other thing”.