Repository navigation
fix(core): scope CacheInvalidator lifetime and clear rolled-back pending entries - #2603
Merged
glennjacobs merged 3 commits intoAug 25, 2026
Merged
Conversation
Contributor
Author
|
Hi @glennjacobs @alecritson — noticed this PR doesn't have a reviewer assigned yet — it's been about 6 days, CI is green and it's mergeable. Would you (or whoever's best placed) be able to take a look when you get a chance, or point me to who should? Thanks! |
Contributor
|
@wakqasahmed on holiday at the moment. Will be hitting all the PRs on my return at the end of next week. |
Contributor
Author
|
Sounds good, thanks — no rush, I'll wait for your review whenever you're back. |
The recorder registered a permanent closure on the shared dispatcher per instance; under the scoped binding every request/job scope in a long-lived worker added another listener retaining its dead instance. The provider now wires a single process-lifetime listener that resolves the scoped recorder at dispatch time, and pruneRolledBack joins the contract. Co-Authored-By: Claude Fable 5 <[email protected]>
This was referenced Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2561
Summary
CacheInvalidatoris documented as request-scoped but was bound as asingleton, letting pending state outlive a request/job under Octane or long-lived workers. It's now bound with$app->scoped(...).Separately,
record()added targets to$pendingand registered anafterCommitcallback, but a rollback discarded the callback while leaving the$pendingentry in place. A later autocommit mutation, a later committed transaction, or a later transaction touching the same target could then flush an invalidation event for a change that was rolled back.The fix tracks the transaction level each pending entry was first (or most shallowly) touched at, and listens for
Illuminate\Database\Events\TransactionRolledBackper connection to drop only the entries whose shallowest touch happened inside the frame being discarded. An entry also touched by a surviving outer frame is kept (accepted over-invalidation, consistent with the class's existing reliability bias documented in its docblock).Changes
packages/core/src/LunarServiceProvider.php: bindCacheInvalidatorasscopedinstead ofsingleton.packages/core/src/Cache/CacheInvalidator.php: record the transaction level per pending entry and register a rollback listener that prunes entries whose frame was discarded.tests/core/Feature/CacheInvalidationTest.php: added regression coverage forTest plan
a root rollback does not leak into a later autocommit mutation(event dispatched 2 times instead of 1).tests/core/Feature/CacheInvalidationTest.phppass with the fix applied (ran viavendor/bin/pest, PHP 8.4, sqlite).