Skip to content

perf(init): run org detection in background during preamble#443

Draft
MathurAditya724 wants to merge 2 commits intomainfrom
fix/init-speed
Draft

perf(init): run org detection in background during preamble#443
MathurAditya724 wants to merge 2 commits intomainfrom
fix/init-speed

Conversation

@MathurAditya724
Copy link
Member

Summary

  • Starts DSN scanning (resolveOrg) and org-list fetching (listOrganizations) concurrently with the sentry init preamble phase (experimental confirm + git status check), so results are ready when the wizard later needs the org for project creation.
  • On a cold start (no DSN cache), this eliminates 2-5 seconds of blocking latency that previously occurred deep inside the wizard's suspend/resume loop at createSentryProjectresolveOrgSlug.
  • When the org is already explicit (e.g., sentry init acme/my-app), background detection is skipped entirely.

How it works

Before:
  init → preamble (user confirms) → wizard starts → ... → create-sentry-project
    → resolveOrgSlug → resolveOrg (DSN scan, 2-5s) → listOrganizations (300ms)

After:
  init → [bg: resolveOrg + listOrganizations] → preamble (user confirms) → wizard starts → ...
    → create-sentry-project → resolveOrgSlug → await bg results (already settled, ~0ms)

Changes

File Change
src/lib/init/types.ts New BgOrgDetection type with pre-started promise fields
src/commands/init.ts Fire background detection before runWizard() when org is unknown
src/lib/init/local-ops.ts resolveOrgSlug() accepts optional BgOrgDetection to use pre-fetched results
test/commands/init.test.ts 7 new tests verifying background detection is passed/omitted correctly

Risk

Low. Background promises are .catch()-wrapped — if they fail, the existing synchronous path runs as a fallback. No behavioral change for the user; only latency improvement.

Start DSN scanning and org-list fetching concurrently with the
preamble user-interaction phase (experimental confirm + git status
check) so the results are already available when the wizard later
needs to resolve the org for project creation.

On a cold start (no DSN cache), this eliminates 2-5s of blocking
latency that previously occurred deep inside the wizard's
suspend/resume loop.

The background promises are .catch()-wrapped so failures fall back
to the existing synchronous path. When the org is already explicit
(e.g., `sentry init acme/my-app`), background detection is skipped
entirely.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Internal Changes 🔧

  • (init) Run org detection in background during preamble by MathurAditya724 in #443

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

Codecov Results 📊

111 passed | Total: 111 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1101 uncovered lines.
✅ Project coverage is 95.09%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.09%    95.09%        —%
==========================================
  Files          165       166        +1
  Lines        22424     22444       +20
  Branches         0         0         —
==========================================
+ Hits         21324     21343       +19
- Misses        1100      1101        +1
- Partials         0         0         —

Generated by Codecov Action

Replace the BgOrgDetection type and promise-threading through
WizardOptions with a simpler warm/consume prefetch module.

init.ts calls warmOrgDetection() to start background work, and
local-ops.ts transparently consumes the cached results via
resolveOrgPrefetched() and listOrgsPrefetched() — no plumbing
needed between the two.
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.

1 participant