Skip to content

Saving metric with large models produces truncated JSON files #1349

Description

@bgoodri

Describe the bug

When save_metric = TRUE in the $sampling method, the resulting JSON file can lack a closing ], a closing }, and worst of all, lacks some of the trailing values.

To Reproduce

You may need a model with about 29,000 parameters.

parameters {
  vector[29000] theta;
}
model {
  theta ~ std_normal();
}

and then sample from it with save_metric = TRUE

Expected behavior

A JSON file with 29,000 elements in the inv_metric field with a closing ] and }.

Operating system

Ubuntu 26.x

CmdStanR version number

0.9.0

Additional context

I can't tell you but @jgabry knows. According to Claude: "All six [JSON files] are ~336 KB but hold only ~28,700 values, and the counts differ per chain while the byte counts agree to within 62 bytes. That's a stdio buffer boundary: CmdStan has flushed whole buffers and the tail is still unflushed. Different chains have different digit widths, so the same byte count holds a different number of values."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions