Skip to content

Add request timeout + explicit error state to WhatsApp HTTP helpers#11

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/whatsapp-sync-request-timeout
Draft

Add request timeout + explicit error state to WhatsApp HTTP helpers#11
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/whatsapp-sync-request-timeout

Conversation

@posthog

@posthog posthog Bot commented Jun 29, 2026

Copy link
Copy Markdown

Why

Users setting up WhatsApp hit dead-ends on the "Sync from Meta" import path: the action does nothing or hangs on an indefinite spinner, so flows/templates never appear. The report traces this through the helper scripts that mirror the same Meta/Platform API surface, and names the root-cause class directly: lib/request.mjs (metaProxyRequest) and lib/http.js "have no timeout or error state, so a slow or failed Meta call spins forever."

That's literally true here — both helpers issued a bare fetch with no timeout. They back every flow/template/data-endpoint script an agent runs, including the chat-assistant recovery path one blocked user fell back on. So the same hang-forever failure exists on the agent-tooling surface, and is fixable in this repo.

What changed

  • lib/http.js / lib/request.mjs: bound each request with an AbortController. Default 30s, override via KAPSO_HTTP_TIMEOUT_MS. On timeout the CJS helper throws a RequestError (status 408, { timedOut: true }) and the ESM helper returns { ok: false, status: 408, timedOut: true } with a clear message — so a slow/hung Meta call surfaces an actionable error instead of spinning forever. Happy-path behavior is unchanged.
  • SKILL.md: document KAPSO_HTTP_TIMEOUT_MS; sharpen troubleshooting so a blank/preview-URL flow preview maps to a missing data endpoint (with a get-data-endpoint.js check), and note that scoped list-flows/list-templates return empty on a mismatched phone_number_id/WABA rather than erroring.

Verification

  • Timeout path: against a server that accepts the connection but never responds, both helpers abort at the configured timeout with a 408 timedOut error (verified ~800ms with KAPSO_HTTP_TIMEOUT_MS=800); the process exits cleanly (no dangling timer).
  • Happy path: normal 200 JSON responses still parse and return as before.
  • npm run validate and npm run check:syntax pass.

Scope / honest limitation

The button, Flows/Templates pages, blank preview, and Inbox composer the affected users actually saw live in the Kapso web-app/platform repos, not here — this change does not by itself alter that browser behavior. It hardens the agent/CLI surface (the documented workaround + chat-assistant recovery path) against the same root cause and gives those tools a clear, bounded error instead of an indefinite hang. The web-app "Sync from Meta" handler still needs the equivalent timeout + success/error UI states, and the error-tracking instrumentation the report calls for, in the platform repo.


Created with PostHog Code from an inbox report.

The shared HTTP helpers (lib/http.js, lib/request.mjs metaProxyRequest) used by
every flow/template/data-endpoint script issued a bare fetch with no timeout, so
a slow or hung Meta/Platform call left the script spinning forever with no
feedback — the agent-tooling analog of the "Sync from Meta" hang.

Bound each request with an AbortController (default 30s, override via
KAPSO_HTTP_TIMEOUT_MS). On timeout the CJS helper throws a RequestError with
status 408 and { timedOut: true }, and the ESM helper returns
{ ok: false, status: 408, timedOut: true } with a clear message, so callers
surface an actionable error instead of hanging.

Also sharpen the integrate-whatsapp SKILL troubleshooting: blank/preview-URL
flow previews map to a missing data endpoint, scoped listings return empty on a
mismatched phone_number_id/WABA, and document the new timeout behavior.

paths:
  plugins/kapso/skills/integrate-whatsapp/scripts/lib/http.js
  plugins/kapso/skills/integrate-whatsapp/scripts/lib/request.mjs
  plugins/kapso/skills/integrate-whatsapp/SKILL.md

Generated-By: PostHog Code
Task-Id: a2dfd3bf-2074-49b4-8ae8-150079840501
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.

0 participants