astrid-runtime/astrid · error

legacy principal layout

Error message

legacy principal layout

What it means

The panic message "legacy principal layout" comes from calling .expect() on the Result returned by principal_home.ensure() in the test audit_retirement_validates_tree_and_removes_only_verified_source (crates/astrid-kernel/src/audit_retirement_tests.rs:12). AstridHome::principal_home() returns a handle for a per-principal directory; ensure() creates the full on-disk layout (including the audit directory) or fails with an io::Error. The library throws it when the per-principal directory tree cannot be created or verified under the home root. In this test the panic indicates the per-principal scaffolding step broke, which would invalidate everything the retirement test does afterwards.

Source

Thrown at crates/astrid-kernel/src/audit_retirement_tests.rs:12

use super::{preflight_legacy_audit_sources, require_audit_integrity, retire_legacy_audit_dir};
use astrid_audit::ChainVerificationResult;
use astrid_core::SessionId;
use astrid_core::dirs::AstridHome;

#[test]
fn audit_retirement_validates_tree_and_removes_only_verified_source() {
    let directory = tempfile::tempdir().expect("temporary home");
    let home = AstridHome::from_path(directory.path().join(".astrid"));
    home.ensure().expect("home layout");
    let principal_home = home.principal_home(&astrid_core::PrincipalId::default());
    principal_home.ensure().expect("legacy principal layout");
    std::fs::write(principal_home.audit_dir().join("entry"), b"audit").expect("audit fixture");

    retire_legacy_audit_dir(&home, &principal_home.audit_dir()).expect("retire audit source");
    assert!(!principal_home.audit_dir().exists());
    assert!(
        !home
            .migrations_dir()
            .join("audit-principal-home.retired")
            .exists()
    );
}

#[cfg(unix)]
#[test]
fn audit_retirement_rejects_redirects_before_removal() {
    let directory = tempfile::tempdir().expect("temporary home");
    let home = AstridHome::from_path(directory.path().join(".astrid"));
    home.ensure().expect("home layout");

View on GitHub (pinned to affd8760f4)

Solutions

  1. Re-run the test in a writable temp location to rule out an environmental (permissions/disk) cause.
  2. Check that the principal path does not collide with an existing non-directory file; delete the stale tempdir and retry.
  3. Inspect PrincipalHome::ensure() for recent changes to layout creation or validation that could reject the default-principal tree.
  4. Ensure AstridHome::ensure() succeeded first (home layout) since ensure() on the principal home may depend on the parent structure existing.

Example fix

// before
principal_home.ensure().expect("legacy principal layout");
// after
if let Err(e) = principal_home.ensure() {
    panic!("legacy principal layout: failed to ensure {}: {e}", principal_home.path().display());
}
Defensive patterns

Strategy: validation

Validate before calling

fn assert_ensureable(home: &PrincipalHome) -> Result<(), String> {
    let path = home.path();
    if path.exists() && !path.is_dir() {
        return Err(format!("{} exists and is not a directory", path.display()));
    }
    std::fs::create_dir_all(path).map_err(|e| format!("{}: {e}", path.display()))
}
// call assert_ensureable(&principal_home)?; before the real ensure()

Type guard

fn is_dir_writable(p: &std::path::Path) -> bool {
    p.is_dir() && std::fs::metadata(p).map(|m| !m.permissions().readonly()).unwrap_or(false)
}

Try / catch

match principal_home.ensure() {
    Ok(()) => {}
    Err(e) => panic!("legacy principal layout: {e} at {}", principal_home.path().display()),
}

Prevention

When it happens

Trigger: Calling principal_home(&PrincipalId::default()).ensure() when the parent .astrid home exists but the per-principal subdirectory cannot be created — e.g. create_dir_all fails due to permissions, a non-directory file already occupies the principal path, the path exceeds filesystem limits, or ensure() contains a layout validation that rejects the produced tree.

Common situations: Running the test suite on a filesystem where the tempdir root is not writable (read-only /tmp, restricted CI sandboxes, some container runtimes), a stale tempdir entry where a file named after the principal id already exists, or a regression in AstridHome/PrincipalHome path construction that builds an invalid path (e.g. empty id segment).

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09). Data as JSON: /api/errors/c69a7b104c5cb0d6. Report an issue: GitHub.