diff --git a/CLAUDE.md b/CLAUDE.md index 5f474e6..bda25f1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -552,3 +552,58 @@ wp-fedistream/ - Uses Gitea API directly for release creation (not GitHub Actions) - Submodule uses relative URL for CI compatibility - Composer symlinks from `lib/wc-licensed-product-client` to vendor + +### 2026-02-02 - Memory Leak Investigation v0.4.1 through v0.4.9 + +**Summary:** Investigated memory exhaustion issue when WP FediStream is used with WP Prometheus plugin. Multiple fix attempts were made but the root cause remains unresolved. + +**Problem:** + +- PHP Fatal error: Allowed memory size exhausted (1GB) +- Error locations varied: Twig StagingExtension.php, Environment.php, ExtensionSet.php, WordPress class-wp-hook.php +- Only occurs when WP Prometheus plugin is also active +- Suspected infinite recursion through WordPress hook system + +**Fix Attempts (v0.4.1 - v0.4.8):** + +1. **v0.4.1** - Added recursion depth tracking in `get_post_data()`, skip `the_content` filter at depth > 1 +2. **v0.4.2** - Added `$in_shortcode_context` flag, all shortcode render methods enter context before data loading +3. **v0.4.3** - Changed boolean to counter (`$shortcode_context_depth`), added context to `template-wrapper.php` +4. **v0.4.4** - Fixed `get_the_excerpt()` which internally triggers `the_content` filter +5. **v0.4.5** - Added render depth tracking in `Plugin::render()`, strip shortcodes from content +6. **v0.4.6** - Added `$loading_page_template` flag to block shortcode rendering during page template loading +7. **v0.4.7** - Added `$rendering_main_template` hard lock in `Plugin::render()`, reduced MAX_RENDER_DEPTH to 2 +8. **v0.4.8** - Nuclear option: ALWAYS skip `the_content` filter (didn't work, reverted) + +**v0.4.9 - Current State:** + +- Reverted nuclear option +- Kept all other protections in place +- Issue documented in README.md as known incompatibility + +**Files Modified:** + +- `includes/Frontend/TemplateLoader.php` - Multiple recursion protection mechanisms +- `includes/Frontend/Shortcodes.php` - Shortcode context entry, page template loading check +- `includes/Frontend/template-wrapper.php` - Page template loading flag, main template render flag +- `includes/Plugin.php` - Render depth tracking, main template rendering lock +- `README.md` - Added Known Issues section + +**Protection Mechanisms in Place:** + +1. `$recursion_depth` counter in `get_post_data()` (max 3) +2. `$shortcode_context_depth` counter for nested shortcodes +3. `$loading_page_template` flag blocks shortcode rendering during page load +4. `$rendering_main_template` flag in `Plugin::render()` blocks parallel renders +5. `MAX_RENDER_DEPTH = 2` in `Plugin::render()` +6. Skip `the_content` and `get_the_excerpt()` when in protected context +7. Strip shortcodes from content when skipping content filter + +**Key Learnings:** + +- `get_the_excerpt()` internally calls `apply_filters('the_content', ...)` when generating auto-excerpts +- `the_content` filter triggers `do_shortcode()` which can cause recursive shortcode processing +- WordPress hook system (class-wp-hook.php) can itself be the recursion point +- The interaction between FediStream and WP Prometheus appears to be at a fundamental WordPress level + +**Status:** UNRESOLVED - Documented as known incompatibility, investigation to continue later