fix(ai): honor server-provided slow_down interval in device-code polling
GitHub's device flow documents slow_down as a rate limit: a poll that
arrives inside the throttle window is answered with slow_down instead of
the token, and the response's interval field reports the new required
minimum ("adds 5 seconds to the last interval"). A client that only
tracks its own +5s increment can stay behind the server's ratcheting
requirement when its timers fire early - common with WSL/VM clock drift
(microsoft/WSL#10006) - so every subsequent poll keeps hitting the rate
limit and login appears to hang forever even after the browser reports
the device as authorized.
Adopt the server-provided interval when a slow_down poll result carries
one, falling back to the RFC 8628 section 3.5 +5s increment otherwise.
GitHub Copilot passes the interval field through.
This restores part of the #1994 mitigations that were lost in the #4788
device-code refactor.
refs #6187
This commit is contained in:
@@ -247,7 +247,7 @@ describe("GitHub Copilot OAuth device flow", () => {
|
||||
const accessTokenPollTimes: number[] = [];
|
||||
const accessTokenResponses = [
|
||||
jsonResponse({ error: "authorization_pending", error_description: "pending" }),
|
||||
jsonResponse({ error: "slow_down", error_description: "slow down" }),
|
||||
jsonResponse({ error: "slow_down", error_description: "slow down", interval: 7 }),
|
||||
jsonResponse({ access_token: "ghu_refresh_token" }),
|
||||
];
|
||||
|
||||
@@ -329,7 +329,8 @@ describe("GitHub Copilot OAuth device flow", () => {
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
expect(accessTokenPollTimes).toHaveLength(2);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(9999);
|
||||
// slow_down carried a server-provided interval of 7 seconds.
|
||||
await vi.advanceTimersByTimeAsync(6999);
|
||||
expect(accessTokenPollTimes).toHaveLength(2);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
@@ -338,7 +339,7 @@ describe("GitHub Copilot OAuth device flow", () => {
|
||||
expect(accessTokenPollTimes).toEqual([
|
||||
startTime.getTime() + 5000,
|
||||
startTime.getTime() + 10000,
|
||||
startTime.getTime() + 20000,
|
||||
startTime.getTime() + 17000,
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user