The architecture distinguishes between deduplicating the resource (the Rust watcher) and the listeners (the subscriptions):
Project-level Deduplication
WatcherManager in Node ensures there is at most one active Rust watcher per project ID. If multiple requests to subscribe to the same project occur concurrently, the system reuses the existing watcher state or the pending promise from pendingProjectWatchers to avoid spawning duplicate Rust processes.
Subscription Non-deduplication
While the Rust watcher is shared, subscriptions are not deduplicated. Every call to subscribeToProject(...) creates:
- A unique
subscriptionId. - A unique
eventChannel. - A separate entry in
watcherSubscriptions.
This allows multiple consumers (e.g., different windows or independent listeners in one window) to coexist for the same project, each with its own channel lifecycle. Note: The UI is expected to create only one subscription per project.