Skip to content

Deprecation of metadata$model_params in 0.9.0.9000 silently breaks brms #1151

@anirban-mu

Description

@anirban-mu

Describe the bug

cmdstanr 0.9.0.9000 deprecated metadata$model_params (now NULL). brms' read_csv_as_stanfit() depends on this field to compute parameter dimensions for the internal stanfit object. With model_params = NULL, brms silently drops population-level coefficients — verified to lose 1–3 parameters in models with 3–8 predictors. No warnings or errors are raised.

CmdStan and cmdstanr are working correctly — all draws are present in the CSV output and in cmdstanr's draws objects. The issue is that the deprecation removed a field that brms relies on, without a compatibility shim or deprecation warning to downstream packages.

Per the NEWS.md entry for 0.9.0.9000, the deprecated field is:

model_params element of fit$metadata() list (variables element)

The replacement fields metadata$stan_variables and metadata$stan_variable_sizes are present and correct, but brms does not yet use them for dimension computation.

To Reproduce

library(brms)

set.seed(42)
n <- 200
dat <- data.frame(
  y  = rnorm(n),
  x1 = rnorm(n), x2 = rnorm(n), x3 = rnorm(n)
)

fit <- brm(y ~ x1 + x2 + x3,
           data = dat, family = gaussian(),
           chains = 1, iter = 500,
           backend = "cmdstanr")
nrow(fixef(fit))
# Returns 3, expected 4 (Intercept is missing)

The mechanism: brms greps csfit$metadata$model_params to determine vector dimensions. When NULL, grepl(pattern, NULL) returns logical(0), dimensions are never assigned, and rename_pars() silently drops parameters.

Expected behavior

fixef(fit) should return 4 rows (Intercept + x1 + x2 + x3), matching the backend = "rstan" result. Either:

  1. model_params should remain populated alongside the new fields during the deprecation period, or
  2. brms should be notified of the breaking change so it can migrate to stan_variable_sizes

Operating system

macOS (Apple Silicon, Darwin 25.3.0)

CmdStanR version number

cmdstanr 0.9.0.9000 (dev, SHA a8adbb1), CmdStan 2.38.0

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions