Repository navigation
Add SettingsService gRPC: daemon config via RPC, delete switch_database (closes #1138) - #1161
Conversation
…se (closes #1138) - Add settings_service.proto with GetDaemonConfig/UpdateDaemonConfig RPCs - Implement SettingsServiceImpl reading/writing ~/.nodespace/daemon.toml - Register SettingsService in nodespaced (headless and tray modes) - Add SettingsServiceClient to Tauri GrpcClient - Rewrite commands/settings.rs: daemon config fetched via gRPC, display prefs (theme, render_markdown) remain in Tauri local storage - Delete AppServices::switch_database() and all hot-swap code - Remove savedDatabasePath from settings store (replaced by gRPC config) - Update database-settings UI: path changes now persist via gRPC, restart required instead of in-process hot-swap - Clean up dead event listeners (database-changed) from app-shell Co-Authored-By: Claude <[email protected]>
Code Review SummaryThis PR is a well-scoped, architecturally sound implementation of the SettingsService gRPC layer. The core design — daemon owns config, Tauri owns display prefs, hot-swap code deleted — is the correct model under ADR-031 and every acceptance criterion is met. The cleanup is thorough: the switch_database hot-swap machinery (Tauri command, AppServices method, all callers, database-changed event listener) is fully removed with no orphaned references found. The code is clean, well-commented, and consistent with the established gRPC service pattern across this codebase. There is one functional correctness issue worth addressing and one design issue that should at least be documented. Findings[Improvement] Concurrent write hazard in update_daemon_config — settings_service.rs, lines 90–103The UpdateDaemonConfig handler does a read-modify-write across two separate async I/O operations with no locking: let mut config = self.read_config().await?; // I/O #1
// ... mutate config ...
self.write_config(&config).await?; // I/O #2Two concurrent RPCs (e.g., two frontend windows both changing settings) can interleave: both read the same config, both apply their respective mutation, and the second write silently discards the first mutation. For a single-user desktop app this is low probability today, but Recommended fix: add a pub struct SettingsServiceImpl {
config_path: PathBuf,
write_lock: tokio::sync::Mutex<()>,
}
// In update_daemon_config:
let _guard = self.write_lock.lock().await;
let mut config = self.read_config().await?;
// mutate ...
self.write_config(&config).await?;[Improvement] Tauri in-process GrpcClient creates a second SettingsServiceImpl — grpc_client.rs, line 90–91The in-process Tauri gRPC server (for the embedded runtime) creates its own This is a pre-existing architectural tension (the in-process gRPC server is a migration artifact) and the issue description acknowledges // NOTE: This SettingsServiceImpl reads/writes the same ~/.nodespace/daemon.toml
// as a standalone nodespaced process. The in-process server is a migration artifact
// (see grpc_client.rs module doc); once nodespaced fully replaces it, this
// duplicate instantiation is removed.
let settings_impl = SettingsServiceImpl::with_default_path()
.map_err(|e| GrpcClientError::InvalidEndpoint(e))?;[Improvement] database-settings.svelte: restartRequired flag is not surfaced to the user on the "Change Location" pathIn This is not a blocker since both paths call the same Tauri command and both paths ultimately persist via gRPC, but the UX inconsistency could confuse users who change the DB path from Settings and don't see the restart advisory. Nitpicks
Acceptance Criteria Verification
VerdictApprove with recommendations. The concurrent write hazard in |
- Add Mutex to SettingsServiceImpl to serialize read-modify-write in update_daemon_config, preventing interleaved concurrent RPCs from silently discarding each other's writes - Show restart-required notice in database-settings.svelte after path changes (previously only surfaced via menu path / status bar) - Fix redundant_closure clippy lint in grpc_client.rs Co-Authored-By: Claude <[email protected]>
Review Feedback Addressed✅ Fixed: Concurrent write hazard in ✅ Fixed: Missing restart advisory in database-settings.svelte — Settings panel now shows a restart-required notice after path changes (previously only visible via the menu path / status bar). ✅ Fixed: ⏭️ Skipped: Dual-writer comment on in-process SettingsServiceImpl — Migration-era artifact; will disappear when Tauri connects to a real ⏭️ Skipped: ⏭️ Skipped: |
…ettings-service-grpc # Conflicts: # packages/daemon/build.rs # packages/daemon/src/lib.rs # packages/daemon/src/main.rs # packages/desktop-app/src-tauri/src/commands/settings.rs # packages/desktop-app/src-tauri/src/lib.rs # packages/desktop-app/src-tauri/src/services/grpc_client.rs
LocalAgentServiceServer was accidentally dropped in ea8849a (PR #1161, Add SettingsService) when the diff removed it while adding SettingsService. This caused ListModels, EnsureModelReady, StartSession, and all other LocalAgent RPCs to return Unimplemented for 13 days. Also clones node_service before ImportServiceImpl::new() consumes it, matching the original pattern from PR #1160. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
partially) ## Completed in This Session - [x] Verified issue #1142: Gemma 4 E4B downloads, loads, and streams tokens without ffi error -1 - [x] Found root cause: Gemma 4 tool-call parsing was broken — model emits <|tool_call> special tokens but old code used token_to_piece(special=false) which silently dropped them - [x] Fixed tool-call parsing: replaced custom StreamingToolCallParser + sentinel detection with ChatParseStateOaicompat (llama.cpp native streaming parser, handles Gemma 4 natively via COMMON_CHAT_FORMAT_PEG_GEMMA4 PEG grammar) - [x] Confirmed fix works: agent_loop logs show tool_calls=1 per inference round (was 0 before) - [x] Restored LocalAgentServiceServer registration in daemon main.rs (accidentally dropped in PR #1161 ea8849a when SettingsService was added — missing for 13 days) - [x] Committed and pushed: 3a4efd6 (parser fix), 443bad0 (LocalAgent restore) ## Remaining Work - [ ] Fix raw token leak in final no-tools inference pass: when the agent loop runs its final plain-text pass (no tools), raw tokens like <|tool_call> still stream as ChatChunk::Token instead of being consumed by the OAI parser. The content deltas from oai_parser.update() are supposed to emit plain text but something is dropping them. - [ ] Verify plain-text streaming works correctly end-to-end in the UI - [ ] Close issue #1142 once the above is confirmed ## Current State - Files modified: packages/nlp-engine/src/chat/mod.rs, packages/daemon/src/main.rs - Tests status: 51/51 passing (cargo test -p nodespace-nlp-engine -- chat) - Daemon binary: ~/.nodespace/bin/nodespaced is up to date, running via launchctl - Gemma 4 E4B model: downloaded at ~/Library/Application Support/NodeSpace/models/ ## Context for Next Session The ChatParseStateOaicompat approach is correct and working for tool-call detection. The remaining raw token issue is in emit_oai_delta() — the content delta path. When the final no-tools inference pass runs, each token piece is fed via oai_parser.update(piece, true) and the C++ layer returns content deltas, but something in the delta JSON parsing or in the generate_blocking flow is dropping them. Start by adding a tracing::debug! in emit_oai_delta to log the raw delta_json strings arriving from the OAI parser — confirm whether content deltas are coming through or whether the parser is silently buffering them. Key file: packages/nlp-engine/src/chat/mod.rs - emit_oai_delta() at ~line 465 — parses OAI delta JSON and emits ChatChunk events - generate_blocking() token loop at ~line 370 — feeds tokens to oai_parser The 5 "duplicate" tool_call_start blocks seen in gRPC SendMessage output are NOT a bug — they are 5 ReAct loop iterations each emitting one correct tool call, as expected. ## Acceptance Criteria Status (issue #1142) - [x] Gemma 4 E4B downloads and loads (5.3GB, no ffi error) - [x] Tokens stream without ffi error -1 - [x] Tool-call Format detection works (tool_calls=1 per iteration, correct name+args) - [ ] Plain-text response streaming works (raw tokens not leaking) - [ ] Results documented on #1142 (partial comment added, full close pending) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…se (closes #1138) (#1161) * Add SettingsService gRPC: daemon config via RPC, delete switch_database (closes #1138) - Add settings_service.proto with GetDaemonConfig/UpdateDaemonConfig RPCs - Implement SettingsServiceImpl reading/writing ~/.nodespace/daemon.toml - Register SettingsService in nodespaced (headless and tray modes) - Add SettingsServiceClient to Tauri GrpcClient - Rewrite commands/settings.rs: daemon config fetched via gRPC, display prefs (theme, render_markdown) remain in Tauri local storage - Delete AppServices::switch_database() and all hot-swap code - Remove savedDatabasePath from settings store (replaced by gRPC config) - Update database-settings UI: path changes now persist via gRPC, restart required instead of in-process hot-swap - Clean up dead event listeners (database-changed) from app-shell Co-Authored-By: Claude <[email protected]> * Address review: fix concurrent write hazard, add restart advisory - Add Mutex to SettingsServiceImpl to serialize read-modify-write in update_daemon_config, preventing interleaved concurrent RPCs from silently discarding each other's writes - Show restart-required notice in database-settings.svelte after path changes (previously only surfaced via menu path / status bar) - Fix redundant_closure clippy lint in grpc_client.rs Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
LocalAgentServiceServer was accidentally dropped in b88096c (PR #1161, Add SettingsService) when the diff removed it while adding SettingsService. This caused ListModels, EnsureModelReady, StartSession, and all other LocalAgent RPCs to return Unimplemented for 13 days. Also clones node_service before ImportServiceImpl::new() consumes it, matching the original pattern from PR #1160. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
partially) ## Completed in This Session - [x] Verified issue #1142: Gemma 4 E4B downloads, loads, and streams tokens without ffi error -1 - [x] Found root cause: Gemma 4 tool-call parsing was broken — model emits <|tool_call> special tokens but old code used token_to_piece(special=false) which silently dropped them - [x] Fixed tool-call parsing: replaced custom StreamingToolCallParser + sentinel detection with ChatParseStateOaicompat (llama.cpp native streaming parser, handles Gemma 4 natively via COMMON_CHAT_FORMAT_PEG_GEMMA4 PEG grammar) - [x] Confirmed fix works: agent_loop logs show tool_calls=1 per inference round (was 0 before) - [x] Restored LocalAgentServiceServer registration in daemon main.rs (accidentally dropped in PR #1161 b88096c when SettingsService was added — missing for 13 days) - [x] Committed and pushed: 8a9a9e0 (parser fix), 6c81f7f (LocalAgent restore) ## Remaining Work - [ ] Fix raw token leak in final no-tools inference pass: when the agent loop runs its final plain-text pass (no tools), raw tokens like <|tool_call> still stream as ChatChunk::Token instead of being consumed by the OAI parser. The content deltas from oai_parser.update() are supposed to emit plain text but something is dropping them. - [ ] Verify plain-text streaming works correctly end-to-end in the UI - [ ] Close issue #1142 once the above is confirmed ## Current State - Files modified: packages/nlp-engine/src/chat/mod.rs, packages/daemon/src/main.rs - Tests status: 51/51 passing (cargo test -p nodespace-nlp-engine -- chat) - Daemon binary: ~/.nodespace/bin/nodespaced is up to date, running via launchctl - Gemma 4 E4B model: downloaded at ~/Library/Application Support/NodeSpace/models/ ## Context for Next Session The ChatParseStateOaicompat approach is correct and working for tool-call detection. The remaining raw token issue is in emit_oai_delta() — the content delta path. When the final no-tools inference pass runs, each token piece is fed via oai_parser.update(piece, true) and the C++ layer returns content deltas, but something in the delta JSON parsing or in the generate_blocking flow is dropping them. Start by adding a tracing::debug! in emit_oai_delta to log the raw delta_json strings arriving from the OAI parser — confirm whether content deltas are coming through or whether the parser is silently buffering them. Key file: packages/nlp-engine/src/chat/mod.rs - emit_oai_delta() at ~line 465 — parses OAI delta JSON and emits ChatChunk events - generate_blocking() token loop at ~line 370 — feeds tokens to oai_parser The 5 "duplicate" tool_call_start blocks seen in gRPC SendMessage output are NOT a bug — they are 5 ReAct loop iterations each emitting one correct tool call, as expected. ## Acceptance Criteria Status (issue #1142) - [x] Gemma 4 E4B downloads and loads (5.3GB, no ffi error) - [x] Tokens stream without ffi error -1 - [x] Tool-call Format detection works (tool_calls=1 per iteration, correct name+args) - [ ] Plain-text response streaming works (raw tokens not leaking) - [ ] Results documented on #1142 (partial comment added, full close pending) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Summary
SettingsServiceproto withGetDaemonConfig/UpdateDaemonConfigRPCs andSettingsServiceImplreading/writing~/.nodespace/daemon.tomlSettingsServicein nodespaced (headless and tray modes)SettingsServiceClientto TauriGrpcClient; rewritecommands/settings.rsso daemon config fetches via gRPC while display prefs (theme, render_markdown) remain in Tauri local storageAppServices::switch_database()and all hot-swap code; database path changes now persist via gRPC and require a restartsavedDatabasePathfrom settings store; clean up deaddatabase-changedevent listeners from app-shellTest plan
cargo build --package nodespace-daemonpassescargo build --package nodespace-apppassesbun run test— 128 files / 3916 tests (no regressions vs baseline)bun run quality:fixpasses~/.nodespace/daemon.toml(visible after restart)~/.nodespace/daemon.toml🤖 Generated with Claude Code