Skip to content

fix: coalesce auth-triggered GetProfile checks in ProfileStatusMonitor - #2872

Draft
laileni-aws wants to merge 1 commit into
mainfrom
fix/coalesce-profile-status-getprofile-checks
Draft

fix: coalesce auth-triggered GetProfile checks in ProfileStatusMonitor#2872
laileni-aws wants to merge 1 commit into
mainfrom
fix/coalesce-profile-status-getprofile-checks

Conversation

@laileni-aws

Copy link
Copy Markdown
Collaborator

Problem

ProfileStatusMonitor re-checks the profile's MCP configuration (a GetProfile request) every time an auth success event fires. Auth success is emitted on every aws/updateConfiguration that carries a profileArn — including when the profile did not change — and on credential updates, so a client that refreshes its token or re-pushes its configuration several times in a short window causes the language server to issue one GetProfile request per event.

Two things make this worse:

  • There is no in-flight guard, so concurrent events each start their own request instead of sharing one.
  • Each check already retries on 5xx via retryWithBackoff, so during a backend error every event costs up to two requests.

The net effect is that a single IDE can generate dozens of GetProfile calls per minute for the same profile, and the rate goes up when the service is returning 5xx.

Solution

  • Route auth success events through onAuthSuccess(), which skips the check when the same profile ARN was already checked within AUTH_EVENT_MIN_INTERVAL_MS (60s). The timestamp is recorded before the request so failed checks are rate-limited too. A different profile ARN still triggers an immediate check.
  • Make isMcpEnabled() return the in-flight promise when a check is already running, so concurrent callers (auth event + checkInitialState(), or repeated events) share one GetProfile request.
  • checkInitialState() and the 24-hour periodic check keep their existing behaviour; the cooldown only applies to event-triggered checks.
  • Swallow the rejection in the event handler (previously void this.isMcpEnabled() could surface as an unhandled rejection; the error is already logged inside the check).

Adds unit tests covering: concurrent checks share one request, sequential checks still run, cooldown suppresses repeats for the same profile and lifts after the interval, profile change bypasses the cooldown, and cooldown applies after a failed (5xx) check.

Testing: ts-mocha src/language-server/agenticChat/tools/mcp/profileStatusMonitor.test.ts — all new tests pass; the pre-existing static lastMcpState test that depends on a cached state file on disk is unaffected by this change. Prettier and eslint pass on the changed files.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Every auth success event ran an independent MCP configuration check, and each check issued its own GetProfile request. Bursts of token refreshes or repeated profile configuration updates therefore turned into bursts of GetProfile calls, made worse during backend errors because each check also retried.

Share a single in-flight check between concurrent callers, and skip auth-triggered checks for the same profile within a one-minute cooldown. Explicit initial and periodic checks are unchanged, and a profile change still triggers an immediate check.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 93.65079% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rver/agenticChat/tools/mcp/profileStatusMonitor.ts 93.65% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants