Skip to content

Migrate Tauri command handlers to thin gRPC proxy wrappers #1113

Closed

Description

@malibio

Overview

Replace all #[tauri::command] handler implementations with thin gRPC proxy wrappers that forward calls to nodespaced on localhost:50051. After this change, the Tauri app contains no business logic — it is a pure gRPC client that translates Tauri IPC into gRPC calls and maps responses back.

Problem Statement

Approximately 30 #[tauri::command] handlers in packages/desktop-app/src-tauri/src/commands/ contain direct calls into packages/core ops. Under ADR-031, all business logic moves to nodespaced. The Tauri process must become a thin client; keeping direct ops calls creates two competing code paths and prevents the daemon architecture from working correctly.

Proposed Solution

For each existing Tauri command handler:

  1. Remove the direct packages/core ops invocation
  2. Replace with a gRPC call to nodespaced using a shared tonic client
  3. Map gRPC response back to the expected Tauri command return type
  4. Map gRPC errors to tauri::Error or command-specific error types

The Tauri app initializes one gRPC client on startup and passes it to all command handlers via Tauri's managed state.

Acceptance Criteria

  • All #[tauri::command] handlers that previously called packages/core ops now call nodespaced via gRPC
  • No direct packages/core imports remain in packages/desktop-app/src-tauri/src/commands/
  • gRPC client initialized on Tauri startup and stored in tauri::State
  • All existing Tauri command return types preserved (frontend calls unchanged)
  • Commands work end-to-end: Tauri frontend → gRPC proxy → nodespaced → response
  • Error cases propagate correctly (gRPC status codes → command errors)
  • cargo build -p desktop-app succeeds
  • All frontend tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Files to modify

  • packages/desktop-app/src-tauri/src/commands/ — all command files; replace ops calls with gRPC calls
  • packages/desktop-app/src-tauri/src/main.rs — initialize gRPC client, add to Tauri managed state
  • packages/desktop-app/src-tauri/Cargo.toml — add tonic, prost dependencies; add packages/daemon as path dependency for generated types

gRPC client state pattern

// src-tauri/src/main.rs
struct GrpcClient {
    node_service: NodeServiceClient<Channel>,
}

tauri::Builder::default()
    .manage(GrpcClient::connect("http://[::1]:50051").await?)
    // ...

Command proxy pattern

// Before
#[tauri::command]
async fn get_node(id: String, service: State<'_, NodeService>) -> Result<Node, String> {
    service.get_node(&id).await.map_err(|e| e.to_string())
}

// After
#[tauri::command]
async fn get_node(id: String, client: State<'_, GrpcClient>) -> Result<Node, String> {
    let response = client.node_service
        .get_node(GetNodeRequest { id })
        .await
        .map_err(|e| e.to_string())?;
    Ok(response.into_inner().into())
}

Commands to migrate

All handlers in:

  • packages/desktop-app/src-tauri/src/commands/nodes.rs
  • packages/desktop-app/src-tauri/src/commands/search.rs
  • packages/desktop-app/src-tauri/src/commands/schema.rs
  • Any other command files with direct core ops calls

Error mapping

tonic::Status → command error string, preserving the status code in the message for debuggability.

Reference files

Dependencies

Non-Goals

  • WatchNodes streaming for UI reactivity (separate issue)
  • ACP/MCP command handlers (deleted separately, not proxied)
  • CLI binary

