feat(copilot-opt): reduce first-turn context size with lazy skill blocks and pre-agent guards#46969
Merged
pelikhan merged 3 commits intoJul 21, 2026
Merged
Conversation
…ll blocks and adding guards - Move Phase 2 (Performance Analysis) to skill 'opt-phase-performance' - Move Phase 3 (PR Cross-Analysis) to skill 'opt-phase-pr-analysis' - Move Phase 4 (Recommendation Selection) to skill 'opt-phase-recommendations' - Move Phase 5 (Issue Creation) to skill 'opt-phase-issue-creation' - Add token budget guard step: warns when estimated first-turn input exceeds 50k tokens - Add trim-large-session-logs step: strips boilerplate from session files >10KB before agent reads them - Recompile copilot-opt.lock.yml Closes #46903 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…y comment - Rename STRIPPED_KB → REMOVED_KB to clarify the variable represents removed content in KB - Use %d (integer) format specifier instead of %s for printf - Add comment explaining why overlap guard is unnecessary (THRESHOLD > FIRST_CHUNK+LAST_CHUNK) - Update token estimate comment to match divisor (3 chars/token conservative estimate) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix oversized initial context payloads causing elevated costs
feat(copilot-opt): reduce first-turn context size with lazy skill blocks and pre-agent guards
Jul 21, 2026
pelikhan
marked this pull request as ready for review
July 21, 2026 05:25
Contributor
There was a problem hiding this comment.
Pull request overview
Reduces Copilot Opt’s initial context size through lazy-loaded phase instructions and pre-agent context guards.
Changes:
- Moves Phases 2–5 into inline skills.
- Adds prompt-size monitoring and session-log trimming.
- Regenerates the compiled workflow.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/copilot-opt.md |
Defines lazy skills and context guards. |
.github/workflows/copilot-opt.lock.yml |
Compiles the updated workflow. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Medium
Comment on lines
+67
to
+69
| PROMPT_CHARS=$(wc -c < "$PROMPT_FILE") | ||
| # Conservative approximation: ~3 chars/token (technical content) | ||
| ESTIMATED_TOKENS=$((PROMPT_CHARS / 3)) |
| # THRESHOLD (10240) > FIRST_CHUNK+LAST_CHUNK (6144), so no chunk overlap possible | ||
| REMOVED_KB=$(( (SIZE - FIRST_CHUNK - LAST_CHUNK) / 1024 )) | ||
| echo "Trimming large session log: $f (${SIZE} bytes, stripping ~${REMOVED_KB}KB of boilerplate)" | ||
| { head -c "$FIRST_CHUNK" "$f"; printf "...[%dKB stripped — fetch raw on demand if needed]\n" "$REMOVED_KB"; tail -c "$LAST_CHUNK" "$f"; } > "${f}.trimmed" |
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
copilot-optworkflow was inlining all Phase 2–5 instructions into the initial system message, contributing to first-turn inputs of 24k–80k+ tokens. Three changes reduce this:Lazy-load Phases 2–5 via
## skill:blocksDetailed instructions for Performance Analysis, PR Cross-Analysis, Recommendation Selection, and Issue Creation are moved out of the main prompt body into four inline skill blocks (
opt-phase-performance,opt-phase-pr-analysis,opt-phase-recommendations,opt-phase-issue-creation). The gh-aw runtime strips these from the initial system message at activation and restores them as on-demand skill files — removing ~5KB (~1,600 tokens) from every first turn.Token budget guard step
A pre-agent step reads the compiled
prompt.txt, estimates tokens at a conservative 3 chars/token, and emits a::warning::annotation if the estimate exceeds 50k — surfacing budget overruns in CI before the agent starts.Trim large session logs step
A pre-agent step trims any session log file over 10KB to first 5KB + retrieval notice + last 1KB, preventing the agent from accidentally loading full multi-turn transcripts (which can exceed 40KB for 80-turn sessions) in a single
cat.