Commit Graph

5 Commits

Author SHA1 Message Date
Pamela Chia
770f1c2b06 fix(aeo): remove ua-based markdown serving (#47770)
## Summary
The `ChatGPT-User` live-fetch agent's user-facing reader hard-fails
(`(400) OK`) on pages we serve it as markdown via user-agent matching,
which made supabase.com blog and product pages unreadable in that
assistant. I root-caused this with a controlled fetch diagnostic
cross-checked against our request logs: the failing fetches never reach
our origin (the failure is cached on their side), pages served as plain
HTML read fine everywhere we tested, and the same failure reproduces on
other major sites that serve UA-matched markdown, so the reader bug is
upstream.

This PR removes user-agent-based markdown serving entirely rather than
special-casing one agent: UA sniffing is a guess about contractless
clients whose fetchers change without notice, and this incident showed
the failure mode is silent (we keep serving 200s while the user-facing
agent breaks). Markdown remains available on every explicit signal —
`Accept: text/markdown` q-value negotiation, explicit `.md` URLs, and
llms.txt — which is the same contract-driven model the Claude fetcher
already uses successfully (it sends `Accept: text/markdown, text/html,
*/*` and keeps receiving markdown after this change).

## Changes
- Remove the `LLM_USER_AGENT` regex and the `userAgent` parameter from
`negotiateMarkdown` in `packages/common/markdown-negotiation.ts`;
decisions now depend only on `Accept`, the `.md` suffix, and the
markdown-variant manifest
- Update both consuming middlewares (`apps/www`, `apps/docs`) to the new
signature; no behavior change for Accept-negotiated or `.md` requests
- Add the missing `Vary: Accept` header to docs guides-md 200 responses
(the www `api-v2/md` route already declares it)
- Fix a pre-existing www bug surfaced in review: explicit changelog
`.md` URLs rewrote to a doubled `.md.md` path (404) under a
markdown-preferring `Accept`, and 406'd on a non-matching `Accept`. The
www middleware now strips the `.md` suffix before slug lookup and passes
`isMarkdownSuffix` into `negotiateMarkdown`, folding the separate
`MD_PAGES` `.md` block into the single negotiation path (same shape as
the docs middleware)
- Rework tests: UA-independence suites replace the per-agent rewrite
tests; a probe Accept header now 406s regardless of user agent
(previously agent UAs were exempt); new changelog `.md` negotiation
coverage

## Testing
Tested locally:
- [x] www middleware suite 36/36, docs middleware suite 17/17
- [x] typecheck green for common, www, docs

Verified on the Vercel previews (www + docs) with curl:
- [x] `ChatGPT-User` and `Claude-User` UA GETs on blog/pricing/guide
pages return `text/html` with a default Accept
- [x] Claude's real Accept (`text/markdown, text/html, */*`) still
returns `text/markdown`; `Accept: text/markdown` and `.md` URLs return
`text/markdown`; probe Accept returns 406
- [x] `/changelog/<slug>.md` with `Accept: text/markdown` returns the
entry markdown as a direct 200 (production today detours through a 308
to the bare URL); changelog index `.md` and bare-entry Accept
negotiation also verified
- [x] docs guides markdown 200s carry `Vary: Accept`

The intermediate commit (ChatGPT-User-only exclusion) was already
verified on the preview: `ChatGPT-User` got HTML while
`Accept`/`.md`/other-UA markdown was unaffected.

Expected effects post-merge: UA-driven markdown volume in the request
logs (~92% of md traffic) collapses to the Accept + `.md` baseline;
named-agent page requests return to prerendered/static serving,
reversing the extra Vercel function invocations the UA rewrite
introduced; user-facing readability in the affected assistant recovers
within ~24h as its fetch cache revalidates. The md-share dashboard gets
a dated annotation; the ratio is not comparable across this change.

## Linear
- fixes GROWTH-973


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Markdown and HTML routing now depends on the request’s `Accept` header
and `.md` links, making content negotiation more predictable.
* Requests that don’t accept available content now consistently return
`406 Not Acceptable`, even for bot-like user agents.
* Guide markdown responses now include an `Accept`-based cache variation
header to improve correct caching behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-10 13:50:34 +08:00
Jeremias Menichelli
575ac8c645 [DOCS-979] feat(Docs): Generate new markdown files for reference pages (#46727)
In this PR:
- The `llms.ts` script is removed from the pipeline. It was just
iterating over the sections of the SDK JSON files to generate _dummy_
text files for LLMS to consume. But with a lot of inconsistencies and
mistakes.
- There's a new script that builds markdown files from the SDK
definition files.
- The Management API now has a definition file too, it was missing
before.
- On the www project now there are redirects for the reference text
files to the new markdown files in the docs project.
- NPM scripts have received better names so that prebuild ones are
smaller and all are easier to differentiate.
2026-06-09 10:39:55 +02:00
Greg Richardson
b539cc0529 feat(docs): return page suggestions in markdown 404 pages (#45439)
Markdown guides (`/docs/guides/**/*.md`) that 404 currently return a
text/plain `Not found` response. Since agents often hallucinate URL
paths, this PR proactively provides page suggestions so that agents can
find the page they are looking forward without further guessing. It uses
the docs Content API to fetch related pages, similar to the [HTML 404
page](https://supabase.com/docs/404):

```
# 404 - Page Not Found

The page `/docs/guides/mcp.md` does not exist.

## You might be looking for...

- [Model context protocol (MCP)](https://supabase.com/docs/guides/getting-started/mcp.md)
- [Building an MCP Server with mcp-lite](https://supabase.com/docs/guides/functions/examples/mcp-server-mcp-lite.md)
- [Model Context Protocol (MCP) Authentication](https://supabase.com/docs/guides/auth/oauth-server/mcp-authentication.md)
- [Deploy MCP servers](https://supabase.com/docs/guides/getting-started/byo-mcp.md)
- [Enabling MCP Server Access](https://supabase.com/docs/guides/self-hosting/enable-mcp.md)

See also: [Changelog](https://supabase.com/changelog.md)
```

## How to test
1. Use curl to fetch a non-existent page with an `.md` extension:

   ```shell
curl -i
https://docs-git-docs-markdown-404-suggestions-supabase.vercel.app/docs/guides/mcp.md
   ```

Confirm that relevant pages are suggested (ballpark - our search algo
needs some improvement). Also confirm that the response has content type
`text/markdown`.

2. Use curl to fetch a non-existent page using the `Accept:
text/markdown` header


   ```shell
   curl -i -H 'Accept: text/markdown' \

https://docs-git-docs-markdown-404-suggestions-supabase.vercel.app/docs/guides/mcp
   ```

    And confirm the same result as 1.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* 404 pages for missing guides now return a formatted Markdown response
with proper content-type and no-cache headers, and include up to five
related documentation suggestions to help users find relevant content.

* **Chores**
* Build environment now preserves an additional hosting URL variable to
improve build/task consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-05 08:40:44 +02:00
Jeremias Menichelli
04d08fbba7 fix(Docs): Add cache-control and default to HTML content (#43989) 2026-03-19 19:45:15 +01:00
Jeremias Menichelli
8b4bf646fc feat(Docs): Add copy as markdown and AI tools to guide (#43355) 2026-03-04 16:31:02 +01:00