Skip to content

Implement WatchNodes gRPC streaming to replace Tauri event system for UI reactivity #1114

Closed

Description

@malibio

Overview

Implement the WatchNodes server-streaming RPC so the Tauri desktop UI receives real-time graph update events from nodespaced without polling. This replaces the current Tauri event system as the mechanism for pushing node change notifications to the frontend.

Problem Statement

The Tauri frontend currently receives node update notifications via Tauri events emitted from within the same process. Under ADR-031, the Tauri app is a separate gRPC client process. Tauri events cannot cross process boundaries. Without a streaming RPC the UI must poll — unacceptable when agent sessions may be modifying the graph concurrently.

Proposed Solution

nodespaced maintains an internal tokio::sync::broadcast channel (the event bus). Every ops-layer mutation publishes a NodeEvent to it. The WatchNodes handler subscribes and streams those events to connected clients. The Tauri app opens a long-lived WatchNodes stream on startup and reconnects automatically on disconnection.

Acceptance Criteria

  • WatchNodes RPC is fully implemented in nodespaced (not a stub returning Unimplemented)
  • NodeEvent proto message includes: event type (created/updated/deleted), node ID, and full node data for created/updated events
  • Every successful ops-layer mutation publishes to the event bus
  • Tauri app opens a WatchNodes stream on startup
  • Tauri app reconnects automatically on stream error using exponential backoff (start 1s, cap 30s)
  • Frontend reactive state updates from watcher events without polling
  • Multiple concurrent watchers supported simultaneously (e.g., Tauri UI + CLI)
  • Stream closes gracefully when the client disconnects
  • Integration test: mutate a node via gRPC, verify the watcher receives the corresponding event
  • All frontend tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Files to create/modify

  • packages/daemon/src/event_bus.rs (NEW) — Arc<EventBus> wrapping a broadcast::Sender<NodeEvent>; exposes publish() and subscribe()
  • packages/daemon/src/services/node_service.rs — implement watch_nodes using async_stream::stream! over a broadcast receiver
  • packages/desktop-app/src-tauri/src/watcher.rs (NEW) — spawns a task that opens the WatchNodes stream and re-emits events to the Svelte frontend via Tauri emit
  • packages/desktop-app/src/lib/ — update reactive stores to consume watcher events

NodeEvent and WatchRequest proto additions

message WatchRequest {
  repeated string node_ids = 1; // empty = watch all nodes
}

message NodeEvent {
  enum EventType { CREATED = 0; UPDATED = 1; DELETED = 2; }
  EventType event_type = 1;
  string node_id        = 2;
  optional NodeResponse node = 3; // populated for CREATED and UPDATED
}

Event bus pattern

pub struct EventBus {
    sender: broadcast::Sender<NodeEvent>,
}
impl EventBus {
    pub fn publish(&self, event: NodeEvent) { let _ = self.sender.send(event); }
    pub fn subscribe(&self) -> broadcast::Receiver<NodeEvent> { self.sender.subscribe() }
}

EventBus held in Arc, injected into both the ops layer and the NodeService gRPC handler.

WatchNodes handler skeleton

async fn watch_nodes(&self, _req: Request<WatchRequest>)
    -> Result<Response<Self::WatchNodesStream>, Status>
{
    let mut rx = self.event_bus.subscribe();
    let stream = async_stream::stream! {
        loop {
            match rx.recv().await {
                Ok(event)             => yield Ok(event),
                Err(RecvError::Lagged(_)) => continue,
                Err(RecvError::Closed)    => break,
            }
        }
    };
    Ok(Response::new(Box::pin(stream)))
}

Reference files

Dependencies

Non-Goals

  • Filtering watch events by node type or parent (future)
  • Persistent event log or replay from last-seen sequence number (future)
  • Watching relationship changes (separate concern)

Activity

  1. malibio commented on May 17, 2026

    @malibio
    CollaboratorAuthor

    Baseline test status (frontend, before implementation):

    Test Files: 128 passed (128)
    Tests: 3918 passed (3918)
    Duration: 39.41s

    Will compare against this baseline before opening PR.

  2. self-assigned this
    on May 17, 2026
  3. added a commit that references this issue on May 17, 2026
  4. malibio commented on May 17, 2026

    @malibio
    CollaboratorAuthor

    Implementation note — scope clarification for AC

    The watcher.rs module will be implemented, tested at the unit/integration level, and committed as part of this PR, but its activation is gated on #1113:

    AC reinterpretation:

    • "Tauri app opens a WatchNodes stream on startup" → watcher module ready, activated by Migrate Tauri command handlers to thin gRPC proxy wrappers #1113
    • "Tauri app reconnects automatically..." → exponential backoff implemented in module
    • "Frontend reactive state updates from watcher events without polling" → event format identical to current DomainEventForwarder output; frontend stays unchanged

    This matches CLAUDE.md 'no dual-mode' rule: only one event source is live at a time. The watcher module exists inert in the codebase until #1113 flips the switch.

  5. added 2 commits that reference this issue on Jun 22, 2026
    919d525
    572426a
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