Overview
The Type Inference Debugger is an L3 Genetically Enhanced agent operating in the quality domain of the Prismatic Platform. This agent specializes in diagnosing and resolving Dialyzer type inference issues, detecting conflicting typespecs, identifying vague type declarations, and optimizing type system usage across the platform's Elixir codebase. The "Genetically Enhanced" designation indicates that this agent has undergone evolutionary optimization through the platform's genetic algorithm-based agent improvement pipeline, resulting in superior diagnostic capabilities compared to standard agents.
Dialyzer type inference issues are among the most challenging defect categories in Elixir development. Unlike compiler errors that point to a specific line, Dialyzer warnings often arise from complex type inference chains where the actual root cause is several function calls removed from the reported location. The Type Inference Debugger specializes in tracing these inference chains to their root causes, generating precise fix recommendations that resolve the underlying type conflict rather than merely suppressing the warning.
This agent is part of the platform's 434-strong autonomous agent ecosystem, maintaining the platform's zero-Dialyzer-violation standard under the NO MERCY doctrine.
Diagnostic Capabilities
| Capability | Description | Complexity | Auto-Fix Rate |
|---|---|---|---|
| Inference Chain Tracing | Follow type inference from warning to root cause | High | 60% |
| Conflicting Spec Detection | Identify specs that contradict each other | Medium | 85% |
| Vague Type Identification | Flag overly broad type declarations | Low | 95% |
| Success Typing Analysis | Compare declared types with inferred success types | High | 50% |
| Contract Violation | Detect function calls that violate caller's spec | High | 70% |
| Pattern Match Coverage | Identify patterns not covered by type declarations | Medium | 80% |
| Opaque Type Violations | Detect improper internal structure access | Medium | 75% |
Dialyzer Warning Classification
The Type Inference Debugger classifies Dialyzer warnings into severity categories that guide remediation priority.
| Warning Type | Severity | Example | Typical Root Cause |
|---|---|---|---|
| no_return | Critical | Function can never return normally | Infinite recursion or crash path |
| invalid_contract | High | Spec contradicts success typing | Incorrect @spec annotation |
| pattern_match | High | Pattern can never match | Dead code or logic error |
| call | Medium | Function called with wrong types | Type mismatch in caller |
| guard_fail | Medium | Guard clause will always fail | Logic error in guards |
| unused_fun | Low | Function never called | Dead code |
Technical Implementation
defmodule PrismaticAgents.TypeInferenceDebugger do
@moduledoc """
L3 Type Inference Debugger agent (Genetically Enhanced).
Diagnoses and resolves Dialyzer type inference issues.
"""
use GenServer
require Logger
@dialyzer_check_interval_ms :timer.hours(2)
defstruct [
:warning_registry,
:inference_chains,
:fix_recommendations,
:plt_status,
:last_check_at,
status: :diagnosing
]
@spec start_link(keyword()) :: GenServer.on_start()
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end
@impl true
def init(_opts) do
schedule_dialyzer_check()
{:ok, %__MODULE__{warning_registry: %{}, inference_chains: []}}
end
@impl true
def handle_info(:dialyzer_check, state) do
warnings = run_dialyzer_analysis()
chains = trace_inference_chains(warnings)
fixes = generate_fix_recommendations(chains)
:telemetry.execute(
[:prismatic, :agents, :type_inference, :check],
%{warnings: length(warnings), chains_traced: length(chains), fixes_generated: length(fixes)},
%{auto_fixable: Enum.count(fixes, & &1.auto_fixable)}
)
schedule_dialyzer_check()
{:noreply, %{state |
warning_registry: index_warnings(warnings),
inference_chains: chains,
fix_recommendations: fixes,
last_check_at: DateTime.utc_now()
}}
end
defp trace_inference_chains(warnings) do
warnings
|> Enum.map(fn warning ->
%{
warning: warning,
chain: build_inference_chain(warning),
root_cause: identify_root_cause(warning),
confidence: calculate_diagnosis_confidence(warning)
}
end)
|> Enum.sort_by(& &1.confidence, :desc)
end
defp build_inference_chain(warning) do
initial_location = warning.location
called_functions = extract_call_chain(initial_location)
called_functions
|> Enum.map(fn {module, function, arity} ->
%{
mfa: {module, function, arity},
declared_type: fetch_declared_type(module, function, arity),
inferred_type: fetch_success_typing(module, function, arity),
conflict: detect_type_conflict(module, function, arity)
}
end)
end
endInference Chain Resolution Strategy
The Type Inference Debugger follows a systematic resolution strategy when addressing type inference issues.
1. Collect Dialyzer warning
2. Trace inference chain from warning location
3. Identify each function in the call chain
4. Compare declared specs with success typings
5. Locate the EARLIEST point where types diverge
6. Generate fix at the root cause (not the symptom)
7. Validate fix with targeted Dialyzer re-run| Resolution Step | Tool | Expected Duration |
|---|---|---|
| Warning Collection | mix dialyzer --format short | 60-120 seconds |
| Chain Tracing | AST analysis + PLT query | 5-30 seconds per warning |
| Root Cause Identification | Success typing comparison | 2-10 seconds per chain |
| Fix Generation | Pattern-matched recommendations | < 1 second per fix |
| Fix Validation | Targeted Dialyzer re-run | 30-60 seconds per fix |
Genetic Enhancement Features
The Type Inference Debugger's genetic enhancement has produced several capabilities that exceed standard agent performance.
| Enhancement | Description | Improvement Over Baseline |
|---|---|---|
| Pattern Recognition | Recognizes recurring type conflict patterns | 3x faster diagnosis |
| Root Cause Accuracy | Higher precision in identifying true root cause | 92% vs 70% baseline |
| Fix Quality | Generated fixes require fewer iterations | 1.2 vs 2.8 iterations |
| PLT Cache Strategy | Optimized PLT caching for faster analysis | 40% faster Dialyzer runs |
Genetic Enhancement Methodology
The "Genetically Enhanced" designation is not merely a label -- it reflects a rigorous evolutionary optimization process that the Type Inference Debugger has undergone through the platform's genetic algorithm-based agent improvement pipeline. Each generation of the agent is evaluated against a fitness function that measures diagnostic accuracy, fix quality, and resolution speed, with the fittest variants selected for the next generation.
defmodule PrismaticAgents.TypeInferenceDebugger.FitnessEvaluator do
@moduledoc """
Fitness evaluation for genetic enhancement of the Type Inference Debugger.
Measures diagnostic accuracy, fix quality, and resolution speed.
"""
@spec evaluate_fitness(map()) :: float()
def evaluate_fitness(generation_metrics) do
accuracy_score = generation_metrics.root_cause_accuracy * 0.40
fix_quality = (1.0 - generation_metrics.fix_iterations / 5.0) * 0.30
speed_score = min(1.0, 300_000 / max(generation_metrics.avg_resolution_ms, 1)) * 0.20
coverage_score = generation_metrics.warning_types_handled / 12 * 0.10
accuracy_score + fix_quality + speed_score + coverage_score
end
end| Generation | Fitness Score | Root Cause Accuracy | Avg Fix Iterations | Key Improvement |
|---|---|---|---|---|
| Gen 1 | 0.42 | 55% | 4.2 | Baseline capabilities |
| Gen 5 | 0.61 | 70% | 3.1 | Pattern library initialized |
| Gen 10 | 0.78 | 82% | 2.2 | PLT cache optimization |
| Gen 15 | 0.89 | 89% | 1.5 | Inference chain tracing improved |
| Gen 18 | 0.95 | 92% | 1.2 | Current production version |
Common Type Conflict Patterns
Through its genetically enhanced pattern recognition capabilities, the Type Inference Debugger has cataloged the most common type conflict patterns encountered in large-scale Elixir codebases. This pattern library enables rapid diagnosis by matching new warnings against known conflict signatures.
| Pattern | Description | Frequency | Root Cause Location |
|---|---|---|---|
| Narrowing Mismatch | Spec too narrow for actual return values | 25% | Function body returns unexpected variant |
| Protocol Confusion | Protocol dispatch type conflicts | 15% | Missing protocol implementation |
| Callback Drift | @impl function diverges from behaviour spec | 18% | Behaviour spec updated, implementations lag |
| Guard Contradiction | Guard clause contradicts parameter spec | 12% | Spec and guard disagree on valid inputs |
| Opaque Leak | Internal opaque type structure accessed directly | 8% | Pattern matching on opaque type internals |
| Union Incomplete | Return type union missing error variants | 22% | New error path added without spec update |
Platform Status
| Metric | Current | Target |
|---|---|---|
| Dialyzer warnings | 0 | 0 |
| PLT build time | 180 seconds | < 300 seconds |
| Warning resolution time | < 5 minutes | < 10 minutes |
| Auto-fix success rate | 78% | > 75% |
| False positive rate | 0% | 0% |
Integration Points
- Quality Gates -- Dialyzer zero-warning enforcement
- Telemetry Integration -- Type analysis metrics
- Autonomous Self-Healing -- Auto-fix Dialyzer warnings
- AIAD Standard -- Full agent specification compliance
AIAD Specification Compliance
| AIAD Component | Status |
|---|---|
| Agent specification file | Compliant |
| Behavioral rules | 14 rules defined |
| Telemetry integration | Full coverage |
| NM/ND doctrine enforcement | Active |
| SEADF integration | Registered |
| Property-based testing | 42 properties verified |
Related Agents
- Type Annotation Analyst -- Typespec completeness and quality analysis
- Route Testing Specialist -- Route handler type verification
- Six Sigma Psycho Coordinator -- Quality enforcement for type safety
Authority Level
L3 - Strategic Command - Multi-domain coordination with authority to diagnose and resolve Dialyzer type inference issues across the entire platform.
Connect & Contribute
Created by Tomáš Korcak (korczis) | Open Source under GHL