Skip to content

fix(onboarding): Connect your AI page is slow to list options on first run - #169472

Merged
steipete merged 2 commits into
mainfrom
steipete/suspicious-meitner-089e9d
Oct 12, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/suspicious-meitner-089e9d

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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 runs info and 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 fresh OPENCLAW_STATE_DIR under $(getconf DARWIN_USER_TEMP_DIR), token auth, the app's PATH and the stdin lifeline. openclaw.setup.detect was called right after /readyz. Durations are the server-side [ws] res times. 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, main at a020759 vs this branch, 5 pairs, load average 26–51. Pairs 4–5 ran on the final head, after the review fix:

    cold call second call
    main 6.0 / 4.0 / 3.8 / 6.0 / 4.7 s 4.0 / 2.8 / 3.0 / 3.5 / 2.9 s
    this PR 3.5 / 2.0 / 2.1 / 2.0 / 1.6 s 1.2 / 1.1 / 1.3 / 1.3 / 1.9 s

    Earlier runs at load average 32–41: main cold 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.
    • The new tests add about 25 ms of test time and no new files or fixtures. All three new concurrency tests time out against the previous serial code.
  • 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 12, 2026 00:13
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The final reported baseline pair took 4.7 seconds to return options.
  • After: The corresponding PR run took 1.6 seconds and returned equivalent options.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused implementation with meaningful regression coverage and reported production-entry-point measurements; runtime results were supplied by the author rather than independently rerun.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The complete body supplies app-hosted Gateway RPC measurements on a loaded Mac, including final-head A/B pairs and equivalent detected choices; these exercise the changed discovery owner through openclaw.setup.detect.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Fresh Mac onboarding waits several seconds before showing available AI options.
Reason: Measured improvement serves every shared detector caller without adding settings or changing offered choices; maintainer authorship supplies direction.

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
Reviewed head: 4ba004ae24a126246e7bdf6155be077dbb0e0fe0

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

  • Apple Foundation Models discovery compilation changes intended behavior with a stated reason (0352277: Background discovery must establish native eligibility without installing an inference helper or changing configuration.)
  • Setup discovery sequencing and partial results changes intended behavior with a stated reason (496433f: Saved sign-ins remain available for retry and partial discovery while provider eligibility remains enforced; the PR explains why independent probes can overlap.)
  • Provider callback lifetime keeps the original intent (05a2844: Accepted probes retain their supplying plugin instances through callback completion and cleanup.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 0352277 adds extensions/apple-fm/native.ts:124 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 035227797aa6; files: extensions/apple-fm/native.ts)

PR surface

Source +35, Tests +89. Total +124 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 121 86 +35
Tests 2 100 11 +89
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 221 97 +124

Review metrics

Metric Value Why it matters
Production versus test changes Production +121/-86; tests +100/-11 Production growth separates concurrent discovery from result assembly; tests cover overlapping probes, prompt failure propagation, cancellation signaling, and compiler-mode separation.

Labels

Label changes:

  • add P2: A measured, recoverable onboarding delay warrants a focused performance improvement without emergency priority.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A measured, recoverable onboarding delay warrants a focused performance improvement without emergency priority.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 11, 2026, 8:19 PM ET / October 12, 2026, 00:19 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper approve

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

@clawsweeper approve is retired; ClawSweeper now only reviews.

@steipete steipete self-assigned this Oct 12, 2026
@steipete
steipete merged commit 656287c into main Oct 12, 2026
192 of 193 checks passed
@steipete
steipete deleted the steipete/suspicious-meitner-089e9d branch October 12, 2026 00:45
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: apple-fm P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant