igniter.upgrade runs the old version of a package upgrade task after the recompile
Note: this issue was drafted with an AI assistant (Claude) and posted by me. The reproduction and output below were run as shown.
Without the igniter_new archive, mix igniter.upgrade runs the upgrade task of the version being upgraded FROM, not TO. A package's upgrade step for the new version lives only in the new release, so it never runs.
Seen with igniter 0.8.4, Elixir 1.18.4, OTP 27.
Reproduction
Any package that adds an upgrade step in a new release. ash_introspection 0.6.0 adds "0.6.0" => [...] to its task; 0.5.3's task has no such key.
# mix.exs
defp deps do
[{:ash_introspection, "0.5.3"}, {:igniter, "~> 0.7"}]
end
mix deps.get && mix compile
# archives hidden so the project's Mix.Tasks.Igniter.Upgrade runs
MIX_ARCHIVES=/path/with/hex/only mix igniter.upgrade [email protected] --yes
Nothing is printed. mix ash_introspection.upgrade 0.5.3 0.6.0 run afterwards prints the 0.6.0 notice.
Probe output
We added IO.puts lines to the fetched deps/igniter source. In Igniter.Upgrades.apply_updates/2, before compose_task, the probe compares the loaded module's md5 with the md5 of its .beam file on disk:
m = Mix.Task.get("#{package}.upgrade")
{:ok, {_, disk}} = :beam_lib.md5(:code.which(m))
IO.puts("in-memory md5 == on-disk md5? #{m.module_info(:md5) == disk}; app vsn: #{Application.spec(package, :vsn)}")
PROBE apply_updates ash_introspection 0.5.3 -> 0.6.0; loaded? {:file, ~c".../_build/dev/lib/ash_introspection/ebin/Elixir.Mix.Tasks.AshIntrospection.Upgrade.beam"}
PROBE in-memory md5 == on-disk md5? false; app vsn: 0.5.3
PROBE composed Mix.Tasks.AshIntrospection.Upgrade notices=0 first=""
PROBE upgrade returns notices=0 issues=[]
PROBE task.run before do_or_dry_run notices=0 issues=0
PROBE do_or_dry_run has_changes?=false notices=0 yes=true
The .beam on disk is the 0.6.0 build. The module in memory is the 0.5.3 one, loaded before Igniter.Upgrades.upgrade/1 recompiles the deps, and the loaded application spec still reports 0.5.3. Through the igniter_new archive the same run composes the 0.6.0 module (notices=1), so the stale copy appears only on this path.
We did not trace which call loads the old module first.
Expected: after the recompile, apply_updates/2 purges and reloads each <package>.upgrade module (for example :code.purge/1, :code.delete/1, then Code.ensure_loaded/1) before composing it.
🤔 I wasn't able to reproduce this. It works right for me?
What matters is whether the old version of the dependency gets compiled inside the mix igniter.upgrade VM before the upgrade starts.
That happens with a fresh or stale _build. With _build already compiled, the new upgrade task runs correctly — which is likely why it worked for you.
To reproduce:
- Add a dep at version A whose upgrade task prints a marker, then
mix deps.get. rm -rf _buildmix igniter.upgrade <dep>@B --yes- The marker shows version A's task ran, not B's.
I will open a pr against the issue for your review.
Closing this, see linked PR comment from me for more. Long story short, this bug only appears in <= 1.18 and I cannot find an actually satisfying solution unfortunately.