fix(circuit-breaker): eliminate JSON field false positives in error detection
Fixes circuit breaker opening prematurely due to naive error pattern matching that treated JSON field names like "is_error": false as actual errors. Changes: - ralph_loop.sh: Implement two-stage error detection with JSON filtering - lib/response_analyzer.sh: Apply same filtering to error counting - tests/test_error_detection.sh: Add comprehensive test suite (12 scenarios) Error detection now: - Filters out JSON field patterns before searching for errors - Uses context-specific patterns (^Error:, ]: error, Exception, Fatal) - Avoids type annotations (error: Error) and code identifiers - Includes debug logging when VERBOSE_PROGRESS=true Test coverage validates: ✓ JSON fields don't trigger false positives ✓ Real error messages are correctly detected ✓ Mixed content handled properly ✓ Code diffs and documentation excluded This prevents the consecutive_same_error counter from incrementing on false positives, eliminating unnecessary circuit breaker trips.
This commit is contained in:
parent
e370c1ec2e
commit
8fc53755bf
3 changed files with 200 additions and 2 deletions
|
|
@ -89,7 +89,12 @@ analyze_response() {
|
|||
fi
|
||||
|
||||
# 4. Detect stuck/error loops
|
||||
error_count=$(grep -c -i "error\|failed\|cannot\|unable" "$output_file" 2>/dev/null | head -1 || echo "0")
|
||||
# Use two-stage filtering to avoid counting JSON field names as errors
|
||||
# Stage 1: Filter out JSON field patterns
|
||||
# Stage 2: Count actual error messages (avoid type annotations like "error: Error")
|
||||
error_count=$(grep -v '"[^"]*\(error\|failed\)"[^"]*":' "$output_file" 2>/dev/null | \
|
||||
grep -cE '(^Error:|^ERROR:|^error:|\]: error|Link: error|Error occurred|failed with error|[Ee]xception|Fatal|FATAL|cannot|unable to)' \
|
||||
2>/dev/null || echo "0")
|
||||
error_count=$(echo "$error_count" | tr -d '[:space:]')
|
||||
error_count=${error_count:-0}
|
||||
error_count=$((error_count + 0))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue