fix(md-exports): Return 200 for agent not-found pages so the body survives#18287
Merged
Conversation
…vives
The .md catch-all serves a Markdown "page not found" helper that links to real
nearby pages so AI agents can self-correct. It was returned with HTTP 404, but
agent fetchers — including Claude Code's WebFetch (User-Agent "Claude-User") —
discard the response body on any non-2xx status. The agent received "0 bytes"
instead of the recovery content, turning a guessed URL into a dead end.
Return 200 so the body reaches the agent. The not-found signal is preserved in
the body ("# Page Not Found"), the response is marked X-Robots-Tag: noindex so
crawlers don't treat it as real content, and X-Sentry-Docs-Not-Found lets
monitoring still distinguish soft misses from genuine hits.
Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Emit docs.md_export.not_found when the agent-facing .md catch-all serves a soft-404. Attributes capture the full invented path, the normalized agent (claude/gptbot/…, via the same matchPattern convention as tracesSampler), and whether recovery suggestions were available — so we can see which agents make up which URLs most and surface content gaps. The full path is kept on the metric on purpose: trace metrics are EAP-backed, so high-cardinality attributes are fine, and an agent-invented not-found path is a public docs-namespace path, not user PII. Co-Authored-By: Claude <noreply@anthropic.com>
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
.mdcatch-all (app/md-exports/[...path]/route.ts) serves a Markdown "page not found" helper that links to real nearby pages so AI agents can recover from a wrong URL. It was returned as HTTP 404 — but agent fetchers, including Claude Code's WebFetch (User-AgentClaude-User), discard the response body on any non-2xx status. The agent received "0 bytes" instead of the recovery content, so a guessed URL became a dead end even though the server had useful Markdown to hand back.This returns the helper with HTTP
200so the body reaches the agent, and adds a metric so we can see which agents invent which URLs.Behavior change
Before/after for a non-existent page fetched as Markdown (e.g.
/platforms/javascript/guides/vercel-edge.md):The body is unchanged — same "Page Not Found" heading and the same list of real sibling pages.
Not-found is still detectable
X-Robots-Tag: noindexkeeps crawlers from treating the soft-200 as real content, andX-Sentry-Docs-Not-Found: 1lets monitoring distinguish these soft misses from genuine hits even though the status is now 200. This only affects the agent-facing.mdroute; the HTML route still returns a true 404.Metric: which agents make up which URLs
Adds
DocMetrics.mdExportNotFound→ emitsdocs.md_export.not_foundwith attributes:requested_path— the full invented path (the signal we want). Kept in full because trace metrics are EAP-backed (high cardinality is fine) and an agent-invented docs path isn't PII.agent— normalized agent name (claude,gptbot, …) via the samematchPattern(ua, AI_AGENT_PATTERN)convention used intracesSampler.ts;otherwhen unmatched.has_suggestions— whether the soft-404 had sibling pages to offer.IS YOUR CHANGE URGENT?