Skip to content

⚡ Copilot Token Optimization2026-05-27 — Build Test Suite #3933

@github-actions

Description

@github-actions

Target Workflow: build-test

Source report: #3931
Estimated cost per run: N/A (cost tracking pending; using effective tokens as proxy)
Total tokens per run: ~662K avg (range: 335K–1,514K)
Effective tokens per run: ~6,653K avg
LLM turns: ~20 avg (range: 8–59)
Runs in period: 6 (over ~5.8 hours)

⚠️ One run (#1965) consumed 1,514K tokens across 59 turns — 2.3× the average. This outlier is likely a retry/recovery loop and suggests missing turn guardrails.


Current Configuration

Setting Value
Tools loaded bash, github
GitHub toolsets context, repos, issues, pull_requests (already restricted ✅)
Network groups 12 groups: defaults, github, node, go, rust, crates.io, java, dotnet, bun.sh, deno.land, jsr.io, dl.deno.land
Pre-agent steps ❌ None
Post-agent steps ❌ None
Prompt size ~8,774 chars (~2,200 tokens)
Max turns Not configured
Tasks 8 ecosystems tested sequentially (Bun, C++, Deno, .NET, Go, Java, Node.js, Rust)
Repositories cloned by agent 8 (one per ecosystem)

Root Cause Analysis

The high turn count stems from the agent performing sequential, multi-step setup work for each of 8 ecosystems:

  1. Cloning 8 repositories (1 bash call each = ~8 "setup" turns)
  2. Creating Maven ~/.m2/settings.xml (1 extra turn)
  3. Running build/test commands per project (~12+ turns for actual work)

Every turn carries the full 2,200-token prompt in context, plus the growing conversation history. At 20 turns avg, this means the prompt alone contributes ~44,000 tokens per run just in repeated context. The 59-turn outlier amplifies this to ~130K tokens from prompt repetition alone.


Recommendations

1. Move repo clones to pre-agent steps:

Estimated savings: ~200–350K tokens/run (~30–50%)

The agent clones 8 GitHub repositories at the start of every run. These are deterministic, require no agent reasoning, and are already handled by the actions/checkout infrastructure. Moving them to steps: eliminates ~8 agent turns and shrinks the context window proportionally.

Add to the frontmatter steps: section in .github/workflows/build-test.md:

steps:
  - name: Clone test repositories
    run: |
      git clone --depth=1 https://github.com/Mossaka/gh-aw-firewall-test-bun.git /tmp/test-bun
      git clone --depth=1 https://github.com/Mossaka/gh-aw-firewall-test-cpp.git /tmp/test-cpp
      git clone --depth=1 https://github.com/Mossaka/gh-aw-firewall-test-deno.git /tmp/test-deno
      git clone --depth=1 https://github.com/Mossaka/gh-aw-firewall-test-dotnet.git /tmp/test-dotnet
      git clone --depth=1 https://github.com/Mossaka/gh-aw-firewall-test-go.git /tmp/test-go
      git clone --depth=1 https://github.com/Mossaka/gh-aw-firewall-test-java.git /tmp/test-java
      git clone --depth=1 https://github.com/Mossaka/gh-aw-firewall-test-node.git /tmp/test-node
      git clone --depth=1 https://github.com/Mossaka/gh-aw-firewall-test-rust.git /tmp/test-rust

Then remove the "Clone Repository" instructions from each task section in the prompt, replacing the clone step with:

Repository is pre-cloned to /tmp/test-<ecosystem>

Why this works: Each eliminated turn removes one full round-trip from the context window. At ~33K tokens/turn average, removing 8 clone turns saves ~264K tokens/run.


2. Move Maven proxy setup to pre-agent steps:

Estimated savings: ~33K tokens/run (~5%)

The Maven ~/.m2/settings.xml creation is deterministic and documented with a large code block in the prompt (29 lines of XML). Moving it to a pre-step eliminates 1 agent turn and reduces prompt complexity.

Add to steps::

  - name: Configure Maven proxy for AWF
    run: |
      mkdir -p ~/.m2
      cat > ~/.m2/settings.xml << 'SETTINGS'
      <settings>
        <proxies>
          <proxy>
            <id>awf-http</id><active>true</active><protocol>http</protocol>
            <host>squid-proxy</host><port>3128</port>
          </proxy>
          <proxy>
            <id>awf-https</id><active>true</active><protocol>https</protocol>
            <host>squid-proxy</host><port>3128</port>
          </proxy>
        </proxies>
      </settings>
      SETTINGS

Remove the "Configure Maven Proxy" section from the Java task in the prompt.


3. Add a max-turns limit to cap worst-case costs

Estimated savings: ~850K tokens on outlier runs (~56% reduction for high-turn runs)

Run #1965 consumed 1,514K tokens across 59 turns — likely a retry loop. Without a turn limit, a single confused run can cost 3–5× the average. Add a turn limit to fail fast:

max-turns: 30

Add this to the frontmatter of .github/workflows/build-test.md. This ensures a run that gets stuck in a retry loop terminates before burning excessive tokens. At 30 turns, worst-case is still ~1M tokens but prevents runaway 59+ turn sessions.


4. Trim the prompt output template

Estimated savings: ~20K tokens/run (~3%)

The "Combined Output" section contains an 18-row pre-filled table template with placeholder values. This template (~700 tokens) is loaded every turn. Replace the verbose pre-filled table with a compact schema description:

Current (700+ tokens):

| Ecosystem | Project | Build/Install | Tests | Status |
|-----------|---------|---------------|-------|--------|
| Bun | elysia | ✅/❌ | X/Y passed | ✅ PASS / ❌ FAIL |
| Bun | hono | ✅/❌ | X/Y passed | ✅ PASS / ❌ FAIL |
... (18 rows)

Proposed (~150 tokens):

Post a PR comment with a markdown table: columns Ecosystem, Project, Build/Install (✅/❌), Tests (X/Y passed or N/A), Status (✅ PASS / ❌ FAIL). Include all 18 projects across 8 ecosystems. End with overall pass/fail count.

At 20 turns avg, saving ~550 tokens/turn = ~11K tokens/run. Smaller savings but zero risk.


5. Install Bun and Deno in pre-steps

Estimated savings: ~66K tokens/run (~10%)

Tasks 1 (Bun) and 3 (Deno) each require a full curl | bash installer run by the agent. These are fully deterministic and could run as pre-steps, eliminating ~2 agent turns:

  - name: Install Bun
    run: |
      curl -fsSL (bun.sh/redacted) | bash
      echo "$HOME/.bun/bin" >> $GITHUB_PATH

  - name: Install Deno
    run: |
      curl -fsSL (deno.land/redacted) | sh
      echo "$HOME/.deno/bin" >> $GITHUB_PATH

Remove the install instructions from Tasks 1 and 3 in the prompt.


Expected Impact

Metric Current Projected Savings
Total tokens/run ~662K ~260K -60%
LLM turns/run ~20 ~8 -60%
Worst-case tokens/run ~1,514K ~600K (capped) -60%
Effective tokens/run ~6,653K ~2,600K -61%

Projections assume recommendations 1+2+5 (pre-steps) reduce turns from 20→8, and rec 3 (max-turns) caps outliers.


Implementation Checklist

  • Add steps: block to clone all 8 test repos (rec 1)
  • Add pre-step for Maven ~/.m2/settings.xml (rec 2)
  • Add pre-steps to install Bun and Deno (rec 5)
  • Remove the corresponding instructions from the prompt body
  • Add max-turns: 30 to frontmatter (rec 3)
  • Trim the 18-row output table template to a compact description (rec 4)
  • Recompile: gh aw compile .github/workflows/build-test.md
  • Verify CI passes on a test PR
  • Compare token usage on new run vs baseline (target: <300K tokens/run)

Generated by Daily Copilot Token Optimization Advisor · sonnet46 1.5M ·

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    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