Skip to content

Commit b114c9b

Browse files
nshkrdotcomnshkrdotcom
authored andcommitted
dbg and qc
1 parent f4c1263 commit b114c9b

File tree

9 files changed

+114
-47
lines changed

9 files changed

+114
-47
lines changed

lib/pipeline/debug/nested_execution.ex

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ defmodule Pipeline.Debug.NestedExecution do
1111
alias Pipeline.Tracing.NestedExecution
1212
alias Pipeline.Error.NestedPipeline
1313

14+
# Import types from tracing module
15+
@type trace_context :: Pipeline.Tracing.NestedExecution.trace_context()
16+
1417
@type debug_session :: %{
1518
trace_context: map(),
1619
execution_tree: map(),
@@ -38,8 +41,13 @@ defmodule Pipeline.Debug.NestedExecution do
3841
## Returns
3942
- Debug session context
4043
"""
41-
@spec start_debug_session(map(), map()) :: debug_session()
42-
def start_debug_session(trace_context, options \\ %{}) do
44+
@spec start_debug_session(trace_context()) :: debug_session()
45+
def start_debug_session(trace_context) do
46+
start_debug_session(trace_context, %{})
47+
end
48+
49+
@spec start_debug_session(trace_context(), map()) :: debug_session()
50+
def start_debug_session(trace_context, options) do
4351
session_id = generate_session_id()
4452
execution_tree = NestedExecution.build_execution_tree(trace_context)
4553

@@ -152,8 +160,18 @@ defmodule Pipeline.Debug.NestedExecution do
152160
## Returns
153161
- Comprehensive debugging report
154162
"""
155-
@spec generate_debug_report(map(), any(), map()) :: String.t()
156-
def generate_debug_report(trace_context, error \\ nil, options \\ %{}) do
163+
@spec generate_debug_report(trace_context()) :: String.t()
164+
def generate_debug_report(trace_context) do
165+
generate_debug_report(trace_context, nil, %{})
166+
end
167+
168+
@spec generate_debug_report(trace_context(), any()) :: String.t()
169+
def generate_debug_report(trace_context, error) do
170+
generate_debug_report(trace_context, error, %{})
171+
end
172+
173+
@spec generate_debug_report(trace_context(), any(), map()) :: String.t()
174+
def generate_debug_report(trace_context, error, options) do
157175
execution_tree = NestedExecution.build_execution_tree(trace_context)
158176
analysis = analyze_execution(execution_tree, options)
159177

@@ -179,8 +197,13 @@ defmodule Pipeline.Debug.NestedExecution do
179197
## Returns
180198
- Formatted context information
181199
"""
182-
@spec inspect_context(map(), map()) :: String.t()
183-
def inspect_context(context, step \\ nil) do
200+
@spec inspect_context(map()) :: String.t()
201+
def inspect_context(context) do
202+
inspect_context(context, nil)
203+
end
204+
205+
@spec inspect_context(map(), map() | nil) :: String.t()
206+
def inspect_context(context, step) do
184207
"""
185208
Context Inspection:
186209
==================
@@ -202,10 +225,20 @@ defmodule Pipeline.Debug.NestedExecution do
202225
Execution Chain:
203226
#{format_execution_chain(context)}
204227
205-
Memory Usage: #{format_memory_usage()}
228+
Memory Usage: #{format_memory_usage_inline()}
206229
"""
207230
end
208231

232+
defp format_memory_usage_inline do
233+
try do
234+
memory_bytes = :erlang.memory(:total)
235+
memory_mb = Float.round(memory_bytes / 1_048_576, 1)
236+
"#{memory_mb} MB"
237+
rescue
238+
_ -> "Unknown"
239+
end
240+
end
241+
209242
@doc """
210243
Compare execution performance between different traces.
211244
@@ -851,20 +884,11 @@ defmodule Pipeline.Debug.NestedExecution do
851884
%{
852885
pipeline_id: Map.get(context, :pipeline_id, "unknown"),
853886
nesting_depth: Map.get(context, :nesting_depth, 0),
854-
parent_context: Map.get(context, :parent_context)
887+
parent_context: Map.get(context, :parent_context),
888+
step_count: Map.get(context, :step_count, 0)
855889
}
856890
end
857891

858-
defp format_memory_usage do
859-
try do
860-
memory_bytes = :erlang.memory(:total)
861-
memory_mb = Float.round(memory_bytes / 1_048_576, 1)
862-
"#{memory_mb} MB"
863-
rescue
864-
_ -> "Unknown"
865-
end
866-
end
867-
868892
defp format_comparison_table(summaries) do
869893
header = "Execution | Duration | Success Rate | Pipelines\n"
870894
separator = "----------|----------|--------------|----------\n"

lib/pipeline/error/nested_pipeline.ex

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ defmodule Pipeline.Error.NestedPipeline do
3030
debug_info: map()
3131
}
3232

