Repository navigation
fix(healthcheck): per-provider proactive-refresh skip list (rescue short-TTL OAuth like Kimi) #3159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -398,3 +398,74 @@ test("checkConnection skips interval refresh when token expiry is known and stil | |
| } | ||
| ); | ||
| }); | ||
|
|
||
| test("checkConnection skips providers listed in OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS (#kimi-15)", async () => { | ||
| await resetStorage(); | ||
|
|
||
| const providerId = "custom-oauth-skip-list"; | ||
| const refreshRequests: string[] = []; | ||
| const prevSkip = process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS; | ||
|
|
||
| await withHttpServer( | ||
| (req, res) => { | ||
| let body = ""; | ||
| req.setEncoding("utf8"); | ||
| req.on("data", (chunk) => { | ||
| body += chunk; | ||
| }); | ||
| req.on("end", () => { | ||
| refreshRequests.push(body); | ||
| res.writeHead(200, { "Content-Type": "application/json" }); | ||
| res.end( | ||
| JSON.stringify({ | ||
| access_token: "should-not-be-fetched", | ||
| refresh_token: "should-not-be-fetched", | ||
| expires_in: 3600, | ||
| }) | ||
| ); | ||
| }); | ||
| }, | ||
| async (tokenServer) => { | ||
| await withPatchedProvider( | ||
| providerId, | ||
| { | ||
| tokenUrl: `${tokenServer.url}/token`, | ||
| clientId: "skip-client-id", | ||
| clientSecret: "skip-client-secret", | ||
| }, | ||
| async () => { | ||
| const connection = await providersDb.createProviderConnection({ | ||
| provider: providerId, | ||
| authType: "oauth", | ||
| name: "Skip-list Account", | ||
| email: "skip@example.com", | ||
| accessToken: "stale-access-token", | ||
| refreshToken: "refresh-token-skip", | ||
| isActive: true, | ||
| }); | ||
|
|
||
| // The connection is due for refresh (no known expiry, never checked). | ||
| // With the provider listed, the proactive sweep must skip it entirely — | ||
| // NO refresh request is made. | ||
| process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS = `foo, ${providerId} ,bar`; | ||
| await tokenHealthCheck.checkConnection(connection); | ||
| assert.equal( | ||
| refreshRequests.length, | ||
| 0, | ||
| "listed provider must NOT trigger a proactive refresh" | ||
| ); | ||
|
|
||
| // Control: with the provider no longer listed, the same due connection | ||
| // IS refreshed — proving the skip (not token freshness) gated it. | ||
| process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS = "some-other-provider"; | ||
| const stillStale = await providersDb.getProviderConnectionById((connection as any).id); | ||
| await tokenHealthCheck.checkConnection(stillStale); | ||
| assert.equal(refreshRequests.length, 1, "non-listed provider must refresh"); | ||
| } | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| if (prevSkip === undefined) delete process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS; | ||
| else process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS = prevSkip; | ||
| }); | ||
|
Comment on lines
+402
to
+471
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If any assertion fails during the test execution (e.g., test("checkConnection skips providers listed in OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS (#kimi-15)", async () => {
await resetStorage();
const providerId = "custom-oauth-skip-list";
const refreshRequests: string[] = [];
const prevSkip = process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS;
try {
await withHttpServer(
(req, res) => {
let body = "";
req.setEncoding("utf8");
req.on("data", (chunk) => {
body += chunk;
});
req.on("end", () => {
refreshRequests.push(body);
res.writeHead(200, { "Content-Type": "application/json" });
res.end(
JSON.stringify({
access_token: "should-not-be-fetched",
refresh_token: "should-not-be-fetched",
expires_in: 3600,
})
);
});
},
async (tokenServer) => {
await withPatchedProvider(
providerId,
{
tokenUrl: tokenServer.url + "/token",
clientId: "skip-client-id",
clientSecret: "skip-client-secret",
},
async () => {
const connection = await providersDb.createProviderConnection({
provider: providerId,
authType: "oauth",
name: "Skip-list Account",
email: "skip@example.com",
accessToken: "stale-access-token",
refreshToken: "refresh-token-skip",
isActive: true,
});
// The connection is due for refresh (no known expiry, never checked).
// With the provider listed, the proactive sweep must skip it entirely —
// NO refresh request is made.
process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS = "foo, " + providerId + " ,bar";
await tokenHealthCheck.checkConnection(connection);
assert.equal(
refreshRequests.length,
0,
"listed provider must NOT trigger a proactive refresh"
);
// Control: with the provider no longer listed, the same due connection
// IS refreshed — proving the skip (not token freshness) gated it.
process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS = "some-other-provider";
const stillStale = await providersDb.getProviderConnectionById((connection as any).id);
await tokenHealthCheck.checkConnection(stillStale);
assert.equal(refreshRequests.length, 1, "non-listed provider must refresh");
}
);
}
);
} finally {
if (prevSkip === undefined) delete process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS;
else process.env.OMNIROUTE_HEALTHCHECK_SKIP_PROVIDERS = prevSkip;
}
}); |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing
process.envand parsing the comma-separated skip list on every single connection check is inefficient, especially in environments with hundreds of connections. SincecheckConnectionis called in a loop duringsweep(), we can optimize this by caching the parsedSetand only re-parsing if the raw environment variable changes (which is useful for tests).