Repository navigation
fix(onboarding): Connect your AI page is slow to list options on first run - #169472
Conversation
On a fresh profile, setup detection compiled the disposable Apple Foundation Models discovery helper with swiftc -O, and it ran saved sign-in, CLI, and provider-service probes one after another. On a loaded Mac the first openclaw.setup.detect call took 9-10 s, about 7 s of which was the optimizing compile. Compile the throwaway discovery helper without optimization. It only runs `info`; the persistent inference helper built at selection keeps -O. Start provider-owned service discovery alongside saved sign-ins and CLI version probes, still publish local candidates before provider probes finish, and abort sibling probes once discovery fails. Release-note context: the macOS "Connect your AI" page and other setup detection callers list their options several times faster on first run. Detected options are unchanged.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR overlaps independent setup probes and disables optimization for the disposable Apple Foundation Models discovery helper. Example: A fresh Mac requests AI options through openclaw.setup.detect.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR: it addresses measured first-run latency that remains on current main, preserves discovery contracts, and introduces no actionable defect found in review. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe shared setup detector receives configuration and provider metadata, probes saved sign-ins, installed CLIs, and local providers, then returns AI choices to native onboarding, Control UI, and CLI callers. flowchart TD
A[Setup clients] --> B[Shared setup detector]
B --> C[Saved sign-ins]
B --> D[CLI discovery]
B --> E[Provider discovery]
E --> F[Disposable Apple helper]
C --> G[Filtered setup choices]
D --> G
E --> G
Technical reviewBest possible solution: Land the focused discovery optimization after the normal merge gates pass. Do we have a high-confidence way to reproduce the issue? Current main shows the serial probes and optimized disposable compilation; the PR reports controlled Gateway reproductions, but this read-only review executed no target code. Is this the best way to solve the issue? The change targets the measured costs at their existing owners while preserving filtering, timeout behavior, persistent-helper optimization, and configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4c53998c762c. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +35, Tests +89. Total +124 across 4 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 11, 2026, 8:19 PM ET / October 12, 2026, 00:19 UTC. |
|
@clawsweeper approve |
|
|
|
Merged via squash.
|
…t run (openclaw#169472) * fix(onboarding): show AI setup options faster on fresh Macs On a fresh profile, setup detection compiled the disposable Apple Foundation Models discovery helper with swiftc -O, and it ran saved sign-in, CLI, and provider-service probes one after another. On a loaded Mac the first openclaw.setup.detect call took 9-10 s, about 7 s of which was the optimizing compile. Compile the throwaway discovery helper without optimization. It only runs `info`; the persistent inference helper built at selection keeps -O. Start provider-owned service discovery alongside saved sign-ins and CLI version probes, still publish local candidates before provider probes finish, and abort sibling probes once discovery fails. Release-note context: the macOS "Connect your AI" page and other setup detection callers list their options several times faster on first run. Detected options are unchanged. * fix(onboarding): report provider discovery failures without waiting for CLI probes
What Problem This Solves
Fixes: on a fresh Mac, the onboarding "Connect your AI" page waits 4–10 seconds before it lists any options, because the first Gateway setup detection (
openclaw.setup.detect) is slow.User Impact
User impact: on a loaded Mac, the first setup detection now returns in about 1.6–3.5 s (was 3.8–10 s), and repeat detections take about 1.1–1.9 s (was 2.8–4 s). The detected options are unchanged. This applies to every caller of setup detection: the macOS app, Control UI model setup, and the CLI.
Why This Change Was Made
Measuring an isolated app-hosted Gateway showed that about 7 s of a 9.1 s cold detection was spent in the Apple Foundation Models discovery probe, which compiles a throwaway Swift helper with
swiftc -O. The probe only runsinfoand then deletes the binary. It now compiles with-Onone, which takes 0.55–0.7 s instead of 2.3–3.3 s when run on its own. The persistent helper built when someone selects Apple Foundation Models still compiles with-O.Detection also ran saved sign-ins, CLI version probes, and provider-owned service probes (Apple Foundation Models, LM Studio, Ollama, llama.cpp) one after another. Provider discovery now runs alongside the other two. Local candidates are still published before provider probes finish, so the existing 30 s deadline fallback still includes them. A failure in either branch ends detection immediately and aborts the remaining probes.
Accepted cost: each detection still compiles the disposable helper (now roughly 0.6–2 s, depending on load). Reusing it across calls would mean managing a temporary binary for the lifetime of the process, so I left that out on purpose. The remaining fixed cost is mostly the synchronous plugin load for provider discovery (about 0.5–0.9 s).
Evidence
Real entry point, run the way the app runs it: the bundled Bun fork and SQLite from OpenClaw.app, started with
openclaw.mjs gateway run --port <random>. Each run used a freshOPENCLAW_STATE_DIRunder$(getconf DARWIN_USER_TEMP_DIR), token auth, the app's PATH and the stdin lifeline.openclaw.setup.detectwas called right after/readyz. Durations are the server-side[ws] restimes. Host: 32-core Mac Studio under heavy shared load.Baseline cold-call breakdown (temporary instrumentation, not committed): Apple Foundation Models probe 7.7 s, of which 6.9 s was compiling. Provider plugin load 0.93 s, saved sign-ins 0.25 s, local-model HTTP probes about 0.3 s, CLI version probes 0.08 s.
Alternating A/B,
mainat a020759 vs this branch, 5 pairs, load average 26–51. Pairs 4–5 ran on the final head, after the review fix:mainEarlier runs at load average 32–41:
maincold calls took 10.4 s and 9.1 s; this PR's cold call took 3.5 s. The instrumented run showed the CLI probes finishing while provider plugins were still loading, and the Apple Foundation Models compile dropping from 6.9 s to 1.9 s.Identical results: every A/B response matches its pair partner once the per-run workspace path and the intentionally random Claude/Codex order are normalized. Pairs 1–3 detected Claude Code, Codex, Apple Foundation Models and Ollama. The local Ollama server stopped answering before pairs 4–5, so both arms of those pairs detected the first three.
Tests (no real timers):
pnpm test src/system-agent/setup-inference-detect.test.ts src/system-agent/setup-inference-detect.lifecycle.test.ts --maxWorkers=1: 14 + 2 passed in 57.4 s wall across 2 shards. The test bodies take milliseconds; the rest is transform and import.pnpm test extensions/apple-fm/native.test.ts extensions/apple-fm/index.test.ts --maxWorkers=1: 14 passed in 55.5 s wall.pnpm tsgo:core,pnpm tsgo:extensions, the system-agent test project typecheck, oxlint and oxfmt are clean.Codex autoreview found that a provider-discovery failure waited for the local probes; fixed with a regression test.
Release-note context: the macOS "Connect your AI" onboarding page and other setup-detection callers list their AI options several times faster on first run, and the options offered are unchanged.