33+
@type error_type ::
34+
:circular_dependency | :not_found | :resource_limit | :timeout | :unknown | :validation
35+
36+
@type debug_log_entry :: %{
37+
timestamp: DateTime.t(),
38+
error_type: error_type(),
39+
error_message: String.t(),
40+
pipeline_id: String.t(),
41+
nesting_depth: non_neg_integer(),
42+
step_name: String.t() | nil,
43+
step_type: String.t() | nil,
44+
execution_chain: [String.t(), ...],
45+
total_steps: non_neg_integer(),
46+
elapsed_ms: integer(),
47+
context_summary: %{
48+
context_size: non_neg_integer(),
49+
has_parent: boolean(),
50+
key_count: non_neg_integer(),
51+
nesting_depth: non_neg_integer()
52+
},
53+
step_config: map() | nil
54+
}
55+
3356
@doc """
3457
Format a nested pipeline error with comprehensive context information.
3558
@@ -253,8 +276,13 @@ defmodule Pipeline.Error.NestedPipeline do
253276
## Returns
254277
- Structured log entry map
255278
"""
256-
@spec create_debug_log_entry(any(), map(), map() | nil) :: map()
257-
def create_debug_log_entry(error, context, step \\ nil) do
279+
@spec create_debug_log_entry(any(), map()) :: debug_log_entry()
280+
def create_debug_log_entry(error, context) do
281+
create_debug_log_entry(error, context, nil)
282+
end
283+
284+
@spec create_debug_log_entry(any(), map(), map() | nil) :: debug_log_entry()
285+
def create_debug_log_entry(error, context, step) do
258286
safe_context = ensure_safe_context(context)
259287

260288
%{

lib/pipeline/metrics/nested_performance.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,9 @@ defmodule Pipeline.Metrics.NestedPerformance do
663663
# < 1s
664664
d when d < 1000 -> 4
665665
# < 5s
666-
d when d < 5000 -> 3
666+
d when d < 5_000 -> 3
667667
# < 30s
668-
d when d < 30000 -> 2
668+
d when d < 30_000 -> 2
669669
# > 30s
670670
_ -> 1
671671
end
@@ -684,7 +684,6 @@ defmodule Pipeline.Metrics.NestedPerformance do
684684
:good -> 3
685685
:fair -> 2
686686
:poor -> 1
687-
_ -> 2
688687
end
689688

690689
avg_score = (success_rate_score + duration_score + depth_score + resource_score) / 4

lib/pipeline/step/nested_pipeline.ex

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,29 @@ defmodule Pipeline.Step.NestedPipeline do
262262
{:error, formatted_error}
263263
end
264264

265-
parent when not is_nil(parent) ->
265+
_parent ->
266266
# For nested pipelines, check circular dependency against parent context,
267267
# then check other limits against current context
268-
with :ok <- check_circular_dependency_with_parent(pipeline_name, parent),
268+
269+
# Inline circular dependency check to avoid dialyzer warning
270+
circular_check_result =
271+
case safety_context.parent_context do
272+
nil ->
273+
:ok
274+
275+
parent_ctx ->
276+
# Ensure parent_context has the right structure for RecursionGuard
277+
safe_parent = %{
278+
nesting_depth: Map.get(parent_ctx, :nesting_depth, 0),
279+
pipeline_id: Map.get(parent_ctx, :pipeline_id, "unknown"),
280+
parent_context: Map.get(parent_ctx, :parent_context),
281+
step_count: Map.get(parent_ctx, :step_count, 0)
282+
}
283+
284+
Pipeline.Safety.RecursionGuard.check_circular_dependency(pipeline_name, safe_parent)
285+
end
286+
287+
with :ok <- circular_check_result,
269288
:ok <- check_limits_for_current(safety_context, safety_config) do
270289
:ok
271290
else
@@ -364,16 +383,6 @@ defmodule Pipeline.Step.NestedPipeline do
364383
defp put_if_present(map, _key, nil), do: map
365384
defp put_if_present(map, key, value), do: Map.put(map, key, value)
366385

367-
# Check circular dependency using parent context
368-
defp check_circular_dependency_with_parent(pipeline_name, parent_context) do
369-
alias Pipeline.Safety.RecursionGuard
370-
371-
case RecursionGuard.check_circular_dependency(pipeline_name, parent_context) do
372-
:ok -> :ok
373-
{:error, message} -> {:error, message}
374-
end
375-
end
376-
377386
# Check resource limits for current context only
378387
defp check_limits_for_current(safety_context, safety_config) do
379388
alias Pipeline.Safety.RecursionGuard
@@ -383,7 +392,15 @@ defmodule Pipeline.Step.NestedPipeline do
383392
max_total_steps: Map.get(safety_config, :max_total_steps, 1000)
384393
}
385394

