fix(mcp): classify auth-validation failures before logging so expected rejections stop masking outages - #1669
Draft
Dhravya wants to merge 1 commit into
Conversation
Split the validateApiKey and validateOAuthToken catch blocks so transient auth-backend failures log at ERROR under a distinct 'Auth backend transient failure:' template while expected rejections log at debug. Return values and 401/503 status contract are unchanged. Co-authored-by: Dhravya Shah <dhravya@supermemory.com>
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
supermemory-mcp | 59e3fb4 | Sep 14 2026, 06:03 PM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
supermemory-app | 59e3fb4 | Commit Preview URL Branch Preview URL |
Sep 14 2026, 06:04 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The MCP authentication layer treated two very different situations as if they were the same. Whenever a request arrived with a token it could not accept, the service raised a loud, top-severity alarm — regardless of whether the token was simply invalid (the normal, expected outcome of internet scanners and misconfigured clients probing a public endpoint) or whether the authentication backend itself was actually struggling. Because the public MCP endpoint receives a constant stream of bad tokens, this generated roughly 20,000 top-severity alarms every six hours as steady background noise.
The consequence: anyone watching for real problems could not find them. A genuine authentication-backend outage would produce the exact same kind of alarm as the endless stream of expected rejections, so it would be buried in the noise and indistinguishable from normal traffic. That noise also dominated the account-wide error rollup, drowning out signal from other services. Merging this change makes routine token rejections quiet and keeps only genuine backend trouble loud, so a real outage stands out immediately.
Before / After
Before: Operators watching the monitoring surfaces saw a relentless flood of top-severity errors coming from the MCP service — thousands every hour — driven entirely by ordinary invalid-token traffic hitting the public endpoint. Because every rejected token, whether just a bad credential or a symptom of a failing auth backend, was reported the same loud way, the two cases were impossible to tell apart. The account-wide error rollup was dominated by this baseline, masking signal from other services. If the authentication backend actually went down, that event would look identical to the everyday noise, so nobody could distinguish a real incident from routine scanner traffic.
After: Routine, expected token rejections no longer raise top-severity alarms; they are recorded quietly at debug level, so they drop out of the error views and stop dominating the account rollup. Genuine authentication-backend trouble — a session endpoint returning 5xx, an unreachable backend, or a JWKS fetch failure — is still reported loudly, now under its own clearly named category. Operators see a near-empty error stream during normal operation, and a real backend outage stands out immediately as a distinct, visible signal instead of hiding among thousands of expected rejections. The rejection and retry behavior clients experience is unchanged.
What changed
Both
validateApiKeyandvalidateOAuthTokeninapps/mcp/src/server/auth/index.tspreviously logged every caught failure withconsole.errorbefore classifying it. The catch blocks now classify first using the existingtransientAuthErrorFor(error)helper:"Auth backend transient failure:", then throwTransientAuthErroras before.console.debugand returnnullas before.No return values, status codes, or imports changed. The 401
invalid_tokenand 503Retry-After: 5contract inapps/mcp/src/server/index.tsis untouched.Tests
apps/mcp/src/server/auth/index.test.tswas extended: the two transient cases (session 500, timeout) now assert an ERROR-level call under the"Auth backend transient failure:"template, and the rejection cases (wrong audience, expired token, session 401) now assert no ERROR-level output. Existingconsole.errormocks in rejection tests were switched toconsole.debugto suppress noise.Checks run
cd apps/mcp && bun run test:unit(vitest) — passed, 23 tests across 4 files.cd apps/mcp && bun run check-types(tsc for both tsconfigs) — passed.bunx biome check apps/mcp/src/server/auth/index.ts apps/mcp/src/server/auth/index.test.ts— passed, no issues on the touched files.bun run format-lint(Biome, repo root) — reports pre-existing errors/warnings in unrelated files (e.g. a test-runner script withconsole.log/forEachdiagnostics); none originate from the files changed here, confirmed by the scoped Biome run above.Assumptions
"Auth backend transient failure:"was chosen to keep real backend outages queryable and separable from the rejection baseline, matching the plan.Fixes: supermemory-mcp auth rejections: ~20k ERROR rows/6h invisible to metrics and Sentry
What caused this
Affected:
acc_ecd28c165001ayzji6subtuo· severity lowA check caught it, an investigation traced it, an autofix wrote the change. Each step links to its record.
fix_0a1122…This pull request originated from a Polylane autofix. Polylane investigated the issue and delegated the fix to Cursor, which authored this pull request.