@kmitov, we hit this recently and it is basically what is described here: Autoloading and Reloading Constants (Zeitwerk Mode) — Ruby on Rails Guides
In our case we were storing an AR model in threadsafe_storage that cause the issue. The solution we used was to do a new lookup for the object when in development environment (as test/prod don’t do code reloading it’s not needed there).
A simple example, instead of:
def common_object
$thing # global object, purely for demonstration purposes
end
We use:
def common_object
thing = $thing
thing = Thing.find(thing.id) if Rails.env.development? # get a new instance if in a code-reloading environment
thing
end