Activity

  1. malibio commented on May 17, 2026

    @malibio
    CollaboratorAuthor

    Scope Clarification (2026-05-17)

    This issue is narrowed to Node + AgentSession handlers only.

    The proto currently covers two services: NodeService and AgentSessionService. There are ~50 additional Tauri command handlers (collections, embeddings, schemas, settings, import, local_agent, chat_models, db, diagnostics) that have no gRPC destination yet — their proto definitions and nodespaced handlers are tracked in follow-up issues (see below).

    What to implement in this issue

    Migrate only the handlers that have an existing proto + nodespaced handler:

    • commands/nodes.rs → NodeService gRPC proxy
    • commands/collections.rs → NodeService gRPC proxy (collections are NodeService operations)
    • commands/schemas.rs → NodeService gRPC proxy (schema reads are NodeService operations)

    Do not attempt to proxy the following in this PR — leave them calling packages/core directly until their follow-up issues land:

    Why this approach

    The Tauri app remains fully functional throughout: unmigrated handlers continue calling packages/core directly with no regression. As each follow-up service issue lands (proto + nodespaced handler + Tauri proxy), those handlers flip to gRPC. Eventually all handlers are proxies and packages/core is no longer imported by the Tauri app.

    Updated acceptance criteria

    The AC "No direct packages/core imports remain in packages/desktop-app/src-tauri/src/commands/" is not achievable in this issue and should be read as the end-state across all service migration issues. For this PR, the criterion is: all nodes.rs, collections.rs, and schemas.rs handlers proxy via gRPC; all other handlers continue calling core directly and are explicitly left for follow-up issues.

  2. malibio commented on May 17, 2026

    @malibio
    CollaboratorAuthor

    Baseline (2026-05-17, worktree issue-1113-grpc-proxy from 5e7ef28):
    Frontend: 128 test files passed, 3918 tests passed (Duration 41.00s)

    Note: required bunx svelte-kit sync in this worktree to generate .svelte-kit/tsconfig.json before bun run test would start (vitest's tsconfig extends chain otherwise fails to resolve in a fresh worktree).

    Working on the narrowed scope per the 2026-05-17 scope-clarification comment: commands/nodes.rs, commands/collections.rs, commands/schemas.rs → NodeService gRPC proxy. Other handler files left untouched per their tracking issues.

  3. self-assigned this
    on May 17, 2026
  4. malibio commented on May 17, 2026

    @malibio
    CollaboratorAuthor

    WIP handoff @ commit 5d1b7f1 on branch worktree-issue-1113-grpc-proxy.

    Completed (Phase 1 of 5): Extended packages/daemon/proto/node_service.proto with +328 LOC. Added 28 new RPCs covering all in-scope handlers, plus ~30 new message types. Existing CreateNodeRequest gained id and insert_after_node_id fields to match the Tauri CreateNodeInput shape.

    Remaining phases:

    • Phase 2: cargo build -p nodespace-daemon to validate proto compiles (was blocked by sibling worktree's target lock during this session)
    • Phase 3: Implement 28 handlers in packages/daemon/src/services/node_service.rs (~800 LOC)
    • Phase 4: Add Tauri gRPC client scaffolding (~50 LOC)
    • Phase 5: Rewrite nodes.rs (19 handlers), collections.rs (12), schemas.rs (2)
    • Phase 6: Build, tests, quality, PR

    See WIP commit message for full handoff context, including design decisions baked into the proto (tri-state TaskNodeUpdate encoding, generic NodeResponse for SchemaNode/TaskNode reads, dedicated CollectionInfo message, etc.).

  5. added a commit that references this issue on May 17, 2026
  6. malibio commented on May 17, 2026

    @malibio
    CollaboratorAuthor

    WIP handoff @ commit d6f9975 on branch worktree-issue-1113-grpc-proxy.

    Completed (Phases 2-4 of 5):

    • Phase 2: Proto compiles cleanly (cargo build -p nodespace-daemon succeeds)
    • Phase 3: Implemented 26 new nodespaced gRPC handlers in packages/daemon/src/services/node_service.rs (+~900 LOC net). All 28 in-scope RPCs now have impls; only WatchNodes/Chat remain stubbed (tracked separately). Includes tri-state TaskNodeUpdate decoding, schema reads via raw Node fetch, and consistent CollectionService usage.
    • Phase 4: Tauri gRPC client scaffolding wired in. New services/grpc_client.rs spawns an in-process tonic server on 127.0.0.1:0 (OS-chosen port) reusing the same Arc<NodeService> AppServices already owns — no second DB open. Registered via app.manage() after AppServices init.

    Build status: Both cargo build -p nodespace-daemon and cargo build -p nodespace-app succeed with no warnings.

    Remaining (Phase 5): Mechanical migration of commands/nodes.rs (19 handlers), commands/collections.rs (12), commands/schemas.rs (2) to proxy through State<'_, GrpcClient>. All proto types and core handlers are wired through — the migration is now: replace inner ops calls with gRPC calls and map responses back to existing CommandError/Value/Node return types.

    See WIP commit message d6f9975 for full Phase 5 implementation guidance and design decisions baked in (tri-state encoding, schema reconstruction, etc.).

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