Skip to content

fix(api): allow regional API fallback - #1136

Open
arthurauffray wants to merge 2 commits into
PostHog:mainfrom
arthurauffray:fix/eu-oauth-project-fetch
Open

fix(api): allow regional API fallback#1136
arthurauffray wants to merge 2 commits into
PostHog:mainfrom
arthurauffray:fix/eu-oauth-project-fetch

Conversation

@arthurauffray

@arthurauffray arthurauffray commented Aug 24, 2026

Copy link
Copy Markdown

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

  • Shared HTTPS agent
  • IPv6 -> IPv4 fallback: 2s
  • Doctor uses same agent
  • Add regression tests

Test plan

  • Focused Vitest: pass
  • Full suite: 143 files, 2017 tests
  • Live EU OAuth + Doctor: pass

LLM context

Co-authored with GitHub Copilot.

@arthurauffray
arthurauffray marked this pull request as ready for review August 24, 2026 13:44
@arthurauffray
arthurauffray requested a review from a team as a code owner August 24, 2026 13:44
Copilot AI lite review requested due to automatic review settings August 24, 2026 13:44

Copilot AI 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.

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 posthogApiHttpsAgent configured with a longer autoSelectFamilyAttemptTimeout (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.

Comment thread src/lib/api.ts Outdated
Comment on lines +7 to +11
// 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,
});
@sarahxsanders

Copy link
Copy Markdown
Collaborator

@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

@sarahxsanders
sarahxsanders enabled auto-merge (squash) August 31, 2026 18:11
@sarahxsanders

Copy link
Copy Markdown
Collaborator

@arthurauffray you'll need to sign your commit so I can merge!

arthurauffray and others added 2 commits September 1, 2026 08:00
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>
auto-merge was automatically disabled August 31, 2026 20:02

Head branch was pushed to by a user without write access

@arthurauffray
arthurauffray force-pushed the fix/eu-oauth-project-fetch branch from 4fa4e4a to 702b1c0 Compare August 31, 2026 20:02
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.

3 participants