Fix stale PostgREST schema cache breaking subscriptions + snapshot sync#75
Merged
Merged
Conversation
The 20260526+ migration batch (subscription_tiers, user_subscriptions, lap_snapshots, account_deletions + RPCs) was applied to Postgres but PostgREST kept serving a stale schema cache. Since the REST API backs both the client and the edge functions' service-role queries, those objects were invisible over REST — breaking checkout (non-2xx), lap-snapshot sync, and the snapshot usage meter, while Stripe price loading (no PostgREST) still worked. Add a migration that issues `notify pgrst, 'reload schema'` so the cache reloads on deploy (and last in sequence on a fresh DB). Also harden two failure modes the incident exposed: document and snapshot auto-sync now reconcile independently, and the Profile snapshot panel no longer blanks when its best-effort usage meter can't load. https://claude.ai/code/session_017wyJik7iHRfxTKeuKFc4Xs
Coverage SummaryLines: 35.53% (2397/6745) · Statements: 34.58% · Functions: 28.94% · Branches: 36.16% Per-file coverage
|
The auto-upload of local snapshots is wired through autoSync's reconcile on app boot / sign-in, but a reconcile that fails (e.g. the schema-cache outage) is swallowed and never retried in the same session, leaving local snapshots stuck off the cloud. Have the Lap snapshots panel re-run reconcileSnapshots when it opens and refresh live on snapshot-store changes, so viewing the panel uploads any local-only snapshots without an app reload. https://claude.ai/code/session_017wyJik7iHRfxTKeuKFc4Xs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three beta function-test failures — checkout returning a non-2xx, lap snapshots not syncing on sign-in, and the Profile snapshot panel showing
Could not find the function public.snapshot_usage ... in the schema cache— all traced to a single root cause: a stale PostgREST schema cache.The
20260526+migration batch (subscription_tiers,user_subscriptions,lap_snapshots,account_deletions+ their RPCs) was applied to Postgres, but PostgREST kept serving a cached schema that predated it. Because the REST API backs both the client (.rpc()/.from()) and the edge functions' service-role.from()calls, every object in that batch was invisible over REST while existing in the database:create-checkout-session→from('subscription_tiers')cache-miss → null row →400 Unknown tier(non-2xx)listCloudSnapshots→from('lap_snapshots')cache-miss →reconcileSnapshotsthrows (swallowed to console)snapshot_usage()RPC → cache-miss → the exact "schema cache" error in the panelstripe-priceskept working precisely because it's pure Stripe API and never touches PostgREST — which is the tell.Changes
20260530000000_reload_postgrest_schema.sql— issuesnotify pgrst, 'reload schema'. Runs last in sequence, so a fresh DB reloads after the whole batch is created, and deploying it to an already-migrated DB reloads the existing-but-uncached objects. This is the actual fix.autoSync.ts— document and snapshot reconcile now run in independent try/catch blocks, so a failure in one (missing table, quota rejection) no longer silently skips the other.LapSnapshotsPanel.tsx— the usage meter is now best-effort: if it can't load, the snapshot list stays usable instead of the whole panel blanking to a raw error.CHANGELOG.md— entries under[Unreleased] → Fixed.Operational note
Editing migrations only affects future applies. To unblock the currently-deployed beta DB immediately (without waiting for this migration to deploy), run once in the SQL editor:
notify pgrst, 'reload schema';Test plan
npm run lintcleannpm run typecheckcleannpm run test:run— 737 passedselect to_regclass('public.lap_snapshots')is non-null andsnapshot_usage()is callable over RESThttps://claude.ai/code/session_017wyJik7iHRfxTKeuKFc4Xs
Generated by Claude Code