From fa63857f5fd016bcb0ee19037bc800e6c111f6b5 Mon Sep 17 00:00:00 2001 From: magdev Date: Mon, 2 Feb 2026 20:25:46 +0100 Subject: [PATCH] docs: Update CLAUDE.md with v0.4.1 session history Co-Authored-By: Claude Opus 4.5 --- CLAUDE.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index 1b453b9..f6c518f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -291,6 +291,32 @@ add_action( 'wp_prometheus_collect_metrics', function( $collector ) { ## Session History +### 2026-02-02 - Plugin Compatibility Fix (v0.4.1) + +- Fixed memory exhaustion (1GB limit) when wp-fedistream (Twig-based) plugin is active +- Root cause: Infinite recursion through WordPress hook system when content filters trigger Twig rendering +- Solution: Early metrics endpoint interception before full WordPress initialization +- Implementation changes: + - Added `wp_prometheus_early_metrics_check()` in bootstrap file (wp-prometheus.php) + - Checks REQUEST_URI for `/metrics` pattern before `plugins_loaded` fires + - Defines `WP_PROMETHEUS_EARLY_METRICS` constant to signal early mode + - Removes content filters (`the_content`, `the_excerpt`, `get_the_excerpt`, `the_title`) + - Collector skips `wp_prometheus_collect_metrics` action in early mode + - Changed MetricsEndpoint from `template_redirect` to `parse_request` hook +- **Key Learning**: WordPress plugin loading order and hook timing + - Plugins load alphabetically, so wp-fedistream ('f') loads before wp-prometheus ('p') + - `template_redirect` fires too late - after themes and Twig initialize + - `parse_request` fires earlier but still after plugin files load + - Earliest interception point: top-level code in plugin bootstrap file +- **Key Learning**: Content filter recursion in WordPress + - `get_the_excerpt()` internally triggers `apply_filters('the_content', ...)` + - This creates unexpected recursion vectors when Twig templates process content + - Solution: Remove all content-related filters before metrics collection +- **Key Learning**: Isolating metrics collection from WordPress template system + - Use `remove_all_filters()` to clear problematic filter chains + - Skip extensibility hooks (`do_action`) when in isolated early mode + - Exit immediately after output to prevent further WordPress processing + ### 2026-02-02 - Persistent Storage (v0.4.0) - Added persistent storage support for metrics: