Why does the container occasionally redownload all parts of its packages?

I’ve had this issue a number of times, for example Awakening causes request timeouts due to NPM reinstall.

I just experienced a similar issue, but worse. The SQLite compilation appeared to get the VM throttled for using too much memory. I don’t think I’ve run into that one before, but here was the result after the VM got un-throttled:

image%20(1)

Not good when it’s running a simple Slack bot. Can something prevent this issue?