Skip to content

fix(ci): don't crash non-interactive run when early auth blips#940

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/ci-early-auth-graceful-degrade
Draft

fix(ci): don't crash non-interactive run when early auth blips#940
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/ci-early-auth-graceful-degrade

Conversation

@posthog

@posthog posthog Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

In CI / non-interactive mode with an API key but no --project-id, the eager authenticate() call in scopeInstallDirToProject routes through fetchProjectDataWithApiKeyfetchUserData to derive the project id. That call was not guarded: any failure other than 401/403/404 (a network blip, timeout, or 5xx) surfaced as the literal ApiError: Failed to fetch user data and propagated up through authenticatescopeInstallDirToProjectciPreRun, killing the whole run.

This is a recent regression: the early authenticate() was moved onto the ciPreRun critical path, which made a transient user-lookup blip fatal. It also broke scopeInstallDirToProject's own documented contract — "every failure leaves the session untouched" — since the auth line was the one unguarded failure in the function. There's a telling asymmetry too: the parallel best-effort user fetch in the CI branch of getOrAskForProjectData is already wrapped in try/catch and swallowed, but this path wasn't.

Changes

Wrap the early authenticate() in scopeInstallDirToProject in try/catch. On failure it captures the exception, fires an auth-failed agentic-detection outcome (keeping the "exactly one outcome per run" telemetry invariant), warns, and continues with the install dir as-is.

The real auth is retried at bootstrap (bootstrap.ts calls authenticate again), so a transient blip no longer kills the run, while a persistent failure still aborts there — at the true critical point. Users could previously only work around this by passing --project-id.

Test plan

  • New unit test in project-scope.test.ts covering the auth-failure path: session untouched, no flag fetch, no scan, auth-failed outcome fired, exception reported.
  • pnpm build, full project-scope suite (11 tests) passing, pnpm lint clean (0 errors).

Created with PostHog Code from this inbox report.

The eager `authenticate()` call in `scopeInstallDirToProject` (added when it
moved onto the ciPreRun critical path) was the only unguarded failure in a
function whose contract is "every failure leaves the session untouched". A
transient user/project lookup failure (network blip, 5xx) there surfaced as
"Failed to fetch user data" and aborted the whole CI/non-interactive run.

Wrap the early auth in try/catch: on failure, warn, fire an `auth-failed`
agentic-detection outcome, and continue with the install dir as-is. The real
auth is retried at bootstrap, so a persistent failure still aborts there — at
the true critical point — while a transient blip no longer kills the run.

Generated-By: PostHog Code
Task-Id: 276512c1-4267-4c07-bb74-f169af2787e8
@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci mcp-analytics
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

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