What is a layer shift? How it occurs? and why?
A layer shift occurs when the stepper motor losses steps for some reason. Usually is mechanical reason.
Practically due to a "hard to pass over" obstacle, mostly created by some boghery, that is something similar to oozing but different from oozing.
Ups, too technical here. Oozing is than when you are not actually printing, sort of in "stand by", and the nozzle leaks from the plastic stored in the melting cavity, accumulated there from printing, in theory the sudden retraction of the filament at the end of a procedure in printing should create enough vacuum to also pull up the ooze and leave the nozzle clear.
But practice does not care much about theory.
Boghery is almost the same, just that the molten quantity is stuck to the outside of the nozzle for some reason (some people made up a nozzle cleaning system with brushes and changes in the G code to brush the nozzle after each layer) So if such bogs drop on your print, they weld themselves to the part, and become an obstacle, usually small, that the nozzle kind of drags itself over and within a few layers you won't even know is there unless is on some outer wall and you will have to cut it off in post processing.
But sometimes it hooks so hard the nozzle that he belt actually stops for a second while the motor still turns, hence you skipped a few steps, your nozzle is no longer where the computer think it is (obviously with a ball bearing threaded rod system this is unlikely to happen, that one is a tank)
And you will notice the print start inside one edge a few millimeters and goes outside the opposite edge a few millimeters.
On critical sized parts, that is the end, kill print and re do it again.
On prints that are not that critical, well, enjoy it as it is (a vase for instance).
But if you happen to be there and see it happen, a simple solution is to pause the print, not kill it, just pause it, appreciate from the edge the distance that the layer shifted, and manually rotate the motor to put it back in line (if your stepper has no encoder the computer will not know about it)
Clearly this is not the best of the best as solution, rarely you can fit the nozzle in the exact step it should be, mostly you go wrong a few microns. But you at least get to finish the print all right...ish.
As I said the solution to that is an anti boghery cleaning device. I saw people adding a static brush (metal) to one end of the X, and adding each layer end a G code to pass the nozzle over the brush. Ain't working well in the sense that if at one passage the nozzle leaves the bogs there, at a future passage might simply collect them back.
So I consider a solution where a small motor has attached to it a "V cup like" brush that rotates not that fast, maybe 100 RPM can do, and is tilted so that the brush contact area keeps the brush wires vertical and that means at the opposite diameter they are towards 45 degrees tilt. Hence when it picks the bogs from the nozzle due to the rotation and spring effect of the wires elasticity might throw away the bogs a few centimeters out the printing area, might do the job.