Skip to content

Add Retry-After header during brownout windows - #9

Merged
rflavien merged 4 commits into
mainfrom
feature/retry-after-header
Mar 13, 2026
Merged

rflavien merged 4 commits into
mainfrom
feature/retry-after-header

Conversation

@rflavien

Copy link
Copy Markdown
Contributor

Summary

  • Add getBrownoutWindowEnd() method to BrownoutChecker returning the window end time
  • Refactor isInBrownoutWindow() to delegate to getBrownoutWindowEnd()
  • Add Retry-After header (RFC 7231 §7.1.3) to 410 responses during brownouts
  • Clients can now automatically retry after the brownout window ends

Test plan

  • getBrownoutWindowEnd returns correct DateTimeImmutable when in window
  • getBrownoutWindowEnd returns null when outside window
  • Retry-After header present in brownout 410 responses
  • Retry-After value is correct (seconds until window end)
  • Existing tests pass (58 tests, 2379 assertions)
  • PHPStan passes at max level

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 13, 2026 11:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds brownout window end-time introspection and uses it to attach an RFC 7231 Retry-After header to brownout-triggered 410 responses, enabling clients to retry automatically when the brownout ends.

Changes:

  • Introduces BrownoutChecker::getBrownoutWindowEnd() and refactors isInBrownoutWindow() to delegate to it.
  • Updates DeprecationHeaderListener to add a Retry-After header on brownout 410s based on the remaining window duration.
  • Adds/updates PHPUnit coverage for the new window-end API and Retry-After behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Brownout/BrownoutChecker.php Adds getBrownoutWindowEnd() and refactors isInBrownoutWindow() to use it.
src/EventListener/DeprecationHeaderListener.php Computes and sets Retry-After on brownout 410 responses.
tests/Brownout/BrownoutCheckerTest.php Adds tests for getBrownoutWindowEnd() behavior.
tests/EventListener/DeprecationHeaderListenerTest.php Adds tests asserting Retry-After presence/value in brownout 410s.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/Brownout/BrownoutChecker.php Resolved
Comment thread tests/Brownout/BrownoutCheckerTest.php Resolved
Refactor BrownoutChecker to expose getBrownoutWindowEnd() returning the
window end time, and use it in DeprecationHeaderListener to include a
Retry-After header (RFC 7231 §7.1.3) in 410 responses during brownouts.
This lets clients know when to retry after a brownout window closes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rflavien
rflavien force-pushed the feature/retry-after-header branch from af14d3b to ea820ea Compare March 13, 2026 13:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the brownout mechanism by exposing the current brownout window end time and using it to emit an RFC-compliant Retry-After header on 410 responses during brownouts, enabling clients to retry automatically when the window ends.

Changes:

  • Add BrownoutChecker::getBrownoutWindowEnd() and refactor isInBrownoutWindow() to delegate to it.
  • Add Retry-After (delta-seconds) header to brownout-triggered 410 Gone responses in DeprecationHeaderListener.
  • Extend test coverage for both the new window-end API and the new response header behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Brownout/BrownoutChecker.php Adds getBrownoutWindowEnd() and refactors brownout-window detection to reuse it.
src/EventListener/DeprecationHeaderListener.php Computes Retry-After during brownouts and adds optional clock injection for deterministic time.
src/ApiDeprecationBundle.php Wires the optional clock service into DeprecationHeaderListener.
tests/Brownout/BrownoutCheckerTest.php Adds unit tests for getBrownoutWindowEnd() behavior and edge cases.
tests/EventListener/DeprecationHeaderListenerTest.php Adds tests validating presence and correctness of the Retry-After header.
Comments suppressed due to low confidence (1)

src/Brownout/BrownoutChecker.php:30

  • Exception message has a trailing period ("Unknown brownout strategy "%s".") but tests assert the message without the period (e.g., BrownoutCheckerTest expects Unknown brownout strategy "nonexistent"). This will cause test failures and is a breaking change for callers relying on the message; consider removing the trailing period (or update all affected tests/messages consistently).
        if (!isset($this->namedStrategies[$strategyName])) {
            throw new \InvalidArgumentException(\sprintf('Unknown brownout strategy "%s".', $strategyName));
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@rflavien
rflavien merged commit 87cc437 into main Mar 13, 2026
12 checks passed
@rflavien
rflavien deleted the feature/retry-after-header branch March 13, 2026 14:59
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