Skip to content

Bound BanManager registry lifetime with a TTL#45

Merged
sascha-egerer merged 1 commit into
mainfrom
chore/ban-registry-ttl
May 27, 2026
Merged

Bound BanManager registry lifetime with a TTL#45
sascha-egerer merged 1 commit into
mainfrom
chore/ban-registry-ttl

Conversation

@sascha-egerer
Copy link
Copy Markdown
Contributor

The per-rule audit registry was written without a TTL, so it accumulated entries across ban churn until something called listBans() or clearBans() pruned them. Each save now carries a TTL matching the longest-surviving entry and prunes already-expired entries before writing. Concurrent ban() calls for the same rule can still drop one of the registry entries, which is acceptable because the primary ban cache key set by ban() is the source of truth and is unaffected by the race.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 bounds the per-rule ban audit registry lifetime by applying a TTL to the registry cache entry and pruning expired entries on every save, preventing unbounded growth across ban churn.

Changes:

  • Add a BanManager unit test asserting the ban registry cache key expires alongside the bans it tracks.
  • Refactor BanManager::registerBan() to reuse loadRegistry() / saveRegistry() and update saveRegistry() to prune expired entries and set a TTL equal to the longest remaining ban lifetime.
  • Document the behavior change in CHANGELOG.md.

Reviewed changes

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

File Description
tests/Unit/BanManagerTest.php Adds a TTL-focused test for the ban registry cache entry.
src/BanManager.php Prunes expired registry entries on save and writes the registry with a TTL to prevent unbounded growth.
CHANGELOG.md Notes the registry TTL + pruning behavior under Unreleased.

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

Comment thread src/BanManager.php Outdated
Comment thread src/BanManager.php Outdated
Comment thread tests/Unit/BanManagerTest.php Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/BanManager.php
Comment thread tests/Unit/BanManagerTest.php
Comment thread tests/Unit/BanManagerTest.php
The per-rule audit registry was written without a TTL, so it accumulated
entries across ban churn until something called listBans() or
clearBans() pruned them. Each save now carries a TTL matching the
longest-surviving entry and prunes already-expired entries before
writing. Concurrent ban() calls for the same rule can still drop one of
the registry entries, which is acceptable because the primary ban cache
key set by ban() is the source of truth and is unaffected by the race.
@sascha-egerer sascha-egerer force-pushed the chore/ban-registry-ttl branch from 1b0fafc to 16cc670 Compare May 27, 2026 10:08
@sascha-egerer sascha-egerer merged commit e81a635 into main May 27, 2026
11 checks passed
@sascha-egerer sascha-egerer deleted the chore/ban-registry-ttl branch May 27, 2026 11:05
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