Skip to content

fix(api): stop expected 4xx outcomes from opening error issues - #2709

Merged
Makisuo merged 4 commits into
mainfrom
triage/api-error-noise
Nov 16, 2026
Merged

Makisuo merged 4 commits into
mainfrom
triage/api-error-noise

Conversation

@Makisuo

@Makisuo Makisuo commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What

Three expected client outcomes in maple-api were exporting as Error spans and opening error issues:

  • Saved view name taken. The service already answered 409 (SavedViewNameTakenError), but it found out by letting the INSERT hit saved_views_owner_surface_name_unq, so the DB span failed with 23505 and became a DatabaseError issue. Create now inserts with ON 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 with error=), e.g. an oversized /register body. 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.ts as API_ANTICIPATED_ERROR_IDENTIFIERS, passed to WorkerTelemetry. 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 answer SavedViewNameTakenError).
  • tsrs --noEmit on apps/api and packages/backend, plus oxlint -c .oxlintrc.effect.json on 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", TransitionConflictError on UPDATE investigations.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Devin Review

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.
@maple-review-bot

This comment has been minimized.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 91460042-1b3c-4c02-98ff-3722d84fd68f
Commits

Reviewing files that changed from the base of the PR and between 4748c8a and 82d47fe.

Files selected for processing: 5

  • apps/api/src/telemetry-options.ts
  • apps/api/src/worker-bridge.test.ts
  • apps/api/src/worker.ts
  • packages/backend/src/services/saved-views/SavedViewsService.test.ts
  • packages/backend/src/services/saved-views/SavedViewsService.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@maple-review-bot maple-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 inline note from Maple's review. The score and summary are in the review comment above.

updatedAt: now,
})
// A taken name is an answer, not a failed statement: no row comes back.
.onConflictDoNothing()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-bot

maple-review-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

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.
no findings · tests covered · risk medium · 1/1 new units observable

Stops three expected 4xx outcomes from exporting as Error spans: saved-view creates insert with ON CONFLICT DO NOTHING, renames check the name first, and the api's telemetry options anticipate McpOAuthProtocolError and TransitionConflictError. Safe to merge.

  • create inserts with onConflictDoNothing; no row back answers SavedViewNameTakenError
  • update reads for a name clash before writing, 23505 mapping kept as the race fallback
  • apiTelemetryOptions adds two backend tags to the anticipated 4xx set
  • Bridge and saved-views tests pin both behaviors

82d47fe · What was checked, coverage and telemetry details are on the Maple / review check. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.

@Makisuo
Makisuo merged commit 650c8d2 into main Nov 16, 2026
36 checks passed
@Makisuo
Makisuo deleted the triage/api-error-noise branch November 16, 2026 16:43
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.

1 participant