Repository navigation
fix(api): stop expected 4xx outcomes from opening error issues - #2709
Conversation
A saved view whose name is taken now inserts with ON CONFLICT DO NOTHING and pre-checks a rename, so the name check never shows up as a failed INSERT. McpOAuthProtocolError (always an OAuth 400) and TransitionConflictError (a lost transition race, always remapped or caught) join the api's anticipated errors, so spans failing only with them export Ok instead of opening issues.
This comment has been minimized.
This comment has been minimized.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
| updatedAt: now, | ||
| }) | ||
| // A taken name is an answer, not a failed statement: no row comes back. | ||
| .onConflictDoNothing() |
There was a problem hiding this comment.
Warning
onConflictDoNothing on saved-view create is not pinned by any test
F1 · Warning · tests
The duplicate-name tests (SavedViewsService.test.ts:250, :252) only assert the 409 tag, which the removed 23505 mapping produced too. Dropping line 273 or the rename pre-check leaves every test green, so nothing catches the failed DatabaseError span and its error issue coming back.
Add a service test that runs the duplicate create and the rename under a tracer and asserts no finished span carries `error.type` `@maple/backend/platform/DatabaseLive` error, like `McpOAuthService.test.ts:360`.
🤖 Prompt to fix with an AI agent
In `packages/backend/src/services/saved-views/SavedViewsService.ts:273`: `onConflictDoNothing` on saved-view create is not pinned by any test.
The duplicate-name tests (`SavedViewsService.test.ts:250`, `:252`) only assert the 409 tag, which the removed 23505 mapping produced too. Dropping line 273 or the rename pre-check leaves every test green, so nothing catches the failed `DatabaseError` span and its error issue coming back.
Suggested fix: Add a service test that runs the duplicate create and the rename under a tracer and asserts no finished span carries `error.type` `@maple/backend/platform/DatabaseLive` error, like `McpOAuthService.test.ts:360`.
Verify the problem exists at that location before changing it, and keep the fix to those lines.
There was a problem hiding this comment.
Fixed: new test runs the duplicate create and rename under a tracer and asserts only the SavedViewsService call spans fail. Verified it fails when onConflictDoNothing is removed.
Maple review🟢 Confidence 10/10 · safe to merge. Both behavior changes are pinned by new tests: the real-error bridge test and the tracer test that fails whenever the insert hits the unique index. Stops three expected 4xx outcomes from exporting as Error spans: saved-view creates insert with
|
What
Three expected client outcomes in maple-api were exporting as Error spans and opening error issues:
SavedViewNameTakenError), but it found out by letting the INSERT hitsaved_views_owner_surface_name_unq, so the DB span failed with 23505 and became aDatabaseErrorissue. Create now inserts withON CONFLICT DO NOTHING(no row back means the name is taken), and a rename checks the name first. The unique-violation mapping stays as the fallback for a rename race.McpOAuthProtocolError. Every one is rendered as an OAuth 400 (or a redirect witherror=), e.g. an oversized/registerbody. It is a backend class, so it was not in the domain's generated 4xx list.TransitionConflictError. A guarded transition that lost its race. Every caller remaps it to a 409 or catches it as a no-op.The last two go in
apps/api/src/telemetry-options.tsasAPI_ANTICIPATED_ERROR_IDENTIFIERS, passed toWorkerTelemetry. They are string literals so the backend classes stay off the init path. The bridge test builds real instances, so a renamed tag fails the test.Verification
apps/api/src/worker-bridge.test.ts: new test "a backend failure the api answers as a 4xx never exports as an Error span". It runs a request whose inner span fails with each error through alchemy's bridge with the api's real telemetry options, and asserts that no exported span has status Error. I removed each identifier from the list in turn and the test failed both times.packages/backend/src/services/saved-views/SavedViewsService.test.ts: 13/13, including the existing "refuses a second view of the same name" test (create and rename still answerSavedViewNameTakenError).tsrs --noEmitonapps/apiandpackages/backend, plusoxlint -c .oxlintrc.effect.jsonon the touched files: clean.Error issues this covers (seen in previews pr-2642, pr-2563 and pr-2310; the same paths run in production): saved_views 23505
DatabaseError,McpOAuthProtocolError"Request body is too large",TransitionConflictErroronUPDATE investigations.🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.