386-
case RecursionGuard.check_limits(safety_context, recursion_limits) do
395+
# Ensure safety_context has the right structure for RecursionGuard
396+
safe_context = %{
397+
nesting_depth: Map.get(safety_context, :nesting_depth, 0),
398+
pipeline_id: Map.get(safety_context, :pipeline_id, "unknown"),
399+
parent_context: Map.get(safety_context, :parent_context),
400+
step_count: Map.get(safety_context, :step_count, 0)
401+
}
402+
403+
case RecursionGuard.check_limits(safe_context, recursion_limits) do
387404
:ok -> :ok
388405
{:error, message} -> {:error, message}
389406
end

test/integration/nested_pipeline_phase4_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ defmodule Pipeline.Integration.NestedPipelinePhase4Test do
519519
parent_context: %{pipeline_id: "parent", nesting_depth: 0, parent_context: nil}
520520
}
521521

522-
timeout_formatted = ErrorHandler.format_timeout_error(30, timeout_context, 35000)
522+
timeout_formatted = ErrorHandler.format_timeout_error(30, timeout_context, 35_000)
523523
assert timeout_formatted =~ "timeout"
524524
assert timeout_formatted =~ "30s"
525525
assert timeout_formatted =~ "35.0s"

test/integration/workflow_scenarios_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ defmodule Pipeline.WorkflowScenariosTest do
174174

175175
case result do
176176
{:ok, results} ->
177-
IO.inspect(results, label: "Workflow results")
178177
# Verify all steps completed successfully
179178
assert results["code_analysis"]["success"] == true
180179
assert results["generate_improvements"]["success"] == true

test/pipeline/debug/nested_execution_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ defmodule Pipeline.Debug.NestedExecutionTest do
151151
pipeline_id: "slow_pipeline",
152152
spans: [
153153
# 10 seconds - slow
154-
%{depth: 0, duration_ms: 10000, status: :completed},
154+
%{depth: 0, duration_ms: 10_000, status: :completed},
155155
# 8 seconds - slow
156-
%{depth: 1, duration_ms: 8000, status: :completed}
156+
%{depth: 1, duration_ms: 8_000, status: :completed}
157157
],
158158
children: [],
159-
total_duration_ms: 18000,
159+
total_duration_ms: 18_000,
160160
step_count: 2,
161161
max_depth: 1
162162
}

test/pipeline/error/nested_pipeline_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ defmodule Pipeline.Error.NestedPipelineTest do
9696
parent_context: %{pipeline_id: "parent", nesting_depth: 0, parent_context: nil}
9797
}
9898

99-
result = NestedPipeline.format_timeout_error(30, context, 45000)
99+
result = NestedPipeline.format_timeout_error(30, context, 45_000)
100100

101101
assert result =~ "Pipeline execution timeout"
102102
assert result =~ "Limit: 30s"
@@ -109,7 +109,7 @@ defmodule Pipeline.Error.NestedPipelineTest do
109109
test "provides timeout troubleshooting guidance" do
110110
context = %{pipeline_id: "test", nesting_depth: 0, parent_context: nil}
111111

112-
result = NestedPipeline.format_timeout_error(10, context, 15000)
112+
result = NestedPipeline.format_timeout_error(10, context, 15_000)
113113

114114
assert result =~ "Long-running AI model calls"
115115
assert result =~ "Network connectivity issues"

test/pipeline/metrics/nested_performance_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ defmodule Pipeline.Metrics.NestedPerformanceTest do
319319
performance_metrics = %{
320320
summary: %{overall_success_rate: 100.0, total_pipelines: 1, max_depth: 1},
321321
# Over 1 minute
322-
pipeline_metrics: [%{duration_ms: 70000, step_count: 3}],
323-
total_duration_ms: 70000,
322+
pipeline_metrics: [%{duration_ms: 70_000, step_count: 3}],
323+
total_duration_ms: 70_000,
324324
resource_metrics: %{peak_memory_mb: 100.0}
325325
}
326326

@@ -451,7 +451,7 @@ defmodule Pipeline.Metrics.NestedPerformanceTest do
451451
# Very low success, deep nesting
452452
summary: %{overall_success_rate: 40.0, max_depth: 12, total_pipelines: 20},
453453
# Very slow
454-
total_duration_ms: 45000,
454+
total_duration_ms: 45_000,
455455
# High resource usage
456456
resource_metrics: %{peak_memory_mb: 2000.0, gc_collections: 50, process_count_peak: 200},
457457
pipeline_metrics: []
@@ -525,7 +525,7 @@ defmodule Pipeline.Metrics.NestedPerformanceTest do
525525
trace_id: "test_trace",
526526
start_time: DateTime.utc_now() |> DateTime.add(-10, :second),
527527
end_time: DateTime.utc_now(),
528-
total_duration_ms: 10000,
528+
total_duration_ms: 10_000,
529529
pipeline_metrics: [
530530
%{pipeline_id: "slow_pipeline", duration_ms: 8000, step_count: 5, success: true},
531531
%{pipeline_id: "fast_pipeline", duration_ms: 500, step_count: 2, success: true},

0 commit comments

Comments
 (0)