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
|
|
@ -386,8 +386,25 @@ EOF
|
|||
# Get file change count for circuit breaker
|
||||
local files_changed=$(git diff --name-only 2>/dev/null | wc -l || echo 0)
|
||||
local has_errors="false"
|
||||
if grep -q "error\|Error\|ERROR" "$output_file"; then
|
||||
|
||||
# Two-stage error detection to avoid JSON field false positives
|
||||
# Stage 1: Filter out JSON field patterns like "is_error": false
|
||||
# Stage 2: Look for actual error messages in specific contexts
|
||||
# Avoid type annotations like "error: Error" by requiring lowercase after ": error"
|
||||
if grep -v '"[^"]*error[^"]*":' "$output_file" 2>/dev/null | \
|
||||
grep -qE '(^Error:|^ERROR:|^error:|\]: error|Link: error|Error occurred|failed with error|[Ee]xception|Fatal|FATAL)'; then
|
||||
has_errors="true"
|
||||
|
||||
# Debug logging: show what triggered error detection
|
||||
if [[ "$VERBOSE_PROGRESS" == "true" ]]; then
|
||||
log_status "DEBUG" "Error patterns found:"
|
||||
grep -v '"[^"]*error[^"]*":' "$output_file" 2>/dev/null | \
|
||||
grep -nE '(^Error:|^ERROR:|^error:|\]: error|Link: error|Error occurred|failed with error|[Ee]xception|Fatal|FATAL)' | \
|
||||
head -3 | while IFS= read -r line; do
|
||||
log_status "DEBUG" " $line"
|
||||
done
|
||||
fi
|
||||
|
||||
log_status "WARN" "Errors detected in output, check: $output_file"
|
||||
fi
|
||||
local output_length=$(wc -c < "$output_file" 2>/dev/null || echo 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue