Skip to content

bug: agentic workflows fail with token limit overflow when repository has comprehensive custom instructions #22929

Closed

Description

@bindsi

bug: agentic workflows fail with token limit overflow when repository has comprehensive custom instructions

Problem

Agentic workflows fail with CAPIError: 400 prompt token count exceeds the limit in repositories with comprehensive .github/ directories because the Copilot CLI auto-discovers and injects all custom instructions into the prompt unconditionally — exceeding the model's token limit before the workflow prompt is even processed. This makes agentic workflows broken out of the box for any serious prompt engineering or enterprise repository.

Large repositories should not be a problem. The whole point of agentic workflows is to automate work in real-world repositories — and real-world repositories grow. A repo with comprehensive coding standards, multiple agent definitions, and domain-specific skills is exactly the kind of repo that benefits most from automation. The current behavior punishes repos for being well-organized and instruction-rich, which is the opposite of what we want to encourage.

Context

Our repository (microsoft/hve-core) is a prompt engineering tooling project. The .github/ directory contains:

Path Size Approx. Tokens
.github/instructions/ ~878 KB ~220K
.github/agents/ ~517 KB ~130K
.github/skills/ ~374 KB ~94K
Total ~2.6 MB ~440K+

The Copilot CLI 168K token limit is exceeded before the workflow prompt even gets a chance to run. But this is not an unreasonable repository — it's a well-structured project with organized instructions across multiple domains (coding standards, design thinking, security, ADO integration). Any enterprise repository with multiple teams contributing standards will hit similar sizes. Agentic workflows need to scale alongside the repos they serve, not collapse under them.

Reproduction

  1. Create a repository with a large .github/instructions/ directory (>500 KB of .instructions.md files)

  2. Create a simple agentic workflow:

    ---
    on:
      issues:
        types: [labeled]
        names: [agent-ready]
    engine: copilot
    ---
    
    # Implement the issue
    Read the issue and implement the requested change.
  3. Trigger the workflow

  4. The agent job fails with:

    CAPIError: 400 prompt token count of 186803 exceeds the limit of 168000
    
  5. The workflow prompt itself is only ~5K tokens — the remaining ~181K comes entirely from auto-discovered custom instructions

Root Cause

The Copilot CLI auto-discovers and loads all files matching these patterns from $GITHUB_WORKSPACE:

  • .github/copilot-instructions.md
  • .github/instructions/**/*.instructions.md
  • .github/agents/**/*.agent.md
  • .github/skills/**/SKILL.md

There is no mechanism to:

  • Filter which instruction files are loaded
  • Set a token budget for auto-discovered content
  • Exclude specific directories or files from discovery

The CLI has --no-custom-instructions but gh aw doesn't expose it, and it's too blunt (disables all instructions, including the ones the workflow actually needs).

Current Workaround

We use sparse-checkout in the workflow frontmatter to physically exclude heavy directories from disk so auto-discovery can't find them:

checkout:
  sparse-checkout: |
    .github/copilot-instructions.md
    .github/instructions/coding-standards/
    .github/instructions/hve-core/
    .github/instructions/shared/
    scripts/
    package.json

This works but is brittle and shifts the burden to every workflow author:

  • Each workflow must manually curate which instruction subdirectories exist on disk
  • Adding new instructions to the repo can silently break workflows by pushing them over the token budget
  • The workflow author needs to know the byte sizes of every instruction directory to stay under budget
  • It conflates "what files the agent can access" with "what instructions the agent should follow" — two fundamentally different concerns

Proposal

One or more of the following would solve this cleanly:

Option A: Frontmatter-level instruction filtering

custom-instructions:
  include:
    - .github/instructions/coding-standards/
    - .github/instructions/hve-core/
  exclude:
    - .github/agents/
    - .github/skills/

Option B: Expose --no-custom-instructions in frontmatter with imports as the sole instruction source

custom-instructions: false
imports:
  - ../agents/hve-core/task-implementor.agent.md

This would mean: "don't auto-discover anything, only use the explicitly imported files." This is the cleanest separation — imports for instructions, checkout for file access.

Option C: Token budget cap for auto-discovered content

