From c05499c1767ea4142613bbf434fcca763401d54e Mon Sep 17 00:00:00 2001 From: Test User Date: Mon, 2 Feb 2026 09:36:48 -0700 Subject: [PATCH] feat(circuit-breaker): allow configuring thresholds via environment variables Makes circuit breaker thresholds configurable via environment variables while maintaining backward compatibility with default values. Usage: CB_NO_PROGRESS_THRESHOLD=10 ralph --monitor CB_SAME_ERROR_THRESHOLD=8 CB_OUTPUT_DECLINE_THRESHOLD=80 ralph Configurable thresholds: - CB_NO_PROGRESS_THRESHOLD (default: 3) - CB_SAME_ERROR_THRESHOLD (default: 5) - CB_OUTPUT_DECLINE_THRESHOLD (default: 70) - CB_PERMISSION_DENIAL_THRESHOLD (default: 2) Fixes #99 Credit: @zerone0x (PR #111) --- lib/circuit_breaker.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/circuit_breaker.sh b/lib/circuit_breaker.sh index 3502ca8..810a17c 100644 --- a/lib/circuit_breaker.sh +++ b/lib/circuit_breaker.sh @@ -16,10 +16,12 @@ CB_STATE_OPEN="OPEN" # Failure detected, execution halted RALPH_DIR="${RALPH_DIR:-.ralph}" CB_STATE_FILE="$RALPH_DIR/.circuit_breaker_state" CB_HISTORY_FILE="$RALPH_DIR/.circuit_breaker_history" -CB_NO_PROGRESS_THRESHOLD=3 # Open circuit after N loops with no progress -CB_SAME_ERROR_THRESHOLD=5 # Open circuit after N loops with same error -CB_OUTPUT_DECLINE_THRESHOLD=70 # Open circuit if output declines by >70% -CB_PERMISSION_DENIAL_THRESHOLD=2 # Open circuit after N loops with permission denials (Issue #101) +# Configurable thresholds - override via environment variables: +# Example: CB_NO_PROGRESS_THRESHOLD=10 ralph --monitor +CB_NO_PROGRESS_THRESHOLD=${CB_NO_PROGRESS_THRESHOLD:-3} # Open circuit after N loops with no progress +CB_SAME_ERROR_THRESHOLD=${CB_SAME_ERROR_THRESHOLD:-5} # Open circuit after N loops with same error +CB_OUTPUT_DECLINE_THRESHOLD=${CB_OUTPUT_DECLINE_THRESHOLD:-70} # Open circuit if output declines by >70% +CB_PERMISSION_DENIAL_THRESHOLD=${CB_PERMISSION_DENIAL_THRESHOLD:-2} # Open circuit after N loops with permission denials (Issue #101) # Colors RED='\033[0;31m'