optimize(detection-analysis-report): ~45 AIC/run savings via prompt compaction and script extraction#45820
Merged
pelikhan merged 3 commits intoJul 15, 2026
Conversation
- Simplify Step 1: remove redundant inline MCP tool documentation block - Merge Steps 2-4 into single 'Analyze Runs' section to reduce context duplication - Extract chart generation to .github/scripts/detection_comparison.py; replace Step 5 with direct bash invocation - Add sub-agent 'update-detection-trending' (model: small) for Step 6 historical trending - Recompile lock file Closes #45770 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
… side-effect) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add optimization for AIC savings in detection analysis report
optimize(detection-analysis-report): ~45 AIC/run savings via prompt compaction and script extraction
Jul 15, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes the detection-analysis workflow by reducing prompt overhead and extracting deterministic chart generation.
Changes:
- Compacts run-analysis instructions.
- Adds a reusable Python comparison-chart script.
- Delegates historical trending to a small-model sub-agent.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/detection-analysis-report.md |
Streamlines analysis and delegates trending. |
.github/workflows/detection-analysis-report.lock.yml |
Updates generated workflow metadata. |
.github/scripts/detection_comparison.py |
Generates the comparison chart. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 5
- Review effort level: Medium
| ### Step 1 — Fetch Logs | ||
|
|
||
| Use the `agentic-workflows` MCP `logs` tool to download workflow runs from the last 24 hours: | ||
| Call `agenticworkflows logs --start-date -1d` to download workflow run directories to `/tmp/gh-aw/aw-mcp/logs`. Each run's `aw_info.json` contains `features["gh-aw-detection"]` (boolean), `status`, `total_tokens`, and `engine_id`. Use `features.gh-aw-detection` directly — do not infer detection status from `.lock.yml` files. |
|
|
||
| Flag a workflow as **misconfigured** when any of the following apply: | ||
| **Flag a workflow as misconfigured** when any of the following apply: | ||
| 1. `gh-aw-detection: false` on a workflow with >3 total runs in the last 7 days |
Comment on lines
+38
to
+39
| regular_success = regular_runs - regular_failure | ||
| detection_success = detection_runs - detection_failure |
Comment on lines
+30
to
+33
| regular_runs = int(m.get("regular_runs", 0)) | ||
| detection_runs = int(m.get("detection_runs", 0)) | ||
| regular_success_rate = float(m.get("regular_success_rate", 0.0)) | ||
| detection_success_rate = float(m.get("detection_success_rate", 0.0)) |
| {"timestamp": "<ISO-8601 UTC>", "regular_runs": N, "detection_runs": N, "regular_success_rate": X.X, "detection_success_rate": X.X, "regular_avg_tokens": X, "detection_avg_tokens": X, "misconfigured_count": N} | ||
| ``` | ||
|
|
||
| If the history file has ≥7 entries, generate a 30-day trend chart at `/tmp/gh-aw/python/charts/detection_trend.png`: |
This was referenced Jul 15, 2026
Contributor
|
🎉 This pull request is included in a new release. Release: |
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.
The
detection-analysis-reportworkflow spent ~164 AIC/run with high output tokens (17,784) from runtime code generation and redundant prompt context. This implements four optimizer recommendations to cut ~45 AIC/run.Changes
.github/scripts/detection_comparison.py(new)Committed chart generation script that was previously written from scratch by the agent on every run (~100 lines of Matplotlib/Seaborn). Accepts
--metricsand--outputargs; reads pre-computedmetrics.json, emits a grouped bar + success-rate line overlay chart at 150 DPI.Step 5 reduced from a code-generation instruction to:
detection-analysis-report.md### Analyze Runs: Merged three separately-headed sections (Classify, Misconfigured, Metrics) into one pass with a single field list and one output JSON schema — eliminates field re-enumeration across section boundaries (~80 tokens, ~5–8 AIC)model: smallsub-agent (update-detection-trending); small models cost 10–20× less than the parent claude-opus modelSkipped
shared/otlp.md): Import is transitive throughdaily-audit-base.mdand provides active OTLP endpoint config — removing it would silently drop telemetrytrending-charts-simplecache hint): Requires compiler-level directive not yet supported in gh-aw