Skip to content

fix: prevent profile page hang from slow billing fetch - #1795

Merged
bokelley merged 3 commits into
mainfrom
bokelley/fix-profile-save-hang
Apr 1, 2026
Merged

bokelley merged 3 commits into
mainfrom
bokelley/fix-profile-save-hang

Conversation

@bokelley

@bokelley bokelley commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes escalation #176: Community profile save page hangs indefinitely for member Sami Mokrani (Progmatic Motion). The billing endpoint (/api/organizations/:orgId/billing) makes 3-5 sequential external API calls (WorkOS + Stripe) and was awaited during page load — when any of those hung, the entire page stayed on "Loading your profile..." forever.

  • Page load fix: Move billing fetch to background with 10s abort timeout — form renders immediately
  • Save button fix: Move payload construction inside try/catch so the button can't get stuck at "Saving..."
  • Observability: Slow API call tracking (client + server) with Slack alerts for responses >10s

Changes

File What
profile-edit.html Background billing fetch, save try/catch fix, idempotent populateMemberFields
csrf.js PostHog slow_api_call events for any fetch >3s (including timeouts)
slow-response.ts Express middleware: log warn >3s, Slack alert >10s, rate-limited per endpoint
http.ts Mount slow-response middleware
posthog-query.ts fetchPageDiagnostics utility for ad-hoc page error investigation

Test plan

  • TypeScript compiles clean
  • All 1010 unit tests pass
  • Pre-commit hooks pass (full test suite)
  • Code review: addressed HogQL injection, res.end safety, fetch rejection tracking, cooldown map bounds
  • Security review: addressed all Must Fix and Should Fix findings

🤖 Generated with Claude Code

The community profile edit page awaited the billing endpoint during page
load. That endpoint makes 3-5 sequential external API calls (WorkOS +
Stripe). When any of those hung, the entire page stayed on "Loading your
profile..." forever — the root cause of escalation #176.

Fixes:
- Move billing fetch to background with 10s abort timeout so the page
  renders immediately
- Move save payload construction inside try/catch so the save button
  can never get stuck at "Saving..."
- Make populateMemberFields idempotent for the background billing callback

Observability:
- csrf.js now emits PostHog slow_api_call events when any fetch >3s
  (including timeouts/network errors with status 0)
- New slow-response Express middleware logs warnings for API responses >3s
  and sends Slack alerts to ops channel for responses >10s
- fetchPageDiagnostics utility for ad-hoc PostHog page error queries

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…angeset

- Remove fetchPageDiagnostics (dead code with HogQL injection risk)
- Replace res.end monkey-patch with res.on('finish') (type-safe, no deps)
- Static import for slack client instead of dynamic import per alert
- Remove duplicate member-profile timing middleware (covered by global)
- Fix LIKE wildcard injection (remove % from pathname allowlist)
- Add changeset

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…og path

- populateMemberFields takes populateFormValues param: true on initial
  load, false on background billing callback (avoids overwriting checkbox
  state if user interacted between the two calls)
- Drop raw req.path from log message template, use structured fields only

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@bokelley
bokelley merged commit 1af8a91 into main Apr 1, 2026
11 checks passed
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.

2 participants