Hi Charles,
Thanks for posting this clear and minimal reproducible example.
What I see going on is perhaps a minor misunderstanding which happened to reveal a minor bug.
The issue is that no variables are being monitored (stored by the MCMC to return in the samples). You've set x to be data, which means it won't be sampled. By default, monitored variables are top-level parameters, i.e. those with no stochastic parameters. The only node sampled in either code_v1 or code_v2 will be y, and that is not monitored by default, so in these examples there are no monitored variables. I suspect you want x to be sampled by MCMC and hence should move it out of data and give it a value in inits. It would then be monitored by default. If you want it held fixed as data and only want 'y' monitored, please try adding "monitors = 'y' " so that something is monitored.
Meanwhile, I'll file a bug report in our GitHub repository that extracting samples from the compiled MCMC object fails if there are no columns to extract. At this point it is surprising that this problem hasn't been discovered (or reported) previously.
HTH,
Perry