BoundaryML/baml · error

failed to clean segmented profiler data at {}

Error message

failed to clean segmented profiler data at {}

What it means

This is the contextual wrapper `baml clean` applies to any other CleanProfilesError from the profiler backend when cleaning segmented profiler data. The underlying cause (I/O error, permission problem, partial deletion failure) is attached to the context 'failed to clean segmented profiler data at <path>'.

Source

Thrown at baml_language/crates/baml_cli/src/clean_command.rs:50

                );
                Ok(crate::ExitCode::Success)
            }
            Err(bex_events::prof::backend::CleanProfilesError::InUse) => {
                bail!("profiling store is in use: {}", profiles_root.display())
            }
            // Cleanup refuses any root not shaped `.../.baml/profiles-v1`,
            // so it cannot delete an arbitrary BAML_PROFILE_DIR. Say so
            // instead of surfacing the bare `InvalidRoot`.
            Err(bex_events::prof::backend::CleanProfilesError::InvalidRoot)
                if std::env::var_os("BAML_PROFILE_DIR").is_some() =>
            {
                bail!(
                    "BAML_PROFILE_DIR points at {}, which is not a `.baml/profiles-v1` store; \
                     remove it manually",
                    profiles_root.display()
                )
            }
            Err(error) => Err(anyhow::Error::new(error).context(format!(
                "failed to clean segmented profiler data at {}",
                profiles_root.display()
            ))),
        }
    }
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the chained `Caused by:` section of the error for the underlying cause.
  2. Fix permissions on the profiles directory (chown/chmod) or run with sufficient privileges.
  3. Delete the store manually: rm -rf .baml/profiles-v1, then re-run the command.

Example fix

# before
baml clean  # permission denied on .baml/profiles-v1
# after
sudo rm -rf .baml/profiles-v1  # or fix ownership first
baml clean
Defensive patterns

Strategy: try-catch

Validate before calling

# pre-check write access to the profiles store
[ -w .baml/profiles-v1 ] || echo "no write permission on .baml/profiles-v1"

Try / catch

try {
  run('baml clean');
} catch (e) {
  if (String(e).includes('failed to clean segmented profiler data')) {
    // inspect the 'Caused by' chain; likely permissions or read-only fs
    fixPermissions('.baml/profiles-v1');
    run('baml clean');
  }
}

Prevention

When it happens

Trigger: `baml clean` invoked on the profiles root where the backend returns an error other than InUse or InvalidRoot — e.g. filesystem permission errors, read-only mounts, or I/O failures while deleting files under `.baml/profiles-v1`.

Common situations: Cleaning profiles on a read-only CI workspace; directories owned by another user/container; sandboxed environments blocking deletion of profile artifacts.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/0588854f50bec6de. Report an issue: GitHub.