Repository navigation
Daemon should bind gRPC socket before embedding model loads - #1292
Conversation
Split daemon startup into two phases: - Phase 1 (~100ms): init NodeService, seed schemas, build all gRPC handlers, bind socket — clients can connect immediately - Phase 2 (background tokio::spawn): load NLP model; once ready, populate Arc<RwLock<Option<EmbeddingReady>>> shared by EmbeddingsServiceImpl and NodeServiceImpl While the model loads, EmbeddingsService RPCs return UNAVAILABLE with "embedding model loading, please retry". Once loaded, they work normally — no client reconnect needed. Key changes: - build_services() returns (ServiceBundle, Option<JoinHandle>) and no longer blocks on nlp.initialize() - EmbeddingReady struct holds (NodeEmbeddingService, EmbeddingProcessor) behind Arc<RwLock<Option<_>>> shared by both service impls - NodeService.embedding_waker changed from Option<EmbeddingWaker> to Arc<OnceLock<EmbeddingWaker>> so the waker can be set from the bg task after NodeService is Arc-wrapped - Tauri daemon startup timeout reduced from 30s to 2s Co-Authored-By: Claude <[email protected]>
Code Review — PR #1292: Daemon should bind gRPC socket before embedding model loadsSummaryThis is a well-executed, targeted refactor. The two-phase startup split is the right architectural approach: Phase 1 establishes the socket and all non-NLP services in ~100ms, while Phase 2 loads the heavy NLP model in a background task. The All acceptance criteria from issue #1287 are met. This is a net positive change and is safe to merge with the one improvement noted below addressed. Findings[Improvement]
|
malibio
left a comment
There was a problem hiding this comment.
Review verdict: REQUEST CHANGES. Two improvements should be addressed before merge - see the detailed review comment above.
…bedding - Use tokio::task::spawn_blocking for EmbeddingService::new + initialize (~6-8s sync CPU/IO) so the tokio worker pool isn't blocked during the window when the gRPC server is accepting its first connections - GraphContextAssembler now holds Arc<RwLock<Option<Arc<NodeEmbeddingService>>>> instead of Option<Arc<NodeEmbeddingService>>. The background load task populates it (via embedding_svc_state) once the model is ready, so agent sessions that start after model load get semantic context enrichment Co-Authored-By: Claude <[email protected]>
- Add comment on get_stale_count clarifying it queries DB directly (no model required) to prevent future reviewers adding a spurious state check - Add comments on _bg_task drops explaining tokio's detach-on-drop semantics - Add comment on EmbeddingsService registration noting it's absent until daemon restart when no model file is present at startup - Increase Tauri socket-wait timeout 2s → 5s for slow-disk margin; still 6x better than the previous 30s that blocked on model load Co-Authored-By: Claude <[email protected]>
Review ResponseAll findings addressed: ✅ Addressed (from prior commit eb57cd4):
✅ Addressed (this commit 953cc96):
Skipped: None — all recommendations were addressed. |
* Bind gRPC socket before embedding model loads (closes #1287) Split daemon startup into two phases: - Phase 1 (~100ms): init NodeService, seed schemas, build all gRPC handlers, bind socket — clients can connect immediately - Phase 2 (background tokio::spawn): load NLP model; once ready, populate Arc<RwLock<Option<EmbeddingReady>>> shared by EmbeddingsServiceImpl and NodeServiceImpl While the model loads, EmbeddingsService RPCs return UNAVAILABLE with "embedding model loading, please retry". Once loaded, they work normally — no client reconnect needed. Key changes: - build_services() returns (ServiceBundle, Option<JoinHandle>) and no longer blocks on nlp.initialize() - EmbeddingReady struct holds (NodeEmbeddingService, EmbeddingProcessor) behind Arc<RwLock<Option<_>>> shared by both service impls - NodeService.embedding_waker changed from Option<EmbeddingWaker> to Arc<OnceLock<EmbeddingWaker>> so the waker can be set from the bg task after NodeService is Arc-wrapped - Tauri daemon startup timeout reduced from 30s to 2s Co-Authored-By: Claude <[email protected]> * Address review: spawn_blocking for model load; assembler gets live embedding - Use tokio::task::spawn_blocking for EmbeddingService::new + initialize (~6-8s sync CPU/IO) so the tokio worker pool isn't blocked during the window when the gRPC server is accepting its first connections - GraphContextAssembler now holds Arc<RwLock<Option<Arc<NodeEmbeddingService>>>> instead of Option<Arc<NodeEmbeddingService>>. The background load task populates it (via embedding_svc_state) once the model is ready, so agent sessions that start after model load get semantic context enrichment Co-Authored-By: Claude <[email protected]> * Address review nits: comments, timeout margin - Add comment on get_stale_count clarifying it queries DB directly (no model required) to prevent future reviewers adding a spurious state check - Add comments on _bg_task drops explaining tokio's detach-on-drop semantics - Add comment on EmbeddingsService registration noting it's absent until daemon restart when no model file is present at startup - Increase Tauri socket-wait timeout 2s → 5s for slow-disk margin; still 6x better than the previous 30s that blocked on model load Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Closes #1287