fix: use Code.ensure_compiled/1 for compile-time module checks - #8
Closed
Munksgaard wants to merge 1 commit into
Closed
Munksgaard wants to merge 1 commit into
Munksgaard wants to merge 1 commit into
Conversation
Code.ensure_loaded?/1 only checks if a module is already loaded in the
BEAM VM. When called at compile time (e.g. in module body expressions or
via use Jido.Composer.Workflow), it returns false for modules that exist
in the project but have not been compiled yet, causing spurious "not a
valid Jido.Action module" errors.
For example, the following triggers the bug because MapNode.new/1 runs
at compile time and ExtractDocumentAction may not have been compiled yet:
```elixir
defmodule MyApp.ExtractionPipeline do
{:ok, extract_node} =
Jido.Composer.Node.MapNode.new(
name: :extract,
over: :documents,
node: MyApp.ExtractDocumentAction
)
use Jido.Composer.Workflow,
name: "extraction_pipeline",
nodes: %{extract: extract_node, merge: MyApp.MergeAction},
transitions: %{{:extract, :ok} => :merge, {:merge, :ok} => :done},
initial: :extract
end
```
Replace with Code.ensure_compiled/1 which triggers compilation of the
target module if needed. Only changes call sites that can run at compile
time; ensure_loaded? calls for optional runtime deps (AgentServer,
OpenTelemetry) are left unchanged.
Munksgaard
force-pushed
the
fix/ensure-compiled-for-compile-time-checks
branch
from
April 7, 2026 08:57
f42321b to
9b952b3
Compare
Contributor
Author
|
Hm, this doesn't seem to work the way I expected. Sorry for the noise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code.ensure_loaded?/1 only checks if a module is already loaded in the BEAM VM. When called at compile time (e.g. in module body expressions or via use Jido.Composer.Workflow), it returns false for modules that exist in the project but have not been compiled yet, causing spurious "not a valid Jido.Action module" errors.
For example, the following triggers the bug because MapNode.new/1 runs at compile time and ExtractDocumentAction may not have been compiled yet:
Replace with Code.ensure_compiled/1 which triggers compilation of the target module if needed. Only changes call sites that can run at compile time; ensure_loaded? calls for optional runtime deps (AgentServer, OpenTelemetry) are left unchanged.