Skip to content

fix(sentry): keep malformed search entity refs out of Sentry - #936

Merged
kody-bot merged 1 commit into
mainfrom
cursor/sentry-triage-7631143592-2394
Jul 25, 2026
Merged

kody-bot merged 1 commit into
mainfrom
cursor/sentry-triage-7631143592-2394

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Jul 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Sentry issue 7631143592 (Error: All entity lookups failed. in runSearchTool) was fired when an agent batch-looked-up entities with malformed refs (or other caller-input parse failures). parseEntityRef / parseValueEntityId threw plain Error, so the entity-batch path treated every failure as a platform incident and reported a synthetic All entity lookups failed. exception.

This continues the #919 / #922 McpCallerError carve-out: bad entity ref / value-entity format is a caller mistake and stays on the mcp-event log line. Genuine platform batch failures still reach Sentry, now with per-entity failure context + an AggregateError cause so triage is not blind.

Changes

  • Throw McpCallerError from parseEntityRef and parseValueEntityId
  • On total entity-batch failure, log entityFailures context; for non-caller failures, chain an AggregateError under the synthetic cause
  • Tests for malformed refs (unit + batch handler path)

Risk / merge

Low (composes): observability attribution only; agent-facing error text unchanged. Platform batch failures still report to Sentry.

Siblings

  • Prefetched validation issue 7631582437 (Provide "query", "entity", or "domain") does not share this root cause — that path already sets callerError: true (event was from a pre-#919 release).
  • Timeout events previously fingerprint-grouped under this issue, and sibling 7631797267, are separate.
System recap — composes existing primitives (low risk)

Mode: recap · Base: main @ 42d211e0 · Head: e22f04b7

Classification: composes — reuses the existing McpCallerError / callerError observability carve-out; no new primitives, no contract change to search results beyond Sentry attribution.

Primitives touched

Primitive Group Impact
mcp-server surfaces composes — marks malformed entity refs as caller errors; richer batch failure context for real platform fails

System map

Malformed search({ entity }) refs are attributed as caller mistakes so they stay off Sentry; platform batch failures still alert with per-entity detail.

Legend: green = composes (wiring only) · amber = extended by this PR · red = new primitive · gray = context (unchanged, included only when an edge crosses it).

flowchart LR
  Agent["Agent / MCP client"] --> Search["search tool<br/>entity batch"]
  Search --> Parse["parseEntityRef /<br/>parseValueEntityId"]
  Parse -->|bad input| CallerErr["McpCallerError<br/>callerError=true"]
  Parse -->|ok| Resolve["resolveEntityDetail"]
  Resolve -->|not found| CallerErr
  Resolve -->|platform fail| Platform["Sentry exception<br/>+ entityFailures"]
  CallerErr --> Log["mcp-event log only"]
  Platform --> Sentry["Sentry"]

  classDef composes fill:#d4edda,stroke:#28a745,color:#000
  classDef context fill:#f1f3f5,stroke:#868e96,color:#000
  class Search,Parse,CallerErr,Log,Platform composes
  class Agent,Resolve,Sentry context
Loading

Invariants

  • Per-user isolation: unchanged (entity lookup still scoped by userId).
  • No auth / billing / migration / DR surface.

Risk notes

  • Low: only changes which failures are reported to Sentry and what context they carry. Agent-visible error strings for malformed refs are unchanged.
  • Remaining true platform batch failures (e.g. D1 read mid-batch) still open Sentry issues by design.

Docs

  • No doc updates required (internal observability attribution).
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes

    • Invalid entity references now return clear caller errors for malformed formats, unsupported types, and invalid value scopes.
    • Entity batch failures now distinguish invalid requests from platform or lookup failures.
    • Batch error reporting includes details for each failed entity lookup.
  • Tests

    • Added coverage for validation errors and mixed entity-batch failure scenarios.
    • Improved verification of aggregated failure reporting and error classifications.

parseEntityRef and parseValueEntityId threw plain Errors for bad agent
input, so all-failed entity batches were reported to Sentry as platform
bugs (issue 7631143592). Throw McpCallerError instead, and attach
per-entity failure context when a batch still fails for platform reasons.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Search entity parsers now classify invalid references as McpCallerError. Entity-batch handling records per-reference failure metadata and aggregates platform failures for Sentry reporting, with tests covering malformed inputs and backend failures.

Changes

MCP search error handling

Layer / File(s) Summary
Entity reference validation
packages/worker/src/mcp/tools/search-entities.ts, packages/worker/src/mcp/tools/search-format-helpers.ts, packages/worker/src/mcp/tools/*test.ts
Parsing failures now throw McpCallerError, with tests covering malformed formats, unsupported types or scopes, empty names, and decoding errors.
Entity-batch failure reporting
packages/worker/src/mcp/tools/search-tool-runner.ts, packages/worker/src/mcp/tools/search-handler.node.test.ts
Batch failures now include per-entity error metadata, caller-error classification, and aggregated platform failure causes in Sentry events.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preventing malformed search entity reference errors from being reported to Sentry.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/sentry-triage-7631143592-2394

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

Comment @coderabbitai help to get the list of available commands.

@cursor
cursor Bot marked this pull request as ready for review July 25, 2026 14:55
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-936.kody-a99.workers.dev

Worker: kody-pr-936
D1: kody-pr-936-db
KV: kody-pr-936-oauth-kv

Mocks:

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/worker/src/mcp/tools/search-handler.node.test.ts`:
- Line 742: Update the error assertion for runSearchTool to match the nested
error contract: assert the logged outer Error first, then verify its cause is an
AggregateError rather than expecting the logged value itself to be an
AggregateError.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f6ea605d-01ad-447a-a2b2-7de553f1b0df

📥 Commits

Reviewing files that changed from the base of the PR and between 42d211e and e22f04b.

📒 Files selected for processing (6)
  • packages/worker/src/mcp/tools/search-detail.node.test.ts
  • packages/worker/src/mcp/tools/search-entities.ts
  • packages/worker/src/mcp/tools/search-format-helpers.ts
  • packages/worker/src/mcp/tools/search-format.node.test.ts
  • packages/worker/src/mcp/tools/search-handler.node.test.ts
  • packages/worker/src/mcp/tools/search-tool-runner.ts

errorName: 'EntityBatchError',
cause: expect.objectContaining({
message: 'All entity lookups failed.',
cause: expect.any(AggregateError),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Match the nested AggregateError contract.

runSearchTool logs an outer Error whose .cause is the AggregateError; this direct assertion will fail.

Proposed fix
-				cause: expect.any(AggregateError),
+				cause: expect.objectContaining({
+					cause: expect.any(AggregateError),
+				}),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cause: expect.any(AggregateError),
cause: expect.objectContaining({
cause: expect.any(AggregateError),
}),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/worker/src/mcp/tools/search-handler.node.test.ts` at line 742,
Update the error assertion for runSearchTool to match the nested error contract:
assert the logged outer Error first, then verify its cause is an AggregateError
rather than expecting the logged value itself to be an AggregateError.

@kody-bot
kody-bot merged commit 7d88928 into main Jul 25, 2026
8 checks passed
@kody-bot
kody-bot deleted the cursor/sentry-triage-7631143592-2394 branch July 25, 2026 15:03
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.

3 participants