Skip to content

Add dead zone ratio to PID controller for noise suppression#1032

Merged
AbdulRahmanAlHamali merged 4 commits intopid-take-2from
abdullah/rejection-mechanism-fix
Feb 27, 2026
Merged

Add dead zone ratio to PID controller for noise suppression#1032
AbdulRahmanAlHamali merged 4 commits intopid-take-2from
abdullah/rejection-mechanism-fix

Conversation

@Abuudiii
Copy link
Contributor

@Abuudiii Abuudiii commented Feb 20, 2026

closes https://github.com/Shopify/resiliency/issues/6664

Summary

  • Adds a configurable dead zone to the PID controller that suppresses reactions to small, noisy error rate fluctuations around the ideal error rate
  • Error rates within ideal_error_rate * dead_zone_ratio of the ideal are treated as zero deviation, preventing unnecessary rejection rate increases
  • Negative deltas (recovery) pass through the dead zone unimpeded, so the dead zone never slows down recovery

How it works

The dead zone defines a band around the ideal error rate where the controller ignores noise:

  • Below ideal: negative delta passes through for fast recovery
  • Within dead zone (0 < delta <= ideal * ratio): delta suppressed to 0
  • Above dead zone (delta > ideal * ratio): controller reacts to the excess (delta - dead_zone)

Example: with initial_error_rate: 0.05 and dead_zone_ratio: 0.25, error rates up to 6.25% won't trigger rejection.

Files changed

  • lib/semian/pid_controller.rb — dead zone logic in calculate_p_value
  • lib/semian/adaptive_circuit_breaker.rb — passes dead_zone_ratio to PID controller
  • lib/semian.rb — wires dead_zone_ratio: 0.25 default in factory method
  • test/pid_controller_test.rb — tests for suppression, reaction above threshold, and unimpeded recovery

- Introduced `dead_zone_ratio` parameter in the PID controller to suppress noise from small deviations in error rates.
- Updated the `calculate_p_value` method to implement dead zone logic, allowing for more stable control responses.
- Enhanced tests to validate the behavior of the dead zone in various scenarios, ensuring it does not impede recovery while effectively filtering noise.
delta_error = 0.0
else
# Above dead zone: react to excess only
delta_error = raw_delta - dead_zone
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the delta_error here should be raw_delta - dead_zone. So that the dead zone does not actually affect calculations: it only silences them when we are within the dead zone, but otherwise everything stays the same

- Updated the handling of the dead zone in the PID controller to allow full signal response above the dead zone, improving control accuracy.
- Adjusted comments for clarity regarding the purpose of the dead zone in noise suppression.
@Abuudiii Abuudiii self-assigned this Feb 27, 2026
@AbdulRahmanAlHamali AbdulRahmanAlHamali merged commit c9eef57 into pid-take-2 Feb 27, 2026
35 checks passed
@AbdulRahmanAlHamali AbdulRahmanAlHamali deleted the abdullah/rejection-mechanism-fix branch February 27, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants