Repository navigation
Description
Overview
The daemon currently loads the embedding model (6-8s on first launch) before binding the Unix socket and starting the gRPC server. Any client that connects during startup receives a hard connection failure with no indication of why. The Tauri app has a 30s timeout workaround, but CLI tools and other gRPC clients get no feedback.
Problem Statement
Current startup sequence:
- Initialize NodeService + seed schemas (~100ms)
- Load embedding model (6-8s, blocks everything)
- Bind socket + start gRPC server
- Clients can now connect
During step 2, clients see: `dial unix ~/.nodespace/daemon.sock: connect: no such file or directory`
Expected behavior:
- Socket binds immediately after NodeService init
- gRPC server accepts connections and handles non-NLP RPCs (NodeService, LocalAgentService, etc.) right away
- NLP-dependent RPCs (EmbeddingsService, semantic search) return a `UNAVAILABLE` status with message "embedding model loading, please retry" until the model is ready
- Once loaded, NLP RPCs work normally with no client restart needed
Proposed Solution
Split daemon startup into two phases:
Phase 1 (fast, ~100ms): Initialize NodeService, seed schemas, bind socket, start gRPC server. Register EmbeddingsService with a "loading" state that returns `UNAVAILABLE` until phase 2 completes.
Phase 2 (background task): Load embedding model asynchronously. On completion, swap the EmbeddingsService implementation to the live one (or signal it ready via a watch channel).
This allows the Tauri app, CLI, and any other client to connect immediately and use all non-embedding RPCs while the model loads in the background.
Acceptance Criteria
- gRPC socket is available within 500ms of daemon start
- NodeService, LocalAgentService, ImportService, SettingsService RPCs work immediately after socket appears
- EmbeddingsService RPCs return `UNAVAILABLE` with a descriptive message while the model loads
- EmbeddingsService RPCs work normally once the model finishes loading (no client reconnect needed)
- Tauri app startup timeout can be reduced from 30s back to a reasonable value (e.g. 2s)
- No regression in embedding throughput or accuracy
Technical Specifications
Reference Files
- Daemon startup: `packages/daemon/src/main.rs` — `build_services()` and `serve_grpc()`
- Embedding state: `packages/daemon/src/main.rs` — `build_embedding_state()` (currently blocking)
- EmbeddingsServiceImpl: `packages/daemon/src/services/embeddings_service.rs`
- Tauri timeout: `packages/desktop-app/src-tauri/src/daemon_setup.rs` — `wait_for_daemon()`
Key change
`build_embedding_state()` currently blocks `build_services()`. Move it to a `tokio::spawn` background task that resolves into an `Arc<RwLock<Option>>`. EmbeddingsServiceImpl reads from this lock and returns `UNAVAILABLE` when it's `None`.
Related Issues
- Verify Gemma 4 and Mistral chat-template path on real Apple Silicon hardware (follow-up to #1094) #1142 (discovered during Gemma 4 verification — cold start causes connection failure)
- Fix AI chat viewer and model manager bugs found during Gemma 4 verification #1285 item 6 (daemon startup timeout, partially addressed by extending to 30s — this is the proper fix)
Activity
malibio commentedon Jun 1, 2026
Frontend baseline: 132 test files, 3836 tests passed
Daemon should bind gRPC socket before embedding model loads (#1292)
Daemon should bind gRPC socket before embedding model loads (#1292)