Date: 2025-05-16
Status
Accepted
Context
The Codexis project uses both OpenRouter and Ollama as LLM providers. The Ollama client requires a pool process (Codexis.LLM.OllamaClient.Pool) to be running. In server/OTP applications, this would typically be started in the supervision tree. However, most Codexis workflows are run via CLI commands (e.g., mix codexis.check_scannos ...), which do not always start the full supervision tree.
Decision
We decided to start the Ollama pool on demand, at the point of use, if the provider is set to :ollama and the pool is not already running. This logic is placed at the start of the scanno integration pipeline, ensuring that CLI commands work reliably without requiring a supervision tree or manual pool management.
if Application.get_env(:codexis, :llm_provider) == :ollama do
case Process.whereis(Codexis.LLM.OllamaClient.Pool) do
nil -> Codexis.LLM.OllamaClient.Pool.start_link([])
_ -> :ok
end
end
Consequences
Positive
- CLI commands will always work with Ollama as the provider, regardless of how the code is invoked.
- No need to add the pool to the supervision tree for CLI-only workflows.
- In server/OTP contexts, the pool can still be supervised if desired, but the on-demand logic is harmless if the pool is already running.
- This approach avoids unnecessary processes when Ollama is not the provider.
Negative
- Slightly less "OTP-pure" than always using a supervision tree, but much more robust for CLI-heavy workflows.
- If the pool fails after being started, it will not be automatically restarted unless the CLI command is re-run.
References
- Implementation:
Codexis.BuildManager.ScannoIntegration.check_manuscript_for_scannos/2 - ADR-0031: LaTeX Requirements: Fontspec, LuaLaTeX, and MathJax