Caching brms models from docker container

I’m facing a problem when containerizing a long-running model of mine.
I use the brms file feature to save on model execution between usages of my model.
But when I run my model from a docker image (via shiny and Rmd files), and mount the cache directory via a bind mount, it seems like brms always regenerates the model.

  brm(data = d,
      family = zero_inflated_negbinomial,
      file = ".cache/my-cached-model-file",
      formula = formula,
      prior = priors,
      warmup = 1000,
      iter  = ITERATIONS,
      chains = CHAINS,
      cores = CORES,
      backend="cmdstanr",
      file_refit = "on_change",
      threads = threading(THREADS),
      save_pars = SAVE_PARS,
      adapt_delta = ADAPT_DELTA)

Then I build my docker image, and run it via a bind mount:

docker run --cpus=8 -p 3435:3435 --mount type=bind,source=${PWD}/.cache,target=/home/app/.cache my-docker-image

It seems like the cache is working as long as the same docker container is up and running.
And I can see that the model is cached in my cache directory, outside of the container ($PWD/.cache).
But if I restart the container (not rebuild, just kill and restart), it seems like brms ‘forgets’ about the cached model, and starts regenerating it.

Most likely, this is not a brms issue per se, but related to how docker bind mounts work.
But I have no clue how brms calculates if a model can be reused, so have no clue where to start looking in the docker documentation.

  • Operating System: Ubuntu 22.04 (host). FROM rocker/r-ver:4.3.1 (docker image)
  • brms Version: 2.20.4

Following up on my own thread, having read some more details on the file_refit parameter:

brms will refit the model if model, data or algorithm as passed to Stan differ from what is stored in the file.
This also covers changes in priors, sample_prior, stanvars, covariance structure, etc.
If you believe there was a false positive, you can use brmsfit_needs_refit to see why refit is deemed necessary.

I will get back to this question once I have sorted our more related to this function.

Thanks and have a nice 2024, all brms and Stan heroes!
/A