Skip to content

fix: expand plugin aliases in Pod macro before escaping#239

Merged
mikehostetler merged 2 commits intoagentjido:mainfrom
Jdyn:jaden/fix-pod-plugins-escape
Mar 29, 2026
Merged

fix: expand plugin aliases in Pod macro before escaping#239
mikehostetler merged 2 commits intoagentjido:mainfrom
Jdyn:jaden/fix-pod-plugins-escape

Conversation

@Jdyn
Copy link
Copy Markdown
Contributor

@Jdyn Jdyn commented Mar 29, 2026

Summary

  • Fix double-escaping of plugin module aliases in Jido.Pod.__using__/1 by running expand_and_eval_literal_option on the user-supplied :plugins list before merging it into agent_opts

Problem

The Jido.Pod.__using__/1 macro correctly expands AST aliases for :name, :default_plugins, and :topology via Definition.expand_and_eval_literal_option, but the user-supplied :plugins list was passed through raw. When Macro.escape(agent_opts) runs inside the quote block, it double-escapes the {:__aliases__, meta, segments} tuples, so downstream code like Jido.Agent.__extract_plugin_module__/1 receives raw AST tuples instead of resolved module atoms.

# Before fix — raw AST alias tuples pass through Macro.escape:
agent_opts =
  opts
  |> Keyword.put(:plugins, pod_plugins ++ Keyword.get(opts, :plugins, []))
  #                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  #                        [{:__aliases__, meta, [:MyApp, :Intelligence, ...]}]

quote do
  use Jido.Agent, unquote(Macro.escape(agent_opts))
  #               ^^^ double-escapes the alias tuples
end

Fix

Expand user-supplied :plugins with expand_and_eval_literal_option (the same helper already used for :name, :default_plugins, and :topology) before concatenation:

user_plugins =
  Definition.expand_and_eval_literal_option(Keyword.get(opts, :plugins, []), __CALLER__)

agent_opts =
  opts
  |> Keyword.delete(:topology)
  |> Keyword.put(:plugins, pod_plugins ++ (user_plugins || []))

Evaluate the user-provided :plugins option with Definition.expand_and_eval_literal_option and store it in user_plugins, then merge pod_plugins with (user_plugins || []) when building agent_opts. This ensures literal plugin lists are expanded/evaluated correctly and avoids nil/unevaluated values when concatenating plugin lists.
@mikehostetler mikehostetler merged commit 6c44bac into agentjido:main Mar 29, 2026
6 checks passed
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.

2 participants