Skip to content

[copilot-opt] Reduce oversized initial context payloads causing elevated first-turn token costs #46903

Description

@github-actions

Problem

Session initial context (first-turn input tokens) is consistently large, ranging from 24k to 80k tokens. One session (29724711240) started at 80,344 input tokens due to large workflow skill/instruction payloads loaded upfront. Oversized initial context increases LLM inference cost on every turn and contributes to context-window exhaustion in long sessions.

Evidence

  • Analysis window: 2026-07-06 to 2026-07-20 UTC
  • Sessions analyzed: 10 (conversation logs available)
  • Key metrics and examples:
    • Session 29724711240: first-turn input = 80,344 tokens (user message was 27,337 chars — bulk comes from system/workflow instructions)
    • Median first-turn input across all sessions: ~26,000 tokens
    • Session 29723853191 context grew to 181,511 tokens by turn 80, indicating no trimming as context accumulates
    • Sessions loading multi-skill instruction bundles upfront show 40-130% higher first-turn token counts than sessions that lazy-load skills

Proposed Change

  1. Audit the agentic-opt workflow instruction payload — the jqschema skill, PR-data prompts, and detailed phase instructions are all inlined into the initial system message. Move lower-priority phase details (Phase 2-5) behind a lazy-load pattern so they are injected only when needed.
  2. For sessions starting with large user.message (>10k chars), add a pre-processing step that summarizes or strips redundant boilerplate before passing to the LLM.
  3. Establish a first-turn token budget guard: if first-turn input exceeds 50k tokens, emit a warning log so the issue is visible before sessions run.

Expected Impact

  • Reduce average first-turn inference cost by 20-40%
  • Reduce context-window exhaustion in long sessions (currently reaching 181k tokens)
  • Faster first-turn response times across all agent sessions

Notes

  • Distinct root cause category: oversized initial instruction/context payload
  • Data quality: 10 of 50 sessions have conversation logs; remaining 40 sessions have no logs available for analysis

Generated by ⚡ Copilot Opt · 33.8 AIC · ⌖ 9.79 AIC · ⊞ 6.8K ·

Metadata

Metadata

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