Skip to content

fix(llm): Serve Markdown to recognized AI agents again, whatever their Accept header - #20991

Merged
sergical merged 2 commits into
masterfrom
fix/agent-markdown-ua-wins
Nov 28, 2026
Merged

sergical merged 2 commits into
masterfrom
fix/agent-markdown-ua-wins

Conversation

@sergical

@sergical sergical commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Stacked on #20990. Merge that one first; GitHub then retargets this PR to master.

DESCRIBE YOUR PR

Since #20930 went live on Nov 24, ChatGPT-User and PerplexityBot get HTML from docs instead of Markdown. Both send a browser's Accept header, and #20930 made an Accept that prefers HTML win over the user agent. Now a recognized AI agent (AI_AGENT_PATTERN, the same list as before #20930) gets Markdown whatever its Accept header says, which is what sentry.io and the blog already do (static-sites packages/www-astro/middleware.ts). Every other client keeps #20930's quality-value rule.

shouldServeMarkdown(accept, isAIAgent)
  before:  formatPreference(accept) == 'none' ? isAIAgent : formatPreference(accept) == 'markdown'
  after:   isAIAgent || formatPreference(accept) == 'markdown'

Why this goes against Vercel's guidance. Vercel's Markdown and Agent Discovery page says "A recognized AI agent receives HTML when it requests text/html", and #20930 followed it. But the two biggest AI fetchers on docs ask for HTML in every request (from the Middleware request processed logs, last 2 days):

Agent Accept it sends Requests
ChatGPT-User text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,… 8,936, all HTML
PerplexityBot text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 1,234, all HTML

ChatGPT-User makes about 4,400 docs requests a day. Vercel request logs for ChatGPT-User on Nov 24 (UTC, page URLs), with #20930 live from 21:14:

Hour Markdown HTML
19:00 202 37
20:00 219 28
21:00 51 160
22:00 2 227
23:00 0 175

In-app browsers keep #20990's fix. The Claude and Cursor desktop apps and Gemini iOS put the app name in their user agent (Claude/6.28899.6 Chrome/…, Cursor/3.32.4 Chrome/… Electron/…, GeminiiOS/…), so they match AI_AGENT_PATTERN. Since the user agent now wins over Accept, a page load in those apps would get Markdown too, not just the background fetch #20990 fixed. So those user agents are recognized as in-app browsers and never treated as agents, and any request marked Sec-Fetch-Dest: empty (the router's background fetch) stays exempt as in #20990. Sec-Fetch-Dest: document is not used as a browser signal, because PerplexityBot sends it on every request.

Vary: Accept, User-Agent on Markdown served from a page URL, since the user agent now picks the format. The Markdown "page not found" reply sets it itself: on production it had no Accept in Vary at all, because the route's response replaces the middleware's. Direct .md URLs keep Vary: Accept; their content doesn't depend on either header, and adding User-Agent would split their cache by browser version.

Checked on the preview (/platforms/javascript/):

Request Production Preview
ChatGPT-User, browser Accept text/html text/markdown, Vary: Accept, User-Agent
PerplexityBot, browser Accept, Sec-Fetch-Dest: document text/markdown, Vary: Accept, User-Agent
Chrome page load text/html
No AI user agent, Accept: text/markdown text/markdown, Vary: Accept, User-Agent
Claude app router fetch (RSC: 1, Accept: */*, Sec-Fetch-Dest: empty) text/x-component (page data)
Claude app page load (browser Accept, Sec-Fetch-Dest: document) text/html
Missing page, Accept: text/markdown (/platforms/apple/cocoa/) Vary without Accept Vary: Accept, User-Agent added

Tests: the updated content-negotiation and middleware tests (agent asking for HTML gets Markdown, Vary: Accept, User-Agent) fail on the old rule and pass now. The "asks for HTML" test now covers ChatGPT-User and PerplexityBot with their real headers, and the in-app browser test covers both the page load and the link-click fetch.

Special things to note

  • Any client whose user agent matches AI_AGENT_PATTERN gets Markdown on page URLs, even with Accept: text/html only, unless it's one of the in-app browsers or sends Sec-Fetch-Dest: empty. The pattern is broad (claude|cursor|gemini|openai|…); narrowing it to named bots, as static-sites and the changelog do, is a separate change.
  • The in-app browser list is three apps seen in the docs logs. Another app whose user agent matches AI_AGENT_PATTERN would get Markdown on page loads; the new secFetchDest log field shows which browsers hit this.

Created with Claude Opus 5.5 in Claude Code.

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.
Select exactly one option. For deadlines, replace YYYY-MM-DD with the due date. You can update this information later by editing the PR description.

  • Urgent deadline (GA date, etc.): YYYY-MM-DD
  • Other deadline: YYYY-MM-DD
  • No deadline: Not urgent, can wait up to 1 week+

SLA

  • Teamwork makes the dream work, so please add a reviewer to your PRs.
  • Please give the docs team up to 1 week to review your PR unless you've supplied a deadline.

Thanks in advance for your help!

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
develop-docs Ready Ready Preview Nov 28, 2026 12:10am UTC
sentry-docs Ready Ready Preview Nov 28, 2026 12:10am UTC

Request Review

@github-actions github-actions Bot added the Priority: Normal Docs review has no urgent deadline label Nov 27, 2026
@codeowner-assignment
codeowner-assignment Bot requested a review from a team November 27, 2026 04:00
@cursor

cursor Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Getting ready to monitor this change · Rollout details

Status Service Environment
⏳ Getting ready to monitor this change

Base automatically changed from fix/agent-markdown-misses to master November 28, 2026 00:04
sergical and others added 2 commits November 27, 2026 19:04
…t header

ChatGPT-User and PerplexityBot send a browser's Accept header, so since #20930
they got HTML. A recognized AI agent now gets Markdown again, matching sentry.io
and the blog. Requests a browser marks Sec-Fetch-Dest: document or empty are not
treated as agents, so in-app browsers keep getting normal pages. Negotiated
Markdown responses set Vary: Accept, User-Agent.

Co-authored-by: Claude <claude@anthropic.com>
…ocument

PerplexityBot sends Sec-Fetch-Dest: document, so that check kept it on HTML.
Recognize the Claude, Cursor and Gemini apps by user agent instead, and keep
the Sec-Fetch-Dest: empty check for the router's background fetch. The
Markdown not-found reply now sets its own Vary, since middleware's is lost.

Co-authored-by: Claude <claude@anthropic.com>
@sergical
sergical force-pushed the fix/agent-markdown-ua-wins branch from ccf083c to 7cd0067 Compare November 28, 2026 00:04
@sergical
sergical enabled stacked auto-merge (squash) November 28, 2026 00:04
@codeowner-assignment
codeowner-assignment Bot requested a review from a team November 28, 2026 00:04
@sergical
sergical merged commit 87d893d into master Nov 28, 2026
32 checks passed
@sergical
sergical deleted the fix/agent-markdown-ua-wins branch November 28, 2026 00:10

This branch was successfully deployed

2 active deployments
Preview – sentry-docs — 7cd0067a Deployed Nov 28, 2026 by vercel[bot]
Preview – develop-docs — 7cd0067a Deployed Nov 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Normal Docs review has no urgent deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants