The bug
Most mobs seem to stop walking (do not wander around / pathfind randomly) when there is only a spectator player nearby. The mobs might start moving, but then eventually stop. They still rotate and can bob up and down, but eventually they never actually leave its position.
Though this is likely intended (MC-46843, MC-48868), it leads to potential gameplay issues as described in MC-202512 and MC-212687. It also behaves inconsistently, because if it is intended behavior, it should apply to all mobs (MC-136206).
Steps to reproduce
This can be reproduced by switching the gamemode from creative to spectator, or by simply remaining in spectator mode and summoning the mobs listed below.
Notes
Logging out and relogging seems to (temporarily) fix the issue for some mobs.
When mobs interact with one another (i.e. cats and rabbits, for example) they might actually move around until the interaction is completed (that is, for example, the cat kills the rabbit). Then the mob stops moving again. Other examples include villagers fleeing from illagers and striders moving around when it rains.
Fixing this issue (if it is not intended) improperly might cause severe performance issues.
Affected mobs
This affects the following mobs: blazes, cats, chickens, cows, creepers, dolphins (MC-202512), donkeys, drowned, elder guardians, endermen (only teleport, don't walk), endermites, evokers, fish (cod, salmon, pufferfish, tropical fish), guardians, horses (including skeleton and zombie horses), husks, illusioners, iron golems, llamas and trader llamas, mooshrooms, mules, ocelots, pandas (they only roll, but don't walk), parrots, pigs, pillagers, polar bears, rabbits, ravagers, sheep, silverfish, spiders and cave spiders, skeletons, snow golems, squids and glow squids (MC-212687), strays, striders, vindicators, wandering traders, witches, wither skeletons, wolves, zombie villagers, zombies and zombified piglins.
This does not affect: axolotls, bats, bees, ender dragons, foxes, ghasts, goats, hoglins, magma cubes, phantoms, piglins, piglin brutes, slimes, turtles, vexes, villagers, withers and zoglins. Shulkers and giants are not affected because they already don't move in creative.
Other mobs, if any, were not tested.
Analysis
Analysis by @unknown provided in this comment.
Related issues
Attachments
Comments


Might duplicate MC-225953.

Mobs have an integer field called noActionTime
which is increased every tick so long as the mob is alive and has its AI enabled. When a mob is within 32 blocks of the closest non-spectator player, this timer is set to zero. This field is also used to determine when a mob can randomly despawn. When this timer is greater than 100 ticks (10 seconds), most mobs are programmed to not wander around. This seems to be intentional given the name of the field. My guess is this was implemented to not use up the game's resources for mobs trying to pathfind that are far from any players. This value is not saved to NBT which means noActionTime
is set to the default value of zero when the world is reloaded.

Thank you for the analysis, that is very intriguing. I wonder why that does not seem to affect some mobs.

Thank you for your report!
We're tracking this issue in MC-47533, so this ticket is being resolved and linked as a duplicate.
That ticket has already been resolved as working as intended, which means this is not considered a bug and won't be fixed. Please do not leave a comment on the linked ticket.
If you haven't already, you might like to make use of the search feature to see if the issue has already been mentioned.
Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki