Include PHP error aggregated events in AI summary prompt#116
Open
MathieuLamiot wants to merge 3 commits into
Open
Include PHP error aggregated events in AI summary prompt#116MathieuLamiot wants to merge 3 commits into
MathieuLamiot wants to merge 3 commits into
Conversation
Extends AI_Summarizer::generate_summary() with an optional $aggregated_events parameter. When non-empty, build_prompt() appends a "PHP Errors" section listing up to 5 error signatures (level, message, occurrence count). Dashboard_Widget and Reports_Page AJAX handlers now fetch aggregated events via Aggregated_Event_Repository::get_rows_for_report() before calling the summarizer, using null for the active-period sentinel (report_id = 0) and the frozen report_id otherwise. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add prompt composition section to ai-transport.md explaining the four parameters of generate_summary() and the four-section prompt structure including the new PHP Errors section. Update report-lifecycle.md AI Summary flow to list the aggregated events fetch step and note the PHP Errors prompt section. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verifies that build_prompt() never emits more than 5 entries in the PHP Errors section even when more than 5 aggregated event rows are provided. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Description
Closes #59
PHP errors tracked by
Error_Trackerwere never visible to the AI summarizer — the prompt only included singular events. This change feeds aggregated PHP error rows into the prompt so AI-generated summaries can mention notable errors (type, count, frequency) alongside regular site activity.Type of change
Detailed scenario
What was tested
Scenario 1 — Active report with PHP errors (dashboard widget)
wp_sybgo_aggregated_eventswith twophp_errorrows (report_id = 0): onewarning(5 occurrences) and onefatal_error(1 occurrence).Logger::debug($prompt)and confirmed the prompt contained a "## PHP Errors" section listing both signatures with correct level, message snippet, and occurrence counts.Scenario 2 — Frozen report with PHP errors (reports page)
report_id.report_id.Scenario 3 — No PHP errors (backward compatibility)
wp_sybgo_aggregated_eventshad nophp_errorrows for the current period.How to test
wp_sybgo_aggregated_eventsrows forevent_type = 'php_error'and regenerate — verify no errors section appears and the rest of the summary is unchanged.Affected Features & Quality Assurance Scope
Dashboard_Widget::ajax_widget_ai_summary,Reports_Page::ajax_generate_ai_summary)AI_Summarizer::build_prompt)$aggregated_eventsparameter defaults to[]; callers that don't pass it produce identical prompts.Technical description
AI_Summarizer::generate_summary()gains an optional 4th parameter$aggregated_events(default[]). When non-empty,build_prompt()appends a PHP Errors section listing up to 5 rows — the top-5 by occurrence count, which arrive pre-sorted fromAggregated_Event_Repository::get_rows_for_report().Each row's
dimensionsJSON supplies the errorlevel(e.g.warning,fatal_error) and themetaJSON supplies themessagesnippet and occurrencetotal.Both AJAX call sites now fetch aggregated events before calling the summarizer:
nullfor the active period — targets thereport_id = 0sentinel rows (unassigned current period).$report_id(int) for frozen reports.See
lib/docs/ai-transport.md(new "AI_Summarizer Prompt Composition" section) andlib/docs/report-lifecycle.md(updated AI Summary On-Demand flow).New dependencies
None.
Risks
None identified. The parameter is optional and defaults to
[], so any existing call site that is not updated continues to produce the same prompt without errors.Mandatory Checklist
Code validation
Code style
Unticked items justification
N/A
Additional Checks
Unticked items justification
Logger::erroralready provides on transport failure.