Skip to content

fix(core): handle .md webfetch URLs - #59842

Open
wang1408 wants to merge 5 commits into
anomalyco:devfrom
wang1408:md-url-accept
Open

wang1408 wants to merge 5 commits into
anomalyco:devfrom
wang1408:md-url-accept

Conversation

@wang1408

@wang1408 wang1408 commented Oct 28, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #59822

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Some documentation hosts return 404 when text/markdown is advertised for URLs ending in .md or .markdown. webfetch now sends Accept: */* for either path suffix and keeps its existing negotiation for other URLs.

How did you verify your code works?

  • npm exec --yes --package=bun@1.4.4 -- bun run script/test.ts test/tool-webfetch.test.ts (91 passed)
  • npm exec --yes --package=bun@1.4.4 -- bun typecheck from packages/core (1,737 files across 2 projects)

Visual

<svg xmlns='http://www.w3.org/2000/svg' width='240' height='72' viewBox='0 0 240 72'>
  <style>
    text { fill: currentColor; font: 12px sans-serif; }
    .dot { fill: currentColor; animation: flow 1.6s ease-in-out infinite alternate; }
    @keyframes flow { from { transform: translateX(0); } to { transform: translateX(104px); } }
    @media (prefers-reduced-motion: reduce) { .dot { animation: none; transform: translateX(104px); } }
  </style>
  <rect x='8' y='24' width='76' height='24' rx='6' fill='currentColor' opacity='.08'/>
  <text x='46' y='40' text-anchor='middle' font-size='9'>.md / .markdown</text>
  <path d='M84 36h100' stroke='currentColor' opacity='.25'/>
  <rect x='100' y='26' width='54' height='20' rx='10' fill='currentColor' opacity='.08'/>
  <text x='127' y='39' text-anchor='middle' font-size='10'>Accept */*</text>
  <text x='190' y='40'>Markdown</text>
  <circle class='dot' cx='84' cy='36' r='3'/>
</svg>

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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

The fix works. I ran the #59822 reproduction (a mock model calling webfetch on https://docs.x.ai/grok-bot/security.md) from source on both checkouts. On the base it fails with a 404. With this change it returns the page's markdown. Non-.md URLs behave as before. tool-webfetch.test.ts passes and tsc -b for packages/core is clean.

Public API: unchanged.

The new new URL(url) call is safe, because the requested URL and every redirect target are checked before a request is built. Redirects and the Cloudflare User-Agent retry go through request(), so they use the same Accept rule. One small gap: only .md is handled, not .markdown, which the issue also mentioned. That doesn't block this change.

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

The new commit only merges dev into the branch. The webfetch change and its test are the same as in my last review, and the merge doesn't touch them. On the new head I re-ran the #59822 reproduction from source: https://docs.x.ai/grok-bot/security.md now returns its markdown. tool-webfetch.test.ts passes and tsc -b for packages/core is clean.

Public API: unchanged.

No new concerns.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Oct 29, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

The new commits extend the check to .markdown, which closes the one gap from my first review. The rest of the new diff is a merge of dev. On the new head I re-ran the #59822 reproduction from source: https://docs.x.ai/grok-bot/security.md returns its markdown. tool-webfetch.test.ts passes and tsc -b for packages/core is clean.

Public API: unchanged.

No new concerns.

This branch has not been deployed

No deployments
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.

webfetch: 404 on .md URLs because Accept always advertises text/markdown

1 participant