Features and support
On this page
Everything Hotcode does, grouped by concern, with the guide that explains each item. Then the versions it runs on, what it does not do, and how it is tested.
Changes applied to a running node
| change | how | guide |
|---|---|---|
| module code | changed beams load atomically; processes running them are suspended around the switch | How it works |
a defstruct gains or loses fields |
Hotcode.StructMigrator rebuilds the struct in every live process that holds it, and back on rollback |
State migration |
| state that changes meaning | use Hotcode.Versioned, vsn: N with one upgrade/2 and one downgrade/2 per version step; a hand-written code_change/3 also works |
State migration |
| ETS rows | use Hotcode.Table, vsn: N rewrites rows through upgrade/2 steps, and the table survives its owner being replaced |
ETS tables |
behaviours hosted by a library (GenStage, gen_event) |
list the host in hosts: |
Hosted behaviours |
| supervisor children added, removed or changed | reconciled in place after the deploy; retain_state: keeps a changed child's state |
Supervision |
| a process that has to be replaced | Hotcode.Swap.child/3 passes its state and sockets through Hotcode.Holder and re-sends its waiting mailbox; Hotcode.Swap.swapping?/0 tells terminate/2 not to close them |
Restart-free replacement |
Application.start/2, or a replaced @on_load or NIF module |
Hotcode.AppSwap restarts that one application inside the VM, when the signers ask for it and the operator allows it |
In-place restart |
| a new NIF version | a new module beside the old one; the facade switches in the atomic load | NIFs |
| a dependency bump | shipped like your own code and classified by semver; a major bump needs the signers' --accept-major |
Dependency bumps |
| a node restart | stored patches are re-verified and re-applied at boot | After a restart |
Safety
| feature | guide |
|---|---|
Ed25519-signed envelopes; the node holds public keys only and refuses every deploy until trusted_keys, audience and allowed_prefixes are set |
Security |
threshold: N distinct signers for a deploy or a rollback |
In practice |
a signature binds the patch hash, audience, a 15-minute expiry, a replay counter, the base code it replaces, and the force, restart_apps, accept_major, requires and auto_rollback fields |
What a signature binds |
allowed_prefixes limits which modules a patch may touch; OTP, the Elixir standard library and Hotcode are always refused |
Module policy |
a kill switch (Hotcode.lock/0) and a failure lockout (five refused envelopes in a minute lock deploys for five minutes) |
Brakes |
a dry run (--dry-run) and analyzer findings (:otp_mismatch, :nif, :on_load, :major_bump, :removed_exports, :build_env, :closure_in_state, :cross_node_contract and others) that block or warn before anything loads |
Analyzer findings |
mix hotcode.sign shows what a signature authorizes, and refuses an envelope whose statement does not match its code |
Signing |
| rollback is signed like a deploy and names the release it undoes; it is refused where another release is on top | Rollback |
| a failure at any step reverts the node; if the revert cannot complete, the node locks itself | When something fails |
Hotcode.Hook: before_deploy/1 can veto a deploy; after_deploy/1, after_rollback/1 and after_app_restart/1 are notified |
Hooks |
Clusters
| feature | guide |
|---|---|
| a roll deploys node by node with a health check after each, and undoes the nodes already done on failure | What a roll does |
| every node runs a dry run before any node changes | What a roll does |
| one roll at a time, under a cluster-wide lock | What a roll does |
mixed versions: --requires (signed) orders releases, Hotcode.Cluster.applied?/1 gates a new message format, expected_nodes covers partitions, releases: declares what an image already contains |
Clusters |
convergence: every node tracks every node's release (Hotcode.Cluster.members/0); :report (the default) reports divergence, :converge lets a node that is behind pull signed envelopes from a peer |
Converging forward |
:auto adds a deadman: a release whose signed statement carries auto_rollback is undone cluster-wide if the cluster has not followed it by the deadline |
Deadman rollback |
Delivery
| feature | guide |
|---|---|
mix hotcode.gen_key, build, sign, push, deploy, rollback, status, describe |
Commands |
a stand-alone hotcode escript (describe, sign, push, rollback, status, gen-key) that runs without your project |
Deploying from CI |
a CI toolchain image (docker/Dockerfile), one tag per OTP and Elixir pair |
The image |
--json on every command, and exit codes 0 to 5 that say what changed |
Deploying from CI |
two transports: signed HTTPS requests (needs plug and bandit) and Erlang distribution (needs the cookie) |
Transports |
--key env:NAME reads a private key from a CI secret; the node can be reached over Tailscale |
The key in a secret manager, Tailscale |
| GitHub Actions workflows (one signer, or CI plus a human signer) and Argo Workflows / Argo CD manifests | GitHub Actions, Argo |
Developer tooling
| feature | guide |
|---|---|
seventeen Credo rules for hot-deploy mistakes (@on_load, NIFs, closures kept in state or in options, missing migration steps, local receive and accept loops, compile-time env, a terminate that closes a swapped socket and others) |
Credo rules |
mix hotcode.check runs them with no configuration; mix hotcode.credo.install adds them to .credo.exs |
Credo rules |
an Igniter installer: mix igniter.install hotcode (or mix hotcode.install) |
Getting started |
use Hotcode.Test: build the next version in a test, deploy it under live processes, and assert the same pid, migrated state, rollback, a second deploy, ETS rows, no lost messages, and mixed-version :peer clusters |
Testing your hot deploys |
Observability
| feature | guide |
|---|---|
every deploy attempt, accepted or refused, goes to Logger, telemetry [:hotcode, :audit] and an append-only audit.log in store_dir |
Audit log |
telemetry [:hotcode, :deploy], [:hotcode, :rollback] and cluster events ([:hotcode, :cluster, :diverged], :converged, :node_down, :cannot_converge, :converge_failed, :auto_rollback) |
Telemetry |
Requirements and compatibility
-
Elixir 1.17 or later, OTP 26 to 29.
-
Developed on Elixir 1.20 / OTP 29. CI tests eight pairs:
Elixir OTP 1.17 26, 27 1.18 26, 27 1.19 27, 28 1.20 28, 29 -
On Elixir 1.17, add
{:jason, "~> 1.4"}to your deps (theJSONmodule arrived in 1.18). -
Optional dependencies:
plugandbanditfor the HTTP endpoint,credofor the rules,igniterfor the installer,stream_datafor the property form ofassert_roundtrip/3. -
Build patches with the same OTP and Elixir as the running release. The node refuses another OTP and warns about another Elixir.
What it does not do
- Upgrade OTP, Elixir or Hotcode itself. Those need a restart.
- Replace a loaded NIF or
@on_loadmodule, or apply anApplication.start/2change, unless that application may be restarted in place. - Change an application's
.appfile orpriv/in a dependency bump. - Migrate plain
:ets.new/2tables,:persistent_term, the process dictionary,Agent,Taskor plainspawnloops. - Keep stored closures working: an
fnkept in state, ETS or a message fails with:badfunafter the second deploy that replaces its module. The plan reports those it finds in the states of the processes a deploy touches (:closure_in_state). - Translate messages between nodes on different releases. A message format change takes three releases (see Clusters).
- Protect against a holder of the Erlang cookie, a compromised signer's machine or a malicious patch its signers approved.
The details, and the limits of what is implemented, are in Limits.
How it is tested
With HOTCODE_REQUIRE_CLUSTER=1, as CI runs it, mix test runs 521 tests and 6 doctests.
About 40 of them are end to end and start real OS processes (--exclude e2e skips them).
The suite covers connections that survive a deploy with no lost or duplicated bytes, migration
chains, failed migrations, supervision changes, a TCP connection that survives an application
restart, two applications where the second fails to start, signed rolls across real :peer
nodes, HTTP and TLS, and forged, replayed, expired, mis-audienced and under-signed envelopes,
policy, lockout and hostile input.
The end-to-end tests start a node with mix run and deploy a bumped dependency to it with the
real mix hotcode.* tasks over HTTP while a TCP client stays connected. They also cover a
stranger's key, a two-signer threshold and a patch that survives a node restart.
examples/pulse runs the features together on three nodes, watched
by a checker in a separate OS process. It is not part of mix test.
Three independent adversarial reviews (two by Opus), and a later multi-agent Opus review of the CI, Credo, ETS and cluster additions, found real problems: blind co-signing, memory exhaustion by anonymous clients, a rolled-back patch returning from the store, and bugs introduced by earlier fixes. All were fixed, each with a regression test that fails without the fix. None of the reviews found a way to run code without a trusted key. That is evidence, not a guarantee; see SECURITY.md.