Skip to content

[GitHub Copilot] Improve AI model error reporting, cache refresh, and test coverage - #33917

Merged
raycastbot merged 3 commits into
raycast:mainfrom
intellectronica:fix-github-copilot-models
Nov 27, 2026
Merged

raycastbot merged 3 commits into
raycast:mainfrom
intellectronica:fix-github-copilot-models

Conversation

@intellectronica

Copy link
Copy Markdown
Contributor

Description

Addresses the client-side bugs found while investigating #33916 and #31852 (follow-up to #31686):

  • Surface real HTTP errors as APICallError: Replaces the custom CopilotApiError thrown inside copilotFetch with APICallError from ai (statusCode, responseHeaders, responseBody, and accurate isRetryable — false for 400/401/403/404, true for 429/5xx). Previously, throwing a non-AI-SDK error inside the custom fetch caused Raycast to classify deterministic 403/400/401 errors as provider-transient / unknown_error, retry them twice, and show a generic error message instead of the actual failure. Also handles model_not_available_for_integrator, no_available_model_endpoints, HTTP 403 responses, and api.github.com top-level { message } errors in fetchApiUrl.
  • Add cache TTL, invalidation, and manual model refresh:
    • Adds a 15-minute TTL to cached api-url and catalog entries in LocalStorage, and invalidates the catalog cache on HTTP 400/404 inference responses so stale endpoint/limit metadata self-heals.
    • Clears inference-v2-* cache entries and calls AI.refreshModels() in reauthorize().
    • Adds a Refresh AI Models action in the Copilot Usage command (src/copilot-usage.tsx) to clear cached model data and call AI.refreshModels() on demand.
  • Defensive fixes & standard headers:
    • Guards Array.isArray(message.content) in requestHeaders() so string user messages do not throw TypeError.
    • Uses optional chaining for request.providerOptions?.raycast?.reasoningEffort and validates non-empty session.selected_model for Auto.
    • Handles non-Error background OAuth rejections in authorizeModelProvider().
    • Adds standard Accept, User-Agent, and X-GitHub-Api-Version headers on fetchApiUrl and a default User-Agent on copilotFetch.
  • Add focused unit tests (npm test): Extracts the pure provider logic into src/services/inference-core.ts and adds tests/inference.test.ts (using node:test, no new dependencies) covering model discovery, caching/TTL/invalidation, error propagation, and all four inference routes (/v1/messages, /responses, /chat/completions, and Auto), closing the test gap noted in Add GitHub Copilot models to Raycast AI #31686.

Note on #33916 / #31852: Full model availability and direct inference for most models still requires GitHub to update server-side Copilot Chat entitlements for the extension's Ov23ctJbHO0idEBx76J5 (copilot-raycast) OAuth client. This PR keeps the extension's legitimate OAuth client and Copilot-Integration-Id intact and fixes the client-side error reporting, caching/refresh, defensive bugs, and test coverage.

Related to #33916 and #31852.

Screencast

No visual layout changes beyond adding a Refresh AI Models action to the Copilot Usage action panel.

Checklist

@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: github-copilot Issues related to the github-copilot extension AI Extension platform: macOS platform: Windows labels Nov 24, 2026
@raycastbot

raycastbot commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! 🎉

🔔 @timrogers @pernielsentikaer @thomaspaulmann @gdarchen @pedrocostadev @xilopaint @jakoss @bru02 you might want to have a look.

You can use this guide to learn how to check out the Pull Request locally in order to test it.

📋 Quick checkout commands
BRANCH="fix-github-copilot-models"
FORK_URL="https://github.com/intellectronica/extensions.git"
EXTENSION_NAME="github-copilot"
REPO_NAME="extensions"

git clone -n --depth=1 --filter=tree:0 -b $BRANCH $FORK_URL
cd $REPO_NAME
git sparse-checkout set --no-cone "extensions/$EXTENSION_NAME"
git checkout
cd "extensions/$EXTENSION_NAME"
npm install && npm run dev

We're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 15 business days.

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · No outstanding findings block merging.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] No outstanding findings block merging.

Summary

The PR improves Copilot HTTP errors, adds cache expiry and model refresh, and guards missing request values.

  • Copilot AI requests show clearer failures and use fresher model details.
  • Copilot Usage can refresh the AI model list, and reauthorization refreshes it too.
  • The contributor list now includes the PR author.

Reviews (3) · Last reviewed commit: "Update CHANGELOG.md" · Reviewed by Greptile

Comment thread extensions/github-copilot/package.json Resolved
Comment thread extensions/github-copilot/CHANGELOG.md Resolved

@0xdhrv 0xdhrv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @intellectronica 👋

Thanks for the Copilot error handling work, surfacing real HTTP errors as APICallError so Raycast stops retrying a 403 and shows the actual failure is a really nice touch 🔥

Here's everything I found in this pass:

Blocking

  • Tests: please remove tests/inference.test.ts and keep it in your own repo, since Store installs only need the extension itself. Greptile's note on the catalog expiry test goes away with it.

  • Test config: please remove tsconfig.test.json.

  • Test script: please remove the test script from package.json. No dev dependencies were added, so the lockfile can stay as it is.

    As mentioned in our docs here ↗

Should fix

  • CHANGELOG.md:9: the last bullet, "Add unit tests covering model discovery, caching, error propagation, and all inference routes", describes internal work and won't apply once the tests are removed. Please drop it, since changelog entries list what users will notice.

Optional

  • If you'd like credit on the Store page, you can add your Raycast username to contributors in package.json. Totally optional.

    As mentioned in our docs here ↗

When the blocking items are done, request another review 😊

Feel free to reach me here or on Slack if anything is unclear.

@0xdhrv
0xdhrv marked this pull request as draft November 27, 2026 05:17
@0xdhrv 0xdhrv self-assigned this Nov 27, 2026
@intellectronica

Copy link
Copy Markdown
Contributor Author

Thanks for the review @0xdhrv! I've addressed all the items:

  • Removed tests/inference.test.ts and tsconfig.test.json
  • Removed the test script from package.json
  • Dropped the internal unit-test bullet from CHANGELOG.md
  • Added intellectronica to contributors in package.json

Verified npm run lint, npm run build, and tsc --noEmit all pass. Ready for another look!

@0xdhrv
0xdhrv marked this pull request as ready for review November 27, 2026 16:23

@0xdhrv 0xdhrv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, approved 🔥

@raycastbot
raycastbot merged commit f71d9c4 into raycast:main Nov 27, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@raycastbot

Copy link
Copy Markdown
Collaborator

🎉 🎉 🎉

We've rewarded your Raycast account with some credits. You will soon be able to exchange them for some swag.

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

Labels

AI Extension extension fix / improvement Label for PRs with extension's fix improvements extension: github-copilot Issues related to the github-copilot extension platform: macOS platform: Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants