Skip to content

fix: suppress benign supabase stale-refresh-token exceptions#19

Draft
posthog[bot] wants to merge 4 commits into
mainfrom
posthog-code/suppress-supabase-refresh-token-noise
Draft

fix: suppress benign supabase stale-refresh-token exceptions#19
posthog[bot] wants to merge 4 commits into
mainfrom
posthog-code/suppress-supabase-refresh-token-noise

Conversation

@posthog

@posthog posthog Bot commented Jul 22, 2026

Copy link
Copy Markdown

What changed

The before_send sanitizer in apps/postshow/src/lib/analytics.ts now drops $exception events whose exception list contains an AuthApiError with an "Invalid Refresh Token" message, before they reach PostHog. Added a unit test covering both the dropped case and that ordinary errors still pass through.

Why

supabase-js is created with autoRefreshToken: true, so it runs a background timer that rotates the session token. When a user's stored refresh token is stale (signed out in another tab, cleared storage, or an already-expired session), that background refresh throws an uncaught AuthApiError. Because capture_exceptions: true is set, exception autocapture files this expected auth condition as an error, cluttering error tracking. Our own getSession() path already handles auth failures gracefully; this closes the one background path we never wrapped so this class of benign event stops burying real errors.

Verification

  • pnpm --filter @eventools/postshow test — 325 passed (includes the new suppression test)
  • pnpm type-check
  • pnpm lint

Safety and release impact

Client-only analytics change; no credentials, tenancy, or outbound behavior affected. The suppression is narrowly scoped to AuthApiError + "Invalid Refresh Token", so real errors continue to be captured.

  • Connector access remains read-only unless the user explicitly approves a supported outbound action.
  • Credentials and private source records do not enter model prompts or hosted paths that are not explicitly documented.
  • Local-only and tenant boundaries remain intact.
  • Human approval still gates every outbound action.
  • New dependencies and redistributed assets have compatible licenses and preserved notices.
  • Tests, documentation, and package metadata cover the changed behavior.
  • The change contains no credentials, customer data, generated build output, or unrelated edits.

Created with PostHog Code from this inbox report.

supabase-js's background auto-refresh timer throws an uncaught AuthApiError
when the stored refresh token is stale (signed out elsewhere, cleared
storage, or an expired session). With capture_exceptions enabled, PostHog's
exception autocapture files that expected auth event as an error.

Drop it in the existing before_send sanitizer: $exception events whose
exception list contains an AuthApiError with an "Invalid Refresh Token"
message are no longer captured.

Generated-By: PostHog Code
Task-Id: 46aad295-db02-4e45-8291-aaa650e8c801
@netlify

netlify Bot commented Jul 22, 2026

Copy link
Copy Markdown

Deploy Preview for postshow failed. Why did it fail? →

Name Link
🔨 Latest commit bc21873
🔍 Latest deploy log https://app.netlify.com/projects/postshow/deploys/6a60c495b5d6880008b32d88

@posthog posthog Bot changed the title Suppress benign supabase stale-refresh-token exceptions fix: suppress benign supabase stale-refresh-token exceptions Jul 22, 2026
posthog Bot added 3 commits July 22, 2026 12:51
Harden the stale-refresh-token suppression so it also recognizes the error
when a capture path populates the flat $exception_types / $exception_values
convenience arrays instead of the structured $exception_list. Scope is
unchanged — still only AuthApiError with an "Invalid Refresh Token" message.

Generated-By: PostHog Code
Task-Id: 46aad295-db02-4e45-8291-aaa650e8c801
Generated-By: PostHog Code
Task-Id: 46aad295-db02-4e45-8291-aaa650e8c801
…-noise

Generated-By: PostHog Code
Task-Id: 46aad295-db02-4e45-8291-aaa650e8c801
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