Weird "off-by-two" error when using variational bayes

I get a very weird “off by two” error whenever using Variational Bayes and extracting items from the generated quantities block. Here is a minimal reprex: here is the Stan code:

data {
  // key numbers
  int<lower = 1> n; // number of periods
  int<lower = 1> p; // number of dependent variables
   
  // input data
  vector[p] y[n]; // dependent variables
}
parameters{
  real throwaway;
}
model {
  for(t in 1:n) y[t] ~ normal(throwaway, 10);
}
generated quantities {
  vector[p] y_prime[n];
  y_prime = y; 
}
// give stan a blank line

library(rstan)
library(tidyverse)
library(magrittr)

n = 100
p = 1
y = matrix(rnorm(n), nrow = n, ncol = p)

test_data <- list(n = n, p = p, y = y)

test_model <- stan_model("stan-models/matrix-issues-diag.stan")

test_samples <- vb(
  test_model,
  test_data
)
  

test_y_prime <- rstan::extract(test_samples, "y_prime") %>% magrittr::use_series("y_prime")
> mean(abs(colMeans(test_y_prime) - y))
[1] 1.147393
> mean(abs(colMeans(test_y_prime)[-1:-2] - y[-99:-100]))
[1] 1.15345e-06

This doesn’t seem to happen with sampling

Here is my Stan version:

> rstan::stan_version()
[1] "2.19.1"

Update: this is only happening on an EC2 instance with Ubuntu Linux — not on my Mac. Seems to be a memory error.