fix: Scope cached http(s) agents per-destination#6716
Conversation
| ): HttpAgentConfig | HttpsAgentConfig { | ||
| const protocol = getProtocolOrDefault(destination); | ||
| const cacheKey = hashCacheKey({ protocol, options }); | ||
| const cacheKey = hashCacheKey({ destination, options }); |
There was a problem hiding this comment.
[Nit] destination.certificates and options already overlap — the same cert material ends up in the hash twice. Is there any functional impact on this change?
There was a problem hiding this comment.
Including the full destination busts the cache on every token refresh for OAuth2ClientCredentials/OAuth2SAMLBearerFlow destinations — `authTokens.value changes hourly but is never read by createAgent, so keep-alive reuse breaks entirely for those destinations.
There was a problem hiding this comment.
I would like to suggest scoping the key to only what affects agent behavior:
const cacheKey = hashCacheKey({
protocol,
options,
proxyConfiguration: destination.proxyConfiguration,
cloudConnectorLocationId: destination.cloudConnectorLocationId
});
There was a problem hiding this comment.
I think a 1h cache is acceptable for this use-case. In addition to cloudConnectorLocationId for the proxy the agent also needs to be keyed per-user.
InjunPark-sap
left a comment
There was a problem hiding this comment.
nit question and suggest changes on http-agent.ts:309
InjunPark-sap
left a comment
There was a problem hiding this comment.
Two open questions:
-
Does
authTokensactually appear in the destination object passed togetAgentConfigin OAuth2 flows? If yes, every token refresh produces a new cache key and keep-alive reuse is lost. -
Is
proxyConfigurationsufficient for per-user keying, or are there cases where the user identity affects agent behavior outside ofproxyConfiguration.headers?
|
InjunPark-sap
left a comment
There was a problem hiding this comment.
Approval with the understanding that OAuth2 destinations will see reduced agent reuse on token refresh. (Worth revisiting if it shows up as a connection overhead issue in production.)
Closes https://github.com/SAP/ai-sdk-js-backlog/issues/604.