mirror of
https://github.com/earendil-works/pi.git
synced 2026-10-02 00:35:27 +08:00
fix(ai): enable Copilot model policies sequentially during login
Batching policy POSTs at concurrency 4 still bursts 30 requests during login, which trips the Copilot API rate limiter and makes the following GET /models fail with 429, aborting login (#8121). Send the policy updates one at a time instead.
This commit is contained in:
@@ -16,7 +16,6 @@ const COPILOT_HEADERS = {
|
||||
"Copilot-Integration-Id": "vscode-chat",
|
||||
} as const;
|
||||
const COPILOT_API_VERSION = "2026-06-01";
|
||||
const COPILOT_POLICY_CONCURRENCY = 4;
|
||||
|
||||
type DeviceCodeResponse = {
|
||||
device_code: string;
|
||||
@@ -344,13 +343,8 @@ async function enableAllGitHubCopilotModels(
|
||||
enterpriseDomain: string | undefined,
|
||||
signal: AbortSignal,
|
||||
): Promise<void> {
|
||||
const models = Object.values(GITHUB_COPILOT_MODELS);
|
||||
for (let index = 0; index < models.length; index += COPILOT_POLICY_CONCURRENCY) {
|
||||
await Promise.all(
|
||||
models.slice(index, index + COPILOT_POLICY_CONCURRENCY).map(async (model) => {
|
||||
await enableGitHubCopilotModel(token, model.id, enterpriseDomain, signal);
|
||||
}),
|
||||
);
|
||||
for (const model of Object.values(GITHUB_COPILOT_MODELS)) {
|
||||
await enableGitHubCopilotModel(token, model.id, enterpriseDomain, signal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ describe("GitHub Copilot OAuth device flow", () => {
|
||||
await loginPromise;
|
||||
});
|
||||
|
||||
it("limits concurrent model policy updates during login", async () => {
|
||||
it("enables model policies sequentially during login", async () => {
|
||||
vi.useFakeTimers();
|
||||
|
||||
let activePolicyRequests = 0;
|
||||
@@ -297,8 +297,8 @@ describe("GitHub Copilot OAuth device flow", () => {
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
await loginPromise;
|
||||
|
||||
expect(policyRequestCount).toBeGreaterThan(4);
|
||||
expect(maxActivePolicyRequests).toBe(4);
|
||||
expect(policyRequestCount).toBeGreaterThan(1);
|
||||
expect(maxActivePolicyRequests).toBe(1);
|
||||
});
|
||||
|
||||
it("rejects a non-http(s) verification_uri before it reaches onDeviceCode", async () => {
|
||||
|
||||
Reference in New Issue
Block a user