← Back to Foundation

JIDO BUGS

Documentation for JIDO_BUGS from the Foundation repository.

JIDO Framework Critical Type System Bugs

Date: 2025-06-29
Reported by: Claude Code Analysis
Context: Foundation JidoSystem Recovery - Phase 1 Dialyzer Analysis
Jido Source: /home/home/p/g/n/agentjido/jido/lib/jido/

Executive Summary

During the comprehensive Dialyzer type analysis of the Foundation JidoSystem recovery effort, I discovered critical type system bugs in the core Jido framework that prevent proper type checking and cause runtime type safety violations. These are not implementation issues in our Foundation code, but fundamental bugs in the upstream Jido library that affect any project using Jido.

CRITICAL BUG #1: Missing Type Definition ⚠️ BLOCKING SEVERITY

File: /home/home/p/g/n/agentjido/jido/lib/jido/sensor.ex
Line: 114
Issue: sensor_result/0 type is referenced but never defined

Evidence:

# Line 114 in jido/lib/jido/sensor.ex - REFERENCES undefined type
@type sensor_result :: Jido.Sensor.sensor_result()

# The type Jido.Sensor.sensor_result/0 is NEVER defined anywhere
# This causes dialyzer to report: "Unknown type: Jido.Sensor.sensor_result/0"

Impact:

  • ALL sensor modules fail Dialyzer type checking
  • Cannot validate sensor return values at compile time
  • Runtime errors possible due to unchecked sensor coordination
  • Type system completely broken for sensor workflows

Files Affected in Foundation:

  • lib/jido_system/sensors/agent_performance_sensor.ex
  • lib/jido_system/sensors/system_health_sensor.ex

CRITICAL BUG #2: Agent Behavior Type Mismatch ⚠️ HIGH SEVERITY

File: /home/home/p/g/n/agentjido/jido/lib/jido/agent.ex
Lines: 1207-1208, callback implementations
Issue: Fundamental design conflict between callback specs and actual implementation

Evidence:

# Callback expects agent structs:
@callback on_error(agent :: t(), reason :: any()) :: {:ok, t()} | {:error, t()}

# But actual implementations return Server.State maps:
# In Foundation JidoSystem agents:
{:ok, %{state: %{status: :recovering, ...}, ...}, []}

Root Cause Analysis:

Looking at the Jido Agent behavior definition:

  • @type agent_result :: {:ok, t()} | {:error, Error.t()} (line ~155)
  • All callbacks expect %Jido.Agent{} structs
  • But the macro-generated code in server context operates on %ServerState{} maps
  • This creates a fundamental type system violation

Impact:

  • ALL agent callback implementations violate type contracts
  • Dialyzer cannot verify agent behavior correctness
  • Runtime type errors when agent structs are expected but maps are provided
  • Impossible to write type-safe agent code

Files Affected in Foundation:

  • lib/jido_system/agents/task_agent.ex
  • lib/jido_system/agents/monitor_agent.ex
  • lib/jido_system/agents/coordinator_agent.ex
  • lib/jido_system/agents/foundation_agent.ex

CRITICAL BUG #3: Overly Broad Generated Specs ⚠️ MEDIUM SEVERITY

File: /home/home/p/g/n/agentjido/jido/lib/jido/agent.ex
Lines: Various auto-generated specs
Issue: Jido macros generate type specs that are broader than actual implementations

Evidence:

# Generated specs include error cases that never occur:
@spec handle_signal(agent(), signal()) :: {:ok, agent()} | {:error, term()}

# But actual implementations always return {:ok, agent()}:
def handle_signal(signal, _agent), do: OK.success(signal)

Impact:

  • Creates “extra range” Dialyzer warnings throughout codebase
  • Makes error handling analysis unreliable
  • Developers cannot trust type specifications for flow control

Signal System Bug ⚠️ MEDIUM SEVERITY

File: Jido Signal dispatch system
Issue: Signal callback return types don’t match expected contracts

Evidence from Dialyzer:

Expected: {:ok, %Jido.Signal{}} | {:error, term()}
Actual: {:ok, {:error, binary()} | {:ok, %Jido.Signal{}} | %Jido.Signal{}, term()}

Fix #1: Add Missing sensor_result Type

# Add to jido/lib/jido/sensor.ex around line 66:
@type sensor_result :: {:ok, map()} | {:error, Error.t()}

Fix #2: Align Agent Callback Types

Either:

  1. Change callbacks to expect ServerState maps:
@callback on_error(state :: map(), reason :: any()) :: {:ok, map()} | {:error, map()}
  1. Or provide conversion functions between Agent structs and ServerState maps

Fix #3: Narrow Generated Specs

Update macro to generate accurate specs based on actual implementation patterns

Workarounds Implemented in Foundation

1. Comprehensive Dialyzer Ignore Patterns

  • 108 ignore patterns in .dialyzer.ignore.exs
  • Covers all known Jido framework type issues
  • Allows focus on actual application bugs

2. Defensive Programming

# Queue type safety with try/rescue
try do
  :queue.len(queue)
rescue
  _ -> 0
end

3. Type Correction

# Fixed Foundation.count/1 to match protocol return type
@spec count(impl :: term() | nil) :: {:ok, non_neg_integer()}

Impact Assessment

Development Impact: CRITICAL

  • Cannot rely on Dialyzer for type safety
  • Manual type checking required for all Jido interactions
  • Increased bug risk due to unchecked type violations

Runtime Impact: HIGH

  • Type mismatches can cause unexpected crashes
  • Sensor type validation completely broken
  • Agent behavior contracts unreliable

Maintenance Impact: HIGH

  • Must maintain extensive ignore patterns
  • Type errors mask real application issues
  • Code review becomes significantly more difficult

Recommendations

Immediate (Foundation):

  1. Comprehensive ignore patterns implemented
  2. Defensive programming patterns in place
  3. Critical type fixes applied where possible

Medium-term (Ecosystem):

  1. Report these bugs to Jido maintainers
  2. Contribute fixes to upstream Jido repository
  3. Consider forking Jido for type-corrected version

Long-term (Architecture):

  1. Evaluate alternative agent frameworks with proper type safety
  2. Build type-safe facades for critical Jido interactions
  3. Consider migration path if type safety is mission-critical

Verification Commands

# Reproduce sensor_result error:
grep -n "sensor_result" /path/to/jido/lib/jido/sensor.ex

# See agent callback type mismatch:
mix dialyzer | grep "callback_type_mismatch"

# View all Jido-related type errors:
mix dialyzer 2>&1 | grep -E "(jido|Jido)"

Conclusion

These are legitimate bugs in the Jido framework that prevent proper type checking and compromise type safety. They are not issues with our Foundation implementation, but fundamental problems in the upstream library that affect anyone using Jido in a type-safe Elixir environment.

The Foundation team has implemented comprehensive workarounds to maintain development velocity, but these upstream issues should be reported and fixed in the Jido library for the benefit of the entire Elixir ecosystem.


Status: Bugs documented, workarounds implemented
Next Action: Report to Jido maintainers with proposed fixes
Foundation Impact: Mitigated through ignore patterns and defensive programming