Skip to content

fix: Fall back when a decorated cache engine cannot increment - #63

Merged
dereuromark merged 1 commit into
dereuromark:masterfrom
tobse:fix/62-debugkit-increment
Sep 29, 2026
Merged

dereuromark merged 1 commit into
dereuromark:masterfrom
tobse:fix/62-debugkit-increment

Conversation

@tobse

@tobse tobse commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Closes #62.

With DebugKit loaded, Cache::pool() returns a DebugEngine decorator, so the instanceof FileEngine guard in VerifyRateLimiter::increment() does not match. The second counted failure then throws LogicException: Files cannot be atomically incremented.

This change catches the LogicException and uses the existing read/write fallback. The instanceof guard stays as the fast path for undecorated engines. The increment is called on the pool engine directly. Cache::increment() only declares InvalidArgumentException, so PHPStan flags a catch around it as dead, even though the engine underneath documents the LogicException.

Tests: a new testDecoratedFileCacheFallback wraps a FileEngine in a minimal test-app decorator shaped like DebugEngine, so the suite needs no DebugKit dependency. It fails with the LogicException on master and passes with the fix. Full suite: 70 tests, 305 assertions. PHPStan (via composer stan-setup) and PHPCS pass locally.

Also checked end to end in an app with DebugKit 5.2.4 and a File cache: invalid submissions are throttled again instead of crashing.

Not addressed here: the Undefined array key "prefix" warning from RateLimitRegistry::acquireLock() mentioned in #62. It comes from DebugEngine not proxying add() and is better fixed in DebugKit.

🤖 Generated with Claude Code

DebugKit wraps every configured cache in a DebugEngine, so the
instanceof FileEngine guard in VerifyRateLimiter::increment() does not
match and the second counted failure throws "Files cannot be atomically
incremented". Catch the LogicException and use the existing read/write
fallback.

The increment is called on the pool engine directly: Cache::increment()
only declares InvalidArgumentException, which hides the LogicException
the engine documents.

Closes dereuromark#62

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 3517a904-08cf-47e3-af08-8570472ab169


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tobse

tobse commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Update on the side note about the Undefined array key "prefix" warning: DebugKit already fixed this in cakephp/debug_kit#1084 (merged 2026-08-13). DebugEngine now proxies add() and has(). The fix is on 5.x but not in a release yet; the latest is 5.2.4. So nothing is needed on this side.

The increment() crash is unaffected by that change. DebugEngine::increment() still forwards to FileEngine, which throws, so #63 is still needed.

@dereuromark
dereuromark merged commit 62d52b6 into dereuromark:master Sep 29, 2026
9 checks passed
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.

Verify rate limiter throws LogicException with DebugKit and a File cache

2 participants