Skip to content

fix: harden container cache handling - #499

Merged
NabDevs merged 3 commits into
mainfrom
fix/robust-version-and-cache
Jul 9, 2026
Merged

fix: harden container cache handling#499
NabDevs merged 3 commits into
mainfrom
fix/robust-version-and-cache

Conversation

@NabDevs

@NabDevs NabDevs commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This addresses failures seen after the WooCommerce 6.6.0 release where stale container/cache state or symlinked webroots with open_basedir restrictions could cause fatal errors.

  • Resolve PDK root/config paths via realpath() with fallbacks
  • Prevent pdkVersion lookup from failing the application when composer.json cannot be read
  • Key compiled container/APCu definition caches by app version
  • Clear all compiled container cache files recursively, including OPcache invalidation

Trade-offs

  • Old APCu cache entries are not actively removed. They expire/evict by themselves.
  • On upgrade, the container may be compiled one extra time. I kept this simple for the hotfix.
  • The cache key now uses the app version. If needed, we can also add a path hash to make it unique per install.
  • I did not change the compiled container class name. That was already shared before this PR and feels out of scope here.

INT-1709

@NabDevs
NabDevs requested a review from a team as a code owner July 8, 2026 12:17
Copilot AI review requested due to automatic review settings July 8, 2026 12:17
@github-project-automation github-project-automation Bot moved this to Todo in PDK Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Hardens PDK container caching and path/version handling to avoid fatal errors in environments with stale caches, symlinked webroots, or restrictive open_basedir settings (as observed after WooCommerce 6.6.0).

Changes:

  • Key compiled container and definition caches by an application/version-specific cache directory and cache key.
  • Make pdkVersion resilient to missing/unreadable composer.json and resolve root/config paths via realpath() with fallbacks.
  • Clear compiled container cache files recursively (including nested version directories) and invalidate OPcache entries for deleted PHP files.

Reviewed changes

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

Show a summary per file
File Description
tests/Unit/Facade/PdkTest.php Updates/extends unit tests to cover versioned cache directories, recursive clearing, and pdkVersion fallback.
tests/Hook/ClearContainerCacheHook.php Ensures test runs start with a clean cache by recursively deleting .cache contents.
src/Base/PdkBootstrapper.php Passes the app/plugin version into PdkFactory to version cache keys/paths.
src/Base/Pdk.php Reworks cache clearing to recursively delete compiled container/proxy caches and invalidate OPcache.
src/Base/Factory/PdkFactory.php Introduces cache versioning to isolate compilation/proxy output and definition cache keys per version.
config/pdk-dependencies.php Makes pdkVersion non-fatal by returning 'unknown' when composer.json can’t be read.
config/pdk-default.php Resolves rootDir/configDirs via realpath() (with fallbacks) to avoid symlink-based paths in compiled artifacts.

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

Comment thread src/Base/Factory/PdkFactory.php
Comment thread config/pdk-dependencies.php
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.22642% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.25%. Comparing base (9d44cd2) to head (b8bbe44).

Files with missing lines Patch % Lines
src/Base/Factory/PdkFactory.php 96.42% 1 Missing ⚠️
src/Base/Pdk.php 95.83% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #499      +/-   ##
============================================
+ Coverage     94.22%   94.25%   +0.02%     
- Complexity     2332     2350      +18     
============================================
  Files           350      350              
  Lines          7499     7538      +39     
============================================
+ Hits           7066     7105      +39     
  Misses          433      433              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread config/pdk-dependencies.php
Comment thread src/Base/Factory/PdkFactory.php
Comment thread src/Base/Factory/PdkFactory.php
Comment thread src/Base/Pdk.php
@github-project-automation github-project-automation Bot moved this from Todo to Needs work in PDK Jul 8, 2026
@myparcel-bot myparcel-bot Bot added the changes requested (Auto) label Jul 8, 2026
Comment thread src/Base/Factory/PdkFactory.php
@myparcel-bot myparcel-bot Bot removed the changes requested (Auto) label Jul 8, 2026
@myparcel-bot
myparcel-bot Bot force-pushed the fix/robust-version-and-cache branch from fb14944 to 0d907a1 Compare July 8, 2026 16:39
@github-project-automation github-project-automation Bot moved this from Needs work to Testing in PDK Jul 9, 2026
@myparcel-bot myparcel-bot Bot added the approved (Auto) label Jul 9, 2026
@myparcel-bot
myparcel-bot Bot force-pushed the fix/robust-version-and-cache branch 2 times, most recently from d3f0681 to 0306f68 Compare July 9, 2026 08:18
@myparcel-bot
myparcel-bot Bot force-pushed the fix/robust-version-and-cache branch from 0306f68 to b8bbe44 Compare July 9, 2026 08:30
@NabDevs
NabDevs added this pull request to the merge queue Jul 9, 2026
Merged via the queue into main with commit ae17c4e Jul 9, 2026
15 checks passed
@NabDevs
NabDevs deleted the fix/robust-version-and-cache branch July 9, 2026 13:26
@github-project-automation github-project-automation Bot moved this from Testing to Done in PDK Jul 9, 2026
myparcel-bot Bot added a commit that referenced this pull request Jul 9, 2026
## [4.2.1](v4.2.0...v4.2.1) (2026-07-09)

### 🐛 Bug Fixes

* harden container cache handling ([#499](#499)) ([ae17c4e](ae17c4e))
* update sdk beta test expectations ([#503](#503)) ([ae28336](ae28336))
@myparcel-bot

myparcel-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 4.2.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@myparcel-bot myparcel-bot Bot added the released label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants