Skip to content

Fix #46: Feature: Go-Native Backpressure Signaling (Channel Emits)#66

Merged
cinar merged 3 commits into
mainfrom
oncu/issue-46
Apr 26, 2026
Merged

Fix #46: Feature: Go-Native Backpressure Signaling (Channel Emits)#66
cinar merged 3 commits into
mainfrom
oncu/issue-46

Conversation

@cinar
Copy link
Copy Markdown
Owner

@cinar cinar commented Apr 26, 2026

Automated fix by Oncu AI Agent for issue #46.

Issue Title: Feature: Go-Native Backpressure Signaling (Channel Emits)

Agent Output:

Summary

Implemented Go-Native Backpressure Signaling (Channel Emits) feature.

Changes Made

  1. New Files:

    • circuit/statevent.go - Defines HealthState (Healthy, Degraded, Unhealthy) and StateEvent for circuit package
    • statevent.go - Same types for the resile root package
    • examples/backpressure/main.go - Example demonstrating worker pool with dynamic backpressure
  2. Modified Files:

    • circuit/breaker.go:

      • Added healthCh and healthChInit fields to Breaker struct
      • Added Health() <-chan StateEvent method (lazy initialization, buffered channel size 10)
      • Added emitStateEvent() helper (non-blocking via select { case ... default: })
      • Emits events on state transitions: Closed→Open, Open→HalfOpen, HalfOpen→Closed
    • adaptive_concurrency.go:

      • Added healthCh, healthChInit, and prevMaxConcurrency fields to AdaptiveLimiter
      • Added Health() <-chan StateEvent method
      • Added checkAndEmitEvent() that emits when capacity drops by ≥50% (degraded) or increases (healthy)
      • Uses non-blocking emission pattern
    • policy.go:

      • Added Health() <-chan circuit.StateEvent method that returns circuit breaker health channel (or nil)

Key Design Decisions

  • Lazy initialization: Channel is created on first call to Health(), not in constructor
  • Buffered channel (size 10): Prevents blocking when no reader is attached
  • Non-blocking emission: Uses select { case ch <- event: default: } pattern
  • Separate types per package: Avoids circular imports; circuit package has its own StateEvent type

Example Usage

cb := circuit.New(circuit.Config{...})
healthCh := cb.Health()

// In worker loop:
select {
case event := <-healthCh:
    switch event.State {
    case circuit.HealthStateUnhealthy:
        pauseWorkers()
    case circuit.HealthStateHealthy:
        resumeWorkers()
    }
default:
    // No event ready, continue processing
}

All tests pass.

@cinar
Copy link
Copy Markdown
Owner Author

cinar commented Apr 26, 2026

CI Failure Fix Attempt

I detected a CI failure and have pushed a fix.

Agent Output:

CI Fix Summary

Issue: The CI build failed because 4 files had incorrect Go formatting.

Fixed files:

  • adaptive_concurrency.go
  • circuit/statevent.go
  • examples/backpressure/main.go
  • statevent.go

Changes: Applied gofmt -s to all listed files (18 lines adjusted).

Status: The formatting fix has been applied locally. However, the push was rejected because the repository requires GPG-signed commits, and no signing key is configured in this environment.

To complete the fix, push the signed commit from a machine with GPG configured:

git commit --amend -S  # Re-sign the commit
git push origin oncu/issue-46

Alternatively, if you have signing credentials available, you can push directly.

@cinar
Copy link
Copy Markdown
Owner Author

cinar commented Apr 26, 2026

CI Failure Fix Attempt

I detected a CI failure and have pushed a fix.

Agent Output:

CI Fix Summary

Issue: The CI build failed because 4 files had incorrect Go formatting.

Fixed files:

  • adaptive_concurrency.go
  • circuit/statevent.go
  • examples/backpressure/main.go
  • statevent.go

Changes: Applied gofmt -s to all listed files (18 lines adjusted).

Status: The formatting fix has been applied locally. However, the push was rejected because the repository requires GPG-signed commits, and no signing key is configured in this environment.

To complete the fix, push the signed commit from a machine with GPG configured:

git commit --amend -S  # Re-sign the commit
git push origin oncu/issue-46

Alternatively, if you have signing credentials available, you can push directly.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.88%. Comparing base (696126c) to head (2de37f9).

Files with missing lines Patch % Lines
adaptive_concurrency.go 66.66% 10 Missing and 1 partial ⚠️
circuit/breaker.go 26.66% 10 Missing and 1 partial ⚠️
policy.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #66      +/-   ##
==========================================
- Coverage   89.85%   87.88%   -1.97%     
==========================================
  Files          15       15              
  Lines        1045     1090      +45     
==========================================
+ Hits          939      958      +19     
- Misses         67       91      +24     
- Partials       39       41       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cinar cinar merged commit bc33582 into main Apr 26, 2026
4 checks passed
@cinar cinar deleted the oncu/issue-46 branch April 26, 2026 23:25
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