Skip to content

[agentic-token-optimizer] Optimize: PR Code Quality Reviewer — Reduce 30% failure rate and AIC variance #44070

Description

@github-actions

Target Workflow

PR Code Quality Reviewer (pr-code-quality-reviewer.md) — selected as the highest-AIC workflow (764.5 total AIC in 7 days, avg 191.1 AIC/run) not optimized in the last 14 days.

Analysis Period

  • 7-day window: 4 runs (in all-runs.json)
  • Broader history: 50 runs (last ~7 days via workflow run API)
  • Failure rate: 15 of 50 runs failed (30%) — all at the "Execute GitHub Copilot CLI" step

Cost Profile

Metric Value
Total AIC (7-day window) 764.5
Avg AIC / run 191.1
AIC range 124.6 – 237.9
Avg action minutes 19.25 min
Declared timeout 15 min
Avg GitHub API calls 9.5 / run
7-day failure rate 50% (2/4 runs in window)
Broader failure rate 30% (15/50 runs)

Note: total_turns and total_raw_tokens fields are not populated for Copilot-engine runs in the current audit data. Cost estimates are inferred from AIC and action-minute distributions.


Ranked Recommendations

1. Fix Timeout Misconfiguration (Reliability · est. −57 AIC/run)

Evidence: Every failure across all 50 runs fails identically at "Execute GitHub Copilot CLI". Failed runs average ~20 action-minutes but the timeout-minutes: 15 frontmatter should kill the job at 15 — yet failed runs show exactly 20 minutes, suggesting the declared timeout either is not applying or is firing after model calls already exhaust the budget. Successful runs also average 19.25 minutes, meaning even successful runs are cutting it close.

Action: Raise timeout-minutes from 15 to 25 in the workflow frontmatter. The current value is below actual runtime for large PRs and causes ~30% of runs to fail without producing any review output.

timeout-minutes: 25

Estimated savings: Eliminating 30% wasteful failed runs saves ~57 AIC/run (0.30 × 191 avg AIC).

References: §28873900484 · §28873560035 · §28849016081


2. Reduce PR Diff Cap from 3000 to 2000 Lines (Cost · est. −20–30 AIC/run)

Evidence: AIC ranges from 124.6 to 237.9/run (91% variance). The pre-agent step caps at PR_DIFF_MAX_LINES=3000, but large PRs send near-3000-line diffs to the model. Lines 2000–3000 of a diff rarely change review quality for correctness/security findings — the most critical issues appear in the first modified hunks.

Action: Reduce PR_DIFF_MAX_LINES to 2000. Optionally expose as a workflow input for callers with very large PRs.

PR_DIFF_MAX_LINES: "2000"

Estimated savings: 20–30 AIC/run for runs currently hitting the 3000-line cap.


3. Streamline Step 1 Multi-Action Turn (Prompt · est. −5–10 AIC/run)

Evidence: Step 1 packs four actions into "one parallel turn": read diff file, read metadata file, fetch get_review_comments, optionally read cache file, and launch grumpy-coder. This complexity risks partial execution (some actions skipped) and reduces prompt cache alignment since the instruction block is large.

Action: Split Step 1 into two explicit beats:

  • Beat A: Read diff + metadata + existing comments (parallel)
  • Beat B: Launch grumpy-coder sub-agent with the loaded context

This reduces first-turn ambiguity and avoids the model accidentally skipping the sub-agent start.

Estimated savings: 5–10 AIC/run from better turn clarity and cache alignment.


4. Move Optional Cache-Memory Read to Pre-Agent Step (Prompt · est. −3–5 AIC/run)

Evidence: Step 1 includes an optional agent-side read of /tmp/gh-aw/cache-memory/pr-{number}.json. This file is absent for most PRs, so the agent either makes a failed tool call or adds a conditional check. Both waste tokens.

Action: Move this read to the pre-agent-steps block with a file-existence guard:

[ -f /tmp/gh-aw/cache-memory/pr-${PR_NUMBER}.json ] && \
  cat /tmp/gh-aw/cache-memory/pr-${PR_NUMBER}.json \
  > /tmp/gh-aw/agent/pr-history.json || true

Then reference /tmp/gh-aw/agent/pr-history.json in the prompt if it exists.

Estimated savings: 3–5 AIC/run by eliminating a conditional tool call from the agent's first turn.


Caveats

  • total_turns and total_raw_tokens are null for Copilot-engine runs; savings estimates use AIC and action-minute data only.
  • 7-day window contains only 4 runs; broader failure pattern confirmed from 50 runs via workflow run API.
  • Timeout increase (rejig docs #1) may slightly raise AIC for runs that previously failed early; net effect is strongly positive since failed runs produce zero review output.
  • Diff cap reduction (Add workflow: githubnext/agentics/weekly-research #2) may reduce coverage on very large PRs — consider making PR_DIFF_MAX_LINES a configurable workflow input.
  • This workflow already uses grumpy-coder as an inline sub-agent on claude-haiku-4.5; no additional sub-agent candidates were identified.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Agentic Workflow AIC Usage Optimizer · 95.7 AIC · ⊞ 7K ·

  • expires on Jul 14, 2026, 7:56 AM UTC-08:00

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions