formulahendry / formulahendry/vscode-acp
Coalesce concurrent connectToAgent() calls in SessionManager
- Dominant language
- TypeScript
- Stars
- 378
- Forks
- 76
- PR merge metrics
- No merged PRs in 30d
Description
## 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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.