AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(platform): fix prod Sentry errors and reduce on-call alert noise (#12560)
## Summary Hotfix targeting master for production Sentry errors that are triggering on-call pages. Fixes actual bugs and expands Sentry filters to suppress user-caused errors that are not platform issues. ### Bug Fixes - **Workspace race condition** (`get_or_create_workspace`): Replaced Prisma's non-atomic `upsert` with find-then-create pattern. Prisma's upsert translates to SELECT + INSERT (not PostgreSQL's native `INSERT ... ON CONFLICT`), causing `UniqueViolationError` when concurrent requests hit for the same user (e.g. copilot + file upload simultaneously). - **ChatSidebar crash**: Added null-safe `?.` for `sessions` which can be `undefined` during error/loading states, preventing `TypeError: Cannot read properties of undefined (reading 'length')`. - **UsageLimits crash**: Added null-safe `?.` for `usage.daily`/`usage.weekly` which can be `undefined` when the API returns partial data, preventing `TypeError: Cannot read properties of undefined (reading 'limit')`. ### Sentry Filter Improvements Expanded backend `_before_send` to stop user-caused errors from reaching Sentry and triggering on-call alerts: - **Consolidated auth keywords** into a shared `_USER_AUTH_KEYWORDS` list used by both exception-based and log-based filters (previously duplicated). - **Added missing auth keywords**: `"unauthorized"`, `"bad credentials"`, `"insufficient authentication scopes"` — these were leaking through. - **Added user integration HTTP error filter**: `"http 401 error"`, `"http 403 error"`, `"http 404 error"` — catches `BlockUnknownError` and `HTTPClientError` from user integrations (expired GitHub tokens, wrong Airtable IDs, etc.). - **Fixed log-based event gap**: User auth errors logged via `logger.error()` (not raised as exceptions) were bypassing the `exc_info` filter. Now the same `_USER_AUTH_KEYWORDS` list is checked against log messages too. ## On-Call Alerts Addressed ### Fixed (actual bugs) | Alert | Issue | Root Cause | |-------|-------|------------| | `Unique constraint failed on the fields: (userId)` | [AUTOGPT-SERVER-8BM](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-8BM) | Prisma upsert race condition | | `Unique constraint failed on the fields: (userId)` | [AUTOGPT-SERVER-8BK](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-8BK) | Same — via `/api/workspace/files/upload` | | `Unique constraint failed on the fields: (userId)` | [AUTOGPT-SERVER-8BN](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-8BN) | Same — via `tools/call run_block` | | `Upload failed (500): Unique constraint failed` | [BUILDER-7GA](https://significant-gravitas.sentry.io/issues/BUILDER-7GA) | Frontend surface of same workspace bug | | `Cannot read properties of undefined (reading 'length')` | [BUILDER-7GD](https://significant-gravitas.sentry.io/issues/BUILDER-7GD) | `sessions` undefined in ChatSidebar | | `Cannot read properties of undefined (reading 'limit')` | [BUILDER-7GB](https://significant-gravitas.sentry.io/issues/BUILDER-7GB) | `usage.daily` undefined in UsageLimits | ### Filtered (user-caused, not platform bugs) | Alert | Issue | Why it's not a platform bug | |-------|-------|-----------------------------| | `Anthropic API error: invalid x-api-key` | [AUTOGPT-SERVER-8B6](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-8B6), 8B7, 8B8 | User provided invalid Anthropic API key | | `AI condition evaluation failed: Incorrect API key` | [AUTOGPT-SERVER-83Y](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-83Y) | User's OpenAI key is wrong (4.5K events, 1 user) | | `GithubListIssuesBlock: HTTP 401 Bad credentials` | [AUTOGPT-SERVER-8BF](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-8BF) | User's GitHub token expired | | `HTTPClientError: HTTP 401 Unauthorized` | [AUTOGPT-SERVER-8BG](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-8BG) | Same — credential check endpoint | | `GithubReadIssueBlock: HTTP 401 Bad credentials` | [AUTOGPT-SERVER-8BH](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-8BH) | Same — different block | | `AirtableCreateBaseBlock: HTTP 404 MODEL_ID_NOT_FOUND` | [AUTOGPT-SERVER-8BC](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-8BC) | User's Airtable model ID is wrong | ### Not addressed in this PR | Alert | Issue | Reason | |-------|-------|--------| | `Unexpected token '<', "<html><hea"...` | [BUILDER-7GC](https://significant-gravitas.sentry.io/issues/BUILDER-7GC) | Transient — backend briefly returned HTML error page | | `undefined is not an object (activeResponse.state)` | [BUILDER-71J](https://significant-gravitas.sentry.io/issues/BUILDER-71J) | Bug in Vercel AI SDK `[email protected]`, already resolved | | `Last Tool Output is needed` | [AUTOGPT-SERVER-72T](https://significant-gravitas.sentry.io/issues/AUTOGPT-SERVER-72T) | User graph misconfiguration (1 user, 21 events) | | `Cannot set property ethereum` | [BUILDER-7G6](https://significant-gravitas.sentry.io/issues/BUILDER-7G6) | Browser wallet extension conflict | | `File already exists at path` | [BUILDER-7FS](https://significant-gravitas.sentry.io/issues/BUILDER-7FS) | Expected 409 conflict | ## Test plan - [ ] Verify workspace creation works for new users - [ ] Verify concurrent workspace access (e.g. copilot + file upload) doesn't error - [ ] Verify copilot ChatSidebar and UsageLimits load correctly when API returns partial/error data - [ ] Verify user auth errors (invalid API keys, expired tokens) no longer appear in Sentry after deployment
Z
Zamil Majdy committed
85f0d8353ae4db1cbd55fb23ad7d8e82cdd1223b
Parent: 866563a
Committed by GitHub <[email protected]>
on 3/25/2026, 4:25:32 PM