Skip to content

Add LocalAgentService gRPC: proto, daemon handler, Tauri proxy (closes #1137) - #1160

Merged
malibio merged 3 commits into
mainfrom
worktree-issue-1137-local-agent-grpc
May 18, 2026
Merged

malibio merged 3 commits into
mainfrom
worktree-issue-1137-local-agent-grpc

Conversation

@malibio

@malibio malibio commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Defines local_agent_service.proto with 8 RPCs (StartSession, SendMessage, GetStatus, CancelGeneration, EndSession, GetSessions, EnsureModelReady, ListModels)
  • Implements LocalAgentServiceImpl in nodespaced daemon — owns LocalAgentService + CompositeModelManager, no longer in the Tauri process
  • Replaces commands/local_agent.rs with a thin gRPC proxy that forwards streaming chunks as Tauri events (local-agent://chunk, local-agent://tool, model://status, etc.)
  • Removes ManagedAgentState from Tauri managed state; CompositeModelManager is retained only for chat_models.rs
  • Adds local_agent_client() accessor to GrpcClient and registers LocalAgentServiceServer on the in-process server

Architecture notes

  • LocalAgentServiceImpl uses Arc<Inner> + #[derive(Clone)] pattern (same as AgentSessionHandler) to satisfy tonic's Clone bound without cloning non-Clone state
  • get_service() clones the Arc<AgentService> out of the RwLock before any .await, avoiding RwLockReadGuard across await points
  • Server-streaming RPCs use unbounded MPSC channel for agent→stream bridging

Test plan

  • cargo build passes for both nodespace-daemon and nodespace-desktop-app
  • Frontend: 3916 tests pass (128 files)
  • bun run quality:fix clean

🤖 Generated with Claude Code

Michael Libio and others added 3 commits May 18, 2026 11:54
…#1137)

Moves the local agent (ReAct loop + llama.cpp inference) from the Tauri
process into nodespaced so sessions survive UI restarts and GPU resources
are managed by the daemon.

- proto/local_agent_service.proto: StartSession, SendMessage (streaming),
  GetStatus, CancelGeneration, EndSession, GetSessions, EnsureModelReady
  (streaming), ListModels
- LocalAgentServiceImpl in daemon: wraps LocalAgentService + CompositeModelManager;
  Arc<inner> pattern keeps handler Clone for tonic
- LocalAgentServiceServer registered in nodespaced (headless + tray paths)
- GrpcClient gains LocalAgentServiceClient; in-process server registers
  LocalAgentServiceServer alongside existing services
- commands/local_agent.rs rewritten as thin gRPC proxy; no direct
  packages/agent imports for session/inference logic remain
- ManagedAgentState removed from Tauri app state and graceful shutdown
- chat_models::chat_model_unload simplified (no longer resets agent state)
- tests.rs: removed ManagedAgentState shutdown tests (moved to daemon)

Co-Authored-By: Claude <[email protected]>
…onal client

- Filter StreamingChunk::Done in on_chunk callback to prevent double "done"
  event (agent loop emits Done + we emit our own with token counts from result)
- Check active_model_id (in-memory) instead of catalog Loaded status for GGUF
  "already loaded" fast path — catalog persists across restarts but engine doesn't
- Move model_manager.load() to after spawn_blocking succeeds so catalog only
  reflects Loaded when llama.cpp context is actually live
- Handle Loaded catalog status as fall-through to re-load path (daemon restart case)
- Return LocalAgentServiceClient directly from local_agent_client() instead of
  Option — it is always present, unlike embeddings_client
- Fix GgufModelManager init to use expect() instead of warn + panic

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@malibio
malibio merged commit 699a4c9 into main May 18, 2026
@malibio
malibio deleted the worktree-issue-1137-local-agent-grpc branch May 18, 2026 10:13
malibio added a commit that referenced this pull request May 31, 2026
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]>
malibio added a commit that referenced this pull request Jun 22, 2026
…#1137) (#1160)

* Add LocalAgentService gRPC: proto, daemon handler, Tauri proxy (closes #1137)

Moves the local agent (ReAct loop + llama.cpp inference) from the Tauri
process into nodespaced so sessions survive UI restarts and GPU resources
are managed by the daemon.

- proto/local_agent_service.proto: StartSession, SendMessage (streaming),
  GetStatus, CancelGeneration, EndSession, GetSessions, EnsureModelReady
  (streaming), ListModels
- LocalAgentServiceImpl in daemon: wraps LocalAgentService + CompositeModelManager;
  Arc<inner> pattern keeps handler Clone for tonic
- LocalAgentServiceServer registered in nodespaced (headless + tray paths)
- GrpcClient gains LocalAgentServiceClient; in-process server registers
  LocalAgentServiceServer alongside existing services
- commands/local_agent.rs rewritten as thin gRPC proxy; no direct
  packages/agent imports for session/inference logic remain
- ManagedAgentState removed from Tauri app state and graceful shutdown
- chat_models::chat_model_unload simplified (no longer resets agent state)
- tests.rs: removed ManagedAgentState shutdown tests (moved to daemon)

Co-Authored-By: Claude <[email protected]>

* Fix review issues: double-done chunk, GGUF stale-status bug, non-Optional client

- Filter StreamingChunk::Done in on_chunk callback to prevent double "done"
  event (agent loop emits Done + we emit our own with token counts from result)
- Check active_model_id (in-memory) instead of catalog Loaded status for GGUF
  "already loaded" fast path — catalog persists across restarts but engine doesn't
- Move model_manager.load() to after spawn_blocking succeeds so catalog only
  reflects Loaded when llama.cpp context is actually live
- Handle Loaded catalog status as fall-through to re-load path (daemon restart case)
- Return LocalAgentServiceClient directly from local_agent_client() instead of
  Option — it is always present, unlike embeddings_client
- Fix GgufModelManager init to use expect() instead of warn + panic

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Jun 22, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant