Skip to content

Daemon should bind gRPC socket before embedding model loads #1287

Closed

Description

@malibio

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:

  1. Initialize NodeService + seed schemas (~100ms)
  2. Load embedding model (6-8s, blocks everything)
  3. Bind socket + start gRPC server
  4. 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

Activity

  1. malibio commented on Jun 1, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 132 test files, 3836 tests passed

  2. self-assigned this
    on Jun 1, 2026
  3. added a commit that references this issue on Jun 2, 2026
    32e944a
  4. added a commit that references this issue on Jun 22, 2026
    b861778
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions