Skip to content

Token optimization for contribution-check: trim deep research, pre-fetch guidelines, narrow toolset, reduce batch cap#26124

Merged
pelikhan merged 2 commits intomainfrom
copilot/copilot-token-optimizer-contribution-check
Apr 14, 2026
Merged

Token optimization for contribution-check: trim deep research, pre-fetch guidelines, narrow toolset, reduce batch cap#26124
pelikhan merged 2 commits intomainfrom
copilot/copilot-token-optimizer-contribution-check

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

The contribution-check workflow was consuming ~2.8M tokens/run (peaking at 11.2M) due to expensive per-PR deep research, redundant CONTRIBUTING.md fetches across all subagent instances, an oversized default GitHub toolset, and a 10-PR batch cap.

Changes

.github/agents/contribution-checker.agent.md

  • Replace Step 2.5 "Deep Research" (repo browsing, surrounding code reads, test pattern mapping, duplicate PR search) with "Targeted Context": read the diff and optionally look up a referenced issue — nothing more
  • Step 1 now accepts inline CONTRIBUTING.md content via <contributing-guidelines> tags to skip redundant fetching; treats # No CONTRIBUTING.md found sentinel as missing guidelines (/no-guidelines)

.github/workflows/contribution-check.md

  • Pre-fetch CONTRIBUTING.md once in the pre-agent bash step (tries root → .github/docs/), write to contributing-guidelines.md, log which location succeeded or that none was found
  • Embed pre-fetched content in every subagent dispatch prompt — eliminates N redundant fetches for N concurrent subagents
  • Narrow toolset: [default] (30+ tools) → [pull_requests, repos, issues]
  • Reduce batch cap: MAX_EVALUATE=10MAX_EVALUATE=5

Estimated savings

Change Est. tokens saved/run
Trim deep research ~1,100,000
Pre-fetch CONTRIBUTING.md ~120,000
Narrow toolset ~80,000
Reduce batch cap (busy days) ~1,400,000
Conservative total (recs 1–3) ~1,300,000 (~46% reduction)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw -pack /home/REDACTED/work/gh-aw/gh-aw/cmd/gh-aw/main.go (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw TAUnjV2J-Fmj2/eR-c (http block)
  • https://api.github.com/repos/actions/upload-artifact/git/ref/tags/v7
    • Triggering command: /usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v7 --jq .object.sha (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v7 --jq .object.sha ck (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v7 --jq .object.sha ithub/workflows credential.helper ker/cli-plugins/docker-buildx (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha (http block)
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha k/gh-aw/gh-aw/.g--irreversible-delete main me: String!) { 6096c38537e2b93ec370a5412a3aceb91df212de (http block)
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha ithub/workflows main repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } (http block)
  • https://api.github.com/repos/docker/build-push-action/git/ref/tags/v7
    • Triggering command: /usr/bin/gh gh api /repos/docker/build-push-action/git/ref/tags/v7 --jq .object.sha (http block)
    • Triggering command: /usr/bin/gh gh api /repos/docker/build-push-action/git/ref/tags/v7 --jq .object.sha k/gh-aw/gh-aw config rs_test.go fault_test.go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/docker/build-push-action/git/ref/tags/v7 --jq .object.sha k/gh-aw/gh-aw/.github/workflows --jq de_modules/.bin/sh (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/-
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/- --jq .object.sha (http block)
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/- --jq .object.sha b:/usr/lib origin _modules/.bin/sh (http block)

If you need me to access, download, or install something from one of these locations, you can either:

…uidelines, narrow toolset, reduce batch size

- Replace Step 2.5 'Deep Research' with 'Targeted Context' in contribution-checker.agent.md
  (removes repo browsing, surrounding code reads, and duplicate PR searches)
- Pre-fetch CONTRIBUTING.md once in the pre-agent bash step; pass it inline to each
  subagent dispatch to eliminate 9 redundant fetches per run
- Narrow GitHub toolset from [default] to [pull_requests, repos, issues]
- Reduce MAX_EVALUATE from 10 to 5 to cap token usage on high-traffic days
- Recompile contribution-check.lock.yml

Resolves: copilot-token-optimizer issue (~46% token reduction estimated)"

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/b996051a-b125-4b10-a8e1-20f02279380e

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize contribution check for token efficiency Token optimization for contribution-check: trim deep research, pre-fetch guidelines, narrow toolset, reduce batch cap Apr 14, 2026
Copilot AI requested a review from pelikhan April 14, 2026 01:03
@pelikhan pelikhan marked this pull request as ready for review April 14, 2026 01:14
Copilot AI review requested due to automatic review settings April 14, 2026 01:14
@pelikhan pelikhan merged commit 1b15988 into main Apr 14, 2026
53 checks passed
@pelikhan pelikhan deleted the copilot/copilot-token-optimizer-contribution-check branch April 14, 2026 01:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reduces token usage in the scheduled contribution-check workflow by limiting per-PR context gathering, reusing a single CONTRIBUTING.md fetch across subagent calls, narrowing GitHub MCP toolsets, and lowering the per-run PR evaluation cap.

Changes:

  • Replace “Deep Research” with “Targeted Context” in the contribution-checker subagent instructions.
  • Pre-fetch CONTRIBUTING.md once in the workflow and instruct the orchestrator to inline it into each subagent dispatch.
  • Narrow GitHub MCP toolsets to [pull_requests, repos, issues] and reduce the PR batch cap from 10 to 5.
Show a summary per file
File Description
.github/workflows/contribution-check.md Updates orchestrator workflow prompt + pre-agent bash to pre-fetch CONTRIBUTING.md, narrow toolsets, and lower batch size.
.github/workflows/contribution-check.lock.yml Regenerated compiled workflow to reflect toolset + prefetch + batch cap changes.
.github/agents/contribution-checker.agent.md Updates subagent behavior to accept inline guidelines and avoids expensive repo exploration via “Targeted Context”.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 3

## Step 1: Fetch Contributing Guidelines

Fetch the target repository's contributing guidelines. Look for these files in order and use the **first one found**:
If the CONTRIBUTING.md content was provided inline at the start of this prompt (inside `<contributing-guidelines>` tags), use that content directly and skip this step. If the inline content is `# No CONTRIBUTING.md found`, treat it as missing guidelines and return a single row with verdict `❓` and quality `no-guidelines`.
3. **Check for related issues** — if the PR body references an issue, read that issue to understand the original requirements and acceptance criteria.
4. **Check for existing tests** — look at the test directory/files adjacent to the changed code. Understand the testing patterns and frameworks the project uses so your feedback and agentic prompts reference the right tools and conventions.
5. **Check for duplicated effort** — search for open PRs that touch the same files or address the same issue to flag potential conflicts.
- Read the PR diff and changed files carefully to understand what's changing.
Comment on lines +123 to 127
Read the contents of `contributing-guidelines.md` from the workspace root. This file was pre-fetched in the `pre-agent` step and contains the target repository's contributing guidelines. Include it verbatim in every subagent dispatch prompt to avoid redundant fetches.

Call the contribution-checker subagent for each PR with this prompt:

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[copilot-token-optimizer] Token Optimization: Contribution Check — Deep Research & Toolset Reduction

3 participants