Skip to content

Coalesce concurrent connectToAgent() calls in SessionManager #29

@stefanpieter

Description

@stefanpieter

Summary

SessionManager.connectToAgent(agentName) should coalesce concurrent calls for the same agent behind a shared pending promise instead of allowing duplicate in-flight connects.

Why

When multiple startup/view-hydration paths trigger connectToAgent() at nearly the same time, the extension can race into duplicate spawn/connect/session creation work. This creates flakiness and slows local iteration/debugging.

Proposal

  • track in-flight connectToAgent(agentName) operations in a per-agent map
  • if a second call arrives for the same agent while the first is still pending, return the same promise
  • clear the pending entry on resolve/reject

Acceptance criteria

  • only one underlying connect/spawn/session-new path runs for concurrent same-agent calls
  • parallel callers all receive the same eventual result
  • rejection cleanup works correctly
  • regression test proves only one connection flow occurs under Promise.all([connectToAgent("Hermes Agent"), connectToAgent("Hermes Agent")])

Notes

This is both a correctness fix and a developer-velocity improvement because duplicate connects make the VS Code session state harder to reason about during local iteration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions