Skip to content

Fix handling of wsl output paths #1214

Open
jgabry wants to merge 4 commits into
masterfrom
bugfix/wsl-output-paths-1110
Open

Fix handling of wsl output paths #1214
jgabry wants to merge 4 commits into
masterfrom
bugfix/wsl-output-paths-1110

Conversation

@jgabry

@jgabry jgabry commented Jul 22, 2026

Copy link
Copy Markdown
Member

Submission Checklist

  • Run unit tests
  • Declare copyright holder and agree to license (see below)

Summary

Fixes #1110.

(Note: I had Claude code assist with writing the tests for this because I don't have a WSL locally right now. )

With this PR we now keep CmdStan output paths in the native Windows/R namespace when using WSL, and we only translate them to WSL paths when constructing CmdStan commands (compose_all_args already handles this). This ensures output files (and diagnostic, profile, config, and metric files) work with functions like file.exists(), save_*_files(), etc.

Copyright and Licensing

Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Jonah Gabry

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:

@jgabry
jgabry requested a review from andrjohns July 22, 2026 17:58
Comment thread R/args.R Outdated
self$model_variables <- model_variables
self$save_cmdstan_config <- save_cmdstan_config
if (os_is_wsl()) {
if (os_is_wsl() && is.null(output_dir)) {

@jgabry jgabry Jul 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to convert output_dir immediately with wsl_safe_path(), so e.g. C:/output would become /mnt/c/output before the output filenames were created. Now we do the special WSL handling when output_dir is omitted.

compose_all_args() already converts output, diagnostic, and profile filenames with wsl_safe_path(), so CmdStan still gets the right paths.

Comment thread R/fit.R
Comment on lines -38 to -40
# Need to update the output directory path to one that can be accessed
# from Windows, for the post-processing of results
self$runset$args$output_dir <- wsl_safe_path(self$runset$args$output_dir, revert = TRUE)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary now. Also, previously this would only run after the CmdStanRun object had already made all the output filenames, so this would only fix args$output_dir, but not the $output_files() and other similar methods.

Comment thread R/run.R
},
config_files = function(include_failed = FALSE) {
files <- private$config_files_
files_win_path <- sapply(private$config_files_, wsl_safe_path, revert = TRUE)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

files_win_path is never actually used anywhere after it's created. Unnecessary now, anyway.

withr::local_tempdir(pattern = pattern, .local_envir = .local_envir)
}

test_that("WSL output paths stay host-native until command composition", {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got Claude to help me with these tests! I reviewed them and I think I understand what they're doing.

@jgabry

jgabry commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

@andrjohns do you mind taking a look at this? very few actual code changes, but it touches WSL which you know much better than I do. Maybe there's an unintended consequence I'm overlooking.

@jgabry jgabry changed the title Bugfix/wsl output paths 1110 Fix handling of wsl output paths Jul 22, 2026
@codecov-commenter

codecov-commenter commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.09%. Comparing base (cd4bb05) to head (5cfb308).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1214      +/-   ##
==========================================
+ Coverage   91.90%   92.09%   +0.19%     
==========================================
  Files          15       15              
  Lines        6260     6249      -11     
==========================================
+ Hits         5753     5755       +2     
+ Misses        507      494      -13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmdstanr::sample() saves incorrect path to csv files, Windows

2 participants