refactor(supervisor): retype VM identity from ItemHash to VmId#982
Conversation
foxpatch-aleph
left a comment
There was a problem hiding this comment.
Clean, mechanically sound refactor that replaces ItemHash with VmId in pool.py and models.py, completing the removal of aleph_message from the pool. The change is type-safe because both types are str-compatible at runtime (same hash/eq semantics), leaving dict key behavior unaffected. The only behavioral delta — deferred ItemHash format validation — is correctly acknowledged in the description as out of scope.
The pool keyed executions by aleph_message's ItemHash, the last aleph_message symbol in pool.py. Replace it with the message-free VmId (a NewType str) from supervisor.types, drop the import so the pool is fully message-free, and retype VmExecution.vm_hash to match so the pool's dict key type stays honest. ItemHash is a str subclass and VmId a str NewType, so stored keys and lookups stay compatible; the spec path now stores spec.vm_id directly instead of re-wrapping it. models.py keeps its message-content imports (ExecutableContent and friends), which drive the message path and are out of scope here.
b328af3 to
8c73728
Compare
foxpatch-aleph
left a comment
There was a problem hiding this comment.
This PR cleanly retypes VM identity from ItemHash to VmId in pool.py and models.py, removing the last aleph_message symbol from the pool module. The change is mechanically safe (ItemHash is a str subclass, VmId is a str NewType — dict key semantics are identical) and correctly propagates the type through all pool method signatures. The only cosmetic point is the redundant str() wrapping on VmId(str(config.vm_hash)) where config.vm_hash is already a str, which is harmless.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #982 +/- ##
==========================================
- Coverage 80.30% 80.30% -0.01%
==========================================
Files 201 201
Lines 23083 23082 -1
Branches 1511 1511
==========================================
- Hits 18536 18535 -1
Misses 4114 4114
Partials 433 433 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What
Removes the last
aleph_messagesymbol fromsrc/aleph/vm/pool.pyby retyping the daemon's VM-identity fromaleph_message.models.ItemHashto the message-freeVmId = NewType("VmId", str)(defined insupervisor/types.py).VmExecution.vm_hashis retyped to match so the pool'sdict[VmId, VmExecution]key type stays honest.This is the VM-identity slice of the "remove
aleph_messagefrom the supervisor" follow-up flagged during Phase 2. It is intentionally scoped:models.pykeeps its message-content imports (ExecutableContent/InstanceContent/ProgramContent), which drive the message path. Removing the message object fromVmExecutionentirely is a separate, larger refactor.Why it's safe
ItemHashis astrsubclass andVmIdastrNewType, so stored keys and lookups stay compatible (hash/==identical).local.pyalready looked the pool up withVmIdvalues; the create path now storesspec.vm_iddirectly instead of re-wrapping it asItemHash.ItemHash-specific behavior (noisinstance, no.item_hash, no pydantic coercion); consumers eitherstr()the value or use it as a plain string dict key.ItemHashformat validation on the spec path. Content-consuming helpers (cloudinit.get_hostname_from_hash,hostnetwork.allocate_vm_ipv6_subnet) still assume a valid hex hash; the agent always supplies one, so a malformed id now fails inside those consumers rather than eagerly atItemHash(). Out of scope, flagged for awareness.Verification
pool.pyconfirmed free ofItemHash/aleph_message.chownsubprocess + pyroute2 netlink), migration+network 26 passed.Base
Stacked on #981 (
od/grpc-only-supervisor-phase2);pool.pyhere is already the Phase 2 pool. Merge after #981.