fix(api): allow regional API fallback - #1136
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the wizard’s PostHog API transport to be more resilient to dual-stack (IPv6→IPv4) connection fallback timing issues that can occur after OAuth, by introducing and reusing a shared HTTPS agent across key API calls (including Doctor), and adding regression tests to lock the behavior in.
Changes:
- Introduces a shared
posthogApiHttpsAgentconfigured with a longerautoSelectFamilyAttemptTimeout(2s) for PostHog API requests. - Applies the shared agent to multiple PostHog REST calls and the Doctor health issues fetch.
- Adds regression tests asserting the shared agent is attached to outbound requests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/lib/programs/posthog-doctor/fetch.ts | Uses the shared PostHog API HTTPS agent for Doctor health issue requests. |
| src/lib/programs/posthog-doctor/tests/fetch.test.ts | Adds a regression test asserting the Doctor request includes the agent with the expected fallback timeout. |
| src/lib/api.ts | Defines the shared HTTPS agent and wires it into several PostHog REST fetch helpers. |
| src/lib/tests/api-transport.test.ts | Adds a regression test asserting API transport requests include the agent with the expected fallback timeout. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Node defaults to 250ms between IPv6 and IPv4 connection attempts, which is | ||
| // too short for some regional PostHog API connections after OAuth completes. | ||
| export const posthogApiHttpsAgent = new Agent({ | ||
| autoSelectFamilyAttemptTimeout: 2_000, | ||
| }); |
|
@arthurauffray thanks again for opening a PR for this!!! pushed my commit to raise the timeout globally so every call gets it including the one that crashed for you :) gonna merge shortly once CI is green |
|
@arthurauffray you'll need to sign your commit so I can merge! |
Move the IPv6-to-IPv4 fallback timeout from per-request https agents to a single process-wide setting. The per-request agents only covered four axios calls, so `detectRegion` in src/utils/urls.ts still failed first, along with the oauth, provisioning and MCP profile calls. Setting the Node default covers every client in the process, including posthog-node, the agent SDK and MCP. Replaces the two mock-based tests, which asserted the config object was passed rather than that the timeout changed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Head branch was pushed to by a user without write access
4fa4e4a to
702b1c0
Compare
Problem
Regional API calls can die before HTTP response after OAuth.
(Couldn't use the posthog wizard at all on my computer, eu cloud)
Changes
Test plan
LLM context
Co-authored with GitHub Copilot.