Auto-discovered instructions are truncated or pruned (least-relevant-first) when they approach a configurable fraction of the model's context window, preserving space for the workflow prompt and conversation.

Why This Matters

The value proposition of agentic workflows grows with repository maturity. Repos that invest in coding standards, security instructions, and domain-specific agents are the repos that get the most out of automation. The current all-or-nothing auto-discovery makes agentic workflows progressively harder to use as repos mature — exactly when they should be getting easier.

Environment

  • gh aw version: v0.63.1
  • Copilot CLI: standalone mode (COPILOT_AGENT_RUNNER_TYPE: STANDALONE)
  • Model token limit: 168,000

Activity

  1. locked and limited conversation to collaborators on Mar 25, 2026
  2. unlocked this conversation on Mar 25, 2026
  3. pelikhan commented on Mar 25, 2026

    @pelikhan
    Collaborator

    Good one. As we are looking into better controlling the agentic tooling environment, this is something we will want full control over.

  4. bindsi commented on Mar 26, 2026

    @bindsi
    Author

    @pelikhan what are the next steps here? Since we are working on the Edge AI and HVE forefront (internally) we want to integrate AW to orchestrate and automate our issue and pr management and maintenance work. This limitation blocks us to do full checkouts and use all the agentic work in /.github folder

  5. locked and limited conversation to collaborators on Mar 26, 2026
  6. unlocked this conversation on Mar 26, 2026
  7. pelikhan commented on Oct 7, 2026

    @pelikhan
    Collaborator

    Status (2026-10-07; Needs progress check): The March 25 report describes prompt-token overflow in an instruction-heavy repository, while the April 10 comment provides only a task link, not a verified fix. The issue is open and needs a progress check on instruction-loading controls and whether the reported failure still occurs.

  8. added
    bugSomething isn't working
    cluster:ambient-configUnrequested repository instructions or MCP configuration entering agent runtimes
    on Oct 14, 2026
  9. pelikhan commented on Oct 16, 2026

    @pelikhan
    Collaborator

    Current-state refresher (2026-10-16): partially addressed; the all-or-nothing instruction opt-out now exists. #25661 merged on April 10 and introduced engine.bare. For Copilot, engine: { id: copilot, bare: true } emits --no-custom-instructions, with compiler regression coverage and bare-mode documentation. This implements the substance of the report's Option B without sparse-checkout-based file hiding.

    That is not selective include/exclude loading or an automatic context/token budget, and bare mode defaults to false. The original large-repository overflow was not reproduced in this pass, so normal-mode behavior and the exact instruction categories loaded by the current Copilot runtime are not verified here. The issue should now distinguish the delivered opt-out from any remaining request for selective, budget-aware discovery.

  10. pelikhan commented on Oct 22, 2026

    @pelikhan
    Collaborator

    Relevance check (2026-10-22): Option B is implemented; keep open pending confirmation of the reported overflow. #25661 merged the opt-out. On current main (ffdd9c9), engine: { id: copilot, bare: true } adds --no-custom-instructions, with positive/default-off compiler coverage and current documentation. This separates ambient instruction discovery from checkout contents, without sparse-checkout hiding.

    The opening proposal accepts one or more alternatives, so selective include/exclude loading and automatic token budgeting should not become additional closure prerequisites if this opt-out meets the actual need. They remain distinct capabilities, not features supplied by bare mode.

    Next concrete action/evidence requested: provide the current gh-aw and Copilot CLI versions, a sanitized minimal instruction-heavy fixture, and the relevant startup/token-limit excerpt from an affected workflow recompiled with bare: true and its intended instructions explicitly imported. Confirm whether it starts without ambient-content overflow and retains the required explicit prompt content. If that succeeds, this report can close as completed via Option B; if selective ambient loading is still essential, identify the exact files that must remain auto-loaded. No large-repository runtime reproduction was performed here, so the original failure is not being declared resolved solely from flag emission.

  11. pelikhan commented on Oct 22, 2026

    @pelikhan
    Collaborator

    I'm going to tentatively close this one. @bindsi please reopen new one with your latest state.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcluster:ambient-configUnrequested repository instructions or MCP configuration entering agent runtimescommunity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions