Skip to content

Runtime crash: Jido.Browser.Error.InvalidError not JSON-encodable (jido_browser 2.0 + jido_ai) #24

@ortegacmanuel

Description

@ortegacmanuel

Problem

When running Goodwizard with updated deps (jido_browser ~> 2.0, jido_ai main), the agent crashes when the LLM invokes any browser tool that returns an error.

Error

(Protocol.UndefinedError) protocol Jason.Encoder not implemented for 
type Jido.Browser.Error.InvalidError (a struct)

Jason.Encoder protocol must always be explicitly implemented.

Stacktrace:
  (jason) Jason.encode!/2
  (jido_ai) Jido.AI.Turn.encode_tool_result_envelope/2
  (jido_ai) Jido.AI.Reasoning.ReAct.Strategy.append_tool_result_to_run_context/5
  (jido_ai) Jido.AI.Reasoning.ReAct.Strategy.apply_runtime_event/2
  (jido_ai) Jido.AI.Reasoning.ReAct.Strategy.process_worker_event/2

Cause

jido_ai's ReAct strategy calls Jido.AI.Turn.encode_tool_result_envelope/2 which tries to Jason.encode! tool results, including error structs. Jido.Browser.Error.InvalidError (from jido_browser 2.0) doesn't implement Jason.Encoder, so it crashes.

Impact

  • Text-only Telegram chat works fine
  • Any query where the LLM decides to use a browser tool (navigate, click, etc.) crashes the agent process
  • The agent recovers (Telegram handler restarts), but the user sees "an unexpected error occurred"

Likely fix

Either:

  1. jido_browser 2.0 needs @derive Jason.Encoder on all error structs (InvalidError, NavigationError, TimeoutError, etc.)
  2. jido_ai's Turn.encode_tool_result_envelope needs to handle non-encodable structs gracefully (e.g., convert to %{error: inspect(struct)} before encoding)

Option 2 is more defensive — any tool could return a non-encodable struct.

Environment

  • jido ~> 2.1 (hex)
  • jido_ai main branch (commit 5601aa5)
  • jido_browser ~> 2.0 (hex, v2.0.0)
  • Elixir 1.18 / OTP 27
  • Docker container

Related

This was discovered while resolving #23 (broken deps). The browser tools work in terms of compilation, but fail at runtime when errors occur.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions