Skip to content

[codex] introduce BaseDiskID typed base-disk ID flow#346

Merged
DorianZheng merged 1 commit intomainfrom
codex/base-disk-id-flow
Mar 4, 2026
Merged

[codex] introduce BaseDiskID typed base-disk ID flow#346
DorianZheng merged 1 commit intomainfrom
codex/base-disk-id-flow

Conversation

@DorianZheng
Copy link
Copy Markdown
Member

@DorianZheng DorianZheng commented Mar 4, 2026

Summary

This change introduces a new strongly typed base disk ID model and propagates it through the base disk domain and storage flow. The implementation adds BaseDiskID / BaseDiskIDMint, switches base disk ID generation to the same Base62 random algorithm used by BoxIDMint, and replaces raw String IDs in the base disk lifecycle with typed IDs.

User Impact

Users benefit from stronger ID correctness guarantees in clone/rootfs base disk handling, especially in code paths that read, track, and garbage-collect base disks. This reduces the risk of accidentally passing malformed or wrong ID values between layers while keeping serialized/DB representations as text.

Problem

Base disk IDs were previously represented as plain strings and generated using nanoid!(8). That allowed broad string usage across APIs and made it easy to accidentally mix unrelated values or pass invalid IDs without compile-time checks.

Root Cause

The base disk path had no dedicated ID type, unlike box IDs (BoxID). Without a semantic newtype, domain boundaries (disk manager, DB store, GC/ref tracking, rootfs install, migration) relied on unconstrained &str/String IDs.

Fix

The fix applies a typed-ID refactor across the base disk flow:

  • Added BaseDiskID and BaseDiskIDMint in runtime/id.rs with strict Base62 validation (8 chars), plus Display, Debug, AsRef<str>, Borrow<str>, and ToSql.
  • Reused a shared internal Base62 mint helper for both BoxIDMint and BaseDiskIDMint to avoid duplicate generation logic.
  • Re-exported the new types from lib.rs.
  • Changed BaseDisk.id from String to BaseDiskID.
  • Updated minting sites to use BaseDiskIDMint::mint():
    • BaseDiskManager::create_base_disk
    • GuestRootfsManager::install
    • v6->v7 rootfs-base migration path
  • Updated base disk store APIs to typed IDs:
    • BaseDiskInfo::id() -> &BaseDiskID
    • find_by_id(&BaseDiskID)
    • delete(&BaseDiskID)
    • add_ref(&BaseDiskID, box_id: &str)
    • has_dependents(&BaseDiskID)
    • dependent_boxes(&BaseDiskID)
    • remove_all_refs_for_box(...) -> Vec<BaseDiskID>
  • Updated call sites in clone, runtime GC/removal, rootfs cache, and migration-related tests.
  • Replaced legacy invalid test literals (for strict Base62 parsing) with valid 8-char Base62 IDs.

Validation

I validated formatting, linting, and tests with the following commands:

  • cargo fmt
  • cargo fmt --check
  • cargo clippy -p boxlite --tests -- -D warnings (passed)
  • cargo test -p boxlite
    • Unit tests passed (565 passed; 0 failed; 5 ignored).
    • Integration test target clone_export_import failed in this environment due unavailable runtime engine registration (Engine Libkrun is not registered. Available engines: []), which is an environment/runtime availability issue rather than a compile/type error from this refactor.

@DorianZheng DorianZheng changed the title introduce BaseDiskID typed base-disk ID flow [codex] introduce BaseDiskID typed base-disk ID flow Mar 4, 2026
@DorianZheng DorianZheng marked this pull request as ready for review March 4, 2026 15:31
@DorianZheng DorianZheng merged commit 2a3b304 into main Mar 4, 2026
18 checks passed
@DorianZheng DorianZheng deleted the codex/base-disk-id-flow branch March 4, 2026 15:32
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.

1 participant