Skip to content

fix: resolve Copilot model context window from /models API - #1541

Merged
avoidwork merged 3 commits into
mainfrom
fix/copilot-model-context-window
Oct 26, 2026
Merged

avoidwork merged 3 commits into
mainfrom
fix/copilot-model-context-window

Conversation

@avoidwork

@avoidwork avoidwork commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Description

Resolves the Copilot model context window from the /models API. Two gaps are closed:

  • resolveCopilotModel (src/provider/openai.js) now decorates the /models discovery request with the Copilot bearer token via createCopilotFetch, so the token is read fresh from memory/auth.json and 401 re-auth is handled consistently.
  • getModelContextLength (src/provider/modelInfo.js) now reads Copilot's usable prompt budget (limits.max_prompt / max_prompt_tokens, falling back to limits.context_window / max_context_window_tokens), preferring max_prompt over context_window.

The OpenSpec change copilot-model-context-window was proposed, implemented, and archived, syncing the model-context-length and github-copilot-provider specs.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes)
  • Performance improvement
  • CI / build / tooling

Testing

  • Added 5 Copilot-shaped resolver cases to tests/unit/provider/modelInfo.test.js (limits.max_prompt, limits.context_window, max_prompt_tokens, max_context_window_tokens, no-usable-fields).
  • Added 1 case to tests/unit/provider/openai.test.js asserting the Authorization: Bearer header on the /models request.
  • Full suite: 4355 tests pass. npm run lint clean. npm run coverage maintained (modelInfo.js 100% lines).

Coverage

  • Line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with maintained line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

Closes #1539

Adds OpenSpec change copilot-model-context-window covering the Copilot
/models discovery auth fix and the Copilot-shaped context-length resolver
branch.
@avoidwork avoidwork added the bug Something isn't working label Oct 26, 2026
@avoidwork avoidwork self-assigned this Oct 26, 2026
- resolveCopilotModel now decorates the /models discovery request with the
  Copilot bearer token via createCopilotFetch, so the token is read fresh
  from memory/auth.json and 401 re-auth is handled consistently.
- getModelContextLength now reads Copilot's usable prompt budget
  (limits.max_prompt / max_prompt_tokens, falling back to
  limits.context_window / max_context_window_tokens), preferring max_prompt
  over context_window.
- Adds unit tests for the Copilot-shaped resolver response and the
  Authorization Bearer header on the /models request.
Archives the OpenSpec change and syncs the updated model-context-length
and github-copilot-provider specs.
@avoidwork

Copy link
Copy Markdown
Owner Author

Audit Results: copilot-model-context-window

Goal Fulfillment

  • Authenticate model discovery — resolveCopilotModel now decorates the /models request with createCopilotFetch(), injecting the Copilot bearer token and handling 401 re-auth consistently. ✅
  • Copilot context window — getModelContextLength reads limits.max_prompt / max_prompt_tokens, falling back to limits.context_window / max_context_window_tokens. Prefers max_prompt (usable budget) over context_window. ✅
  • Guard new fields — Only returns a number when present and numeric; falls through to undefined otherwise. Never throws. ✅
  • Unit tests — 5 Copilot-shaped cases in modelInfo.test.js; 1 Authorization header case in openai.test.js. ✅
  • Verify — 4355 tests pass, lint clean, coverage maintained. ✅

Spec Compliance

  • model-context-length delta: all Copilot shape scenarios covered (limits.max_prompt, limits.context_window, max_prompt_tokens, max_context_window_tokens, no-usable-fields). ✅
  • github-copilot-provider delta: discovery request authenticated scenario covered. ✅

Task Completion

All 6 tasks complete (1.1, 2.1, 2.2, 3.1, 3.2, 4.1). ✅

Quality Check

  • modelInfo.js at 100% line coverage (all new branches covered).
  • openai.js at 96.35% lines / 80% functions — uncovered lines (62-64, 171, 199-200, 212-215) are pre-existing retry-delay and prototype-patch paths, not from this change.
  • No forbidden patterns; conventional commit style applied.

@avoidwork
avoidwork merged commit fdf1bdc into main Oct 26, 2026
2 checks passed
@avoidwork
avoidwork deleted the fix/copilot-model-context-window branch October 26, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: resolve Copilot model context window from /models API

1 participant