Skip to content

fix(framework): normalize plugin list cache ID generation#40499

Closed
lbajsarowicz wants to merge 1 commit intomagento:2.4-developfrom
lbajsarowicz:fix/40407-plugin-list-cache-id-mismatch
Closed

fix(framework): normalize plugin list cache ID generation#40499
lbajsarowicz wants to merge 1 commit intomagento:2.4-developfrom
lbajsarowicz:fix/40407-plugin-list-cache-id-mismatch

Conversation

@lbajsarowicz
Copy link
Copy Markdown
Contributor

Description

Sort scopes alphabetically before creating cache IDs in both PluginList and PluginListGenerator to ensure compile-time and runtime cache IDs match.

Root Cause:
The cache IDs generated at compile-time (PluginListGenerator::write()) didn't match runtime (PluginList::_loadScopedData()) because:

  • Runtime has "move to end" logic that reorders scopes based on processing order
  • Compile-time didn't have this logic
  • Result: primary|global vs global|primary depending on which scope loaded first

Solution:
Normalize cache IDs by sorting scopes alphabetically before creating the ID. This ensures cache IDs are deterministic regardless of processing order, allowing pre-compiled plugin metadata files (~600KB+) to be loaded correctly and eliminating 1-2 second delays on first request after cache:flush.

Related Pull Requests

None

Fixed Issues (if relevant)

  1. Fixes Plugin list metadata files generated by setup:di:compile are never used at runtime due to cache ID mismatch #40407

Manual testing scenarios

  1. Run bin/magento setup:di:compile and verify plugin-list files are generated in generated/metadata/
  2. Run bin/magento cache:flush
  3. Add debug logging to PluginList::_loadScopedData() before $configData = $this->configLoader->load($cacheId):
    file_put_contents(BP . '/var/debug.log', "cacheId=$cacheId\n", FILE_APPEND);
  4. Make a frontend request
  5. Check the cache IDs in the debug log match the filenames in generated/metadata/
  6. Verify pre-compiled metadata is loaded (no 1-2 second delay on first request)

Questions or comments

Unit tests pass: vendor/bin/phpunit lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

⭐ Support my work

Do you like the fix? Remember to react with "👍🏻" to get it merged faster,
Then Sponsor me on Github so I can spend more time on fixing issues like this one.

Learn more at https://github.com/sponsors/lbajsarowicz

@m2-assistant
Copy link
Copy Markdown

m2-assistant bot commented Feb 3, 2026

Hi @lbajsarowicz. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@ct-prd-pr-scan
Copy link
Copy Markdown

ct-prd-pr-scan bot commented Feb 3, 2026

The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com.

@lbajsarowicz
Copy link
Copy Markdown
Contributor Author

@magento run all tests

Sort scopes alphabetically before creating cache IDs to ensure
consistency between compile-time (PluginListGenerator) and runtime
(PluginList) generation. This allows pre-compiled plugin metadata
files to be loaded correctly, improving performance after cache:flush.

Fixes magento#40407
@lbajsarowicz lbajsarowicz force-pushed the fix/40407-plugin-list-cache-id-mismatch branch from 987fa1a to 27c9a74 Compare February 3, 2026 23:31
@lbajsarowicz
Copy link
Copy Markdown
Contributor Author

@magento run all tests

@hostep
Copy link
Copy Markdown
Contributor

hostep commented Feb 4, 2026

Doesn't this duplicate this fix: #40408 ?

@lbajsarowicz
Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #40408 by @jakwinkler, which addresses the same plugin list cache ID normalization issue with a similar sorting approach. Their PR was submitted first (Jan 2026).

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.

Plugin list metadata files generated by setup:di:compile are never used at runtime due to cache ID mismatch

2 participants