Skip to content

fix(content): keep a webhook's 2xx as sent when the rest of its answer doesn't arrive in time - #1668

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/webhook-2xx-at-time-limit
Oct 28, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/webhook-2xx-at-time-limit

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up from #1605 (item 1): a webhook's 2xx counts as sent even when the rest of its answer doesn't arrive in time.

A webhook that sent 200 and part of its answer, then nothing more, was reported as a timeout. The time limit's abort reached the request's error handler before the answer's, so postJson rejected with timeout even though the status had arrived. A content send was marked failed, and a task send was reported as refused.

postJson now remembers when the status has arrived. An error the request hears after that (the time limit, or the connection dropping) ends the answer with what was read of it.

  • A 3xx, 4xx or 5xx that arrives before the time limit is now reported as that status ("the webhook returned 503"), not as a timeout.
  • All four callers (content delivery, webhook dispatch, and the content route's bulk, single and test sends) check for 2xx themselves.

docs/api-reference/webhooks.mdx: the Delivery line says so.

Where people see it: a page sent to a slow webhook stays "sent".

Related issue

Follow-up from #1605's review.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

cd server && npx vitest run src/lib/safe-post.test.js. The new test fails on main: a 200 that stalls past a 100 ms limit.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Full checks were run once, in one tree with this batch's ten follow-up branches merged:

  • server format, lint and npm test: 246 files, 3,343 tests passed;
  • web format, lint (0 errors; 7 warnings already on main), typecheck and build: all pass;
  • web vitest: 4,348 of 4,349 tests passed. The editor's page.test.tsx timed out under load; it passed alone (271/271).

A pre-push review was run on all ten branches.

🤖 Generated with Claude Code

…r doesn't arrive in time

Follow-up from ansvisor#1605 (item 1). A webhook that sends 200 and part of its
answer, then nothing more, was reported as a timeout: the time limit's
abort reaches the request's error handler before the answer's, so
postJson rejected with `timeout` though the status had arrived. A send
was marked failed, and a task send reported as refused.

postJson now remembers once the status has arrived; an error the request
hears after that (the time limit, the connection dropping) ends that
answer with what was read of it. The docs' Delivery line says so.

The new test fails on main: a 200 that stalls past a 100 ms limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 28, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit e0f058d.

Approve preview

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, with follow-ups.

What I checked:

  • Merge. One commit (e0f058d) on 3f6a4d4. It merges clean on main (b591947), alone and together with #1672 and #1673. None of the files it touches changed on main since its base.
  • The fix. answered is set at the end of the response callback, so it's only set once the status has arrived. After that, any request error (the time limit, a reset) resolves with done(), which keeps the first result and what was read. Before the status arrives, nothing changes: our own PageFetchErrors, timeout and unreachable are reported as before.
  • Callers.
    • Send to CMS (content-delivery.js) and webhook dispatch (webhook-dispatch.js) count only a 2xx as delivered, so a 4xx or 5xx that stalls is now "the webhook answered 503" rather than "took too long".
    • The webhook test reports the status it got, with success only for a 2xx.
    • The opportunity sends (/bulk/send-webhook and /:id/send-webhook) only turn away a 3xx; see follow-up 1.
  • Tests.
    • At the head, the safe-post, content-webhooks, content-delivery and webhook-dispatch tests pass (79).
    • With main's safe-post.js under the head's tests, the new /stalled test fails, as described.
    • CI passes.
  • Docs. The Delivery line matches what postJson now does.
  • Before the API deploy. This is server only. Nothing changes for anyone until the API is deployed.
  • Speed. No regex and no loop over user input.

Follow-ups:

  1. The description says all callers check for 2xx, but the opportunity sends don't (server/src/routes/content.js, bulk and single send-webhook). They mark any answer except a 3xx as sent. Before this PR, a 4xx or 5xx whose answer stalled past 15 s was a timeout, so the opportunity stayed unsent. Now it's marked sent. That's rare and comes from the existing gap #1672 notes. A follow-up that fails a non-2xx there, as Send to CMS does, covers both. Please also fix that sentence in the description.

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.

2 participants