Skip to content

perf(desktop): stop forwarding unobserved session events #1957

Closed as not planned

Description

@Astro-Han

Problem

Desktop currently forwards every SessionEvent from every running session to the renderer through webContents.send, even when no renderer surface subscribes to that session's channel.

The renderer normally subscribes only to the active session. Conditional surfaces such as quote or plan views may add other subscriptions, but Main has no subscriber knowledge and therefore sends all events unconditionally.

Electron serializes and transports every webContents.send payload before the renderer can dispatch or discard it. With multiple concurrent sessions, this creates avoidable IPC work proportional to total event throughput.

Desired outcome

Forward fine-grained sessions:event:<sessionId> traffic only while at least one renderer consumer subscribes to that session:

  • preserve active-session, quote-companion, plan, and other legitimate subscriptions;
  • reference-count multiple consumers of the same session channel;
  • stop forwarding after the final consumer unsubscribes;
  • clean up subscriptions when the renderer or window is destroyed or reloaded;
  • preserve coarse sessions:changed lifecycle broadcasts so background status remains correct.

Acceptance criteria

  • A session with no renderer subscriber produces no sessions:event:<sessionId> sends.
  • The first subscriber enables delivery and the final unsubscribe disables it.
  • Multiple subscribers to one session do not disable each other.
  • Session switching does not lose active-session events during subscription handoff.
  • Renderer reload/teardown cannot leave stale subscriptions behind.
  • Existing background completion and sidebar status reconciliation remain intact.
  • Focused tests cover subscription reference counting, teardown, and event-delivery gating.

Alternatives considered

  • Gate delivery only on the active session ID: simpler, but breaks legitimate secondary consumers.
  • Keep unconditional delivery because unmatched events are ignored: preserves behavior but retains serialization and cross-process work for data with no consumer.
  • Coalesce or throttle all session events: changes observable streaming behavior and does not remove unobserved delivery.

Non-goals

Activity

  1. added
    enhancement
    on Aug 3, 2026
  2. Astro-Han commented on Aug 3, 2026

    @Astro-Han
    ContributorAuthor

    Root-cause review confirmed that the unnecessary IPC forwarding is real, but we should not add a parallel subscription/ref-counting authority to the current embedded Desktop runtime.

    Runtime Host session continuity already owns the intended final semantics: subscriber-gated transient events, atomic snapshot/live handoff, connection-scoped cleanup, sequence continuity, and reload after gaps. Implementing the same behavior in Electron main now would create an intermediate path that M5 would later delete.

    We will therefore defer this issue to the Runtime Host M5 atomic production cutover tracked by #853 and #1167. The Desktop Runtime Host adapter should consume the existing Host subscription boundary, and the legacy unconditional sessions:event:<sessionId> forwarding path should be removed as part of that cutover.

    No standalone embedded-runtime fix is planned unless this becomes a measured, release-blocking performance problem before M5.

  3. Astro-Han commented on Aug 8, 2026

    @Astro-Han
    ContributorAuthor

    Closing this standalone issue in favor of the Runtime Host authority. The latest decision here correctly defers subscriber-gated session events to the M5 cutover tracked by #853 and #1167; adding a parallel ref-counting authority to the legacy embedded Desktop path would be a temporary duplicate implementation. The unique requirement remains: the Desktop Host adapter should consume the Host subscription boundary and remove legacy unconditional forwarding at cutover.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions