fix: prevent agent proliferation when adding bots to channels#621
Merged
Conversation
7c6f331 to
bf26ca6
Compare
tlongwell-block
approved these changes
May 20, 2026
This was referenced May 20, 2026
…l UI - Extract reuse helpers into agentReuse.ts (commandsMatch, pickPreferred, findReusablePersonaAgent, findReusableGenericAgent, findReusableAgent) - Add generic agent reuse: when no persona and no custom prompt, reuse existing agent with matching command instead of spawning a new keypair - Add forceNewInstance flag to CreateChannelManagedAgentInput so users can explicitly opt into creating a fresh instance - Guard both persona and generic reuse paths with forceNewInstance check - Add useReusableAgentDetection hook for UI-side reuse detection - Add AddChannelBotReuseGuard component: radio choice defaulting to reuse, with opt-out for 'Create new instance' - Wire guardrail into AddChannelBotDialog — shows when reuse would fire for single-agent selections (1 persona or generic with blank prompt)
Replace bordered card with radio buttons → label + select dropdown + helper text. Same visual plane as 'Who can talk to this agent' field.
Covers commandsMatch, parseTimestamp, pickPreferredManagedAgent, findReusablePersonaAgent, findReusableGenericAgent, and findReusableAgent. 38 test cases covering edge cases: - Path normalization and claude command aliasing - Whitespace-only vs empty vs undefined systemPrompt - Running vs stopped agent preference - Null/undefined timestamp handling - Channel member exclusion logic
bf26ca6 to
0024a61
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Category: improvement
User Impact: Adding an agent to a channel now reuses an existing instance by default instead of spawning a duplicate, reducing agent sprawl from dozens of redundant keypairs down to one per persona.
Problem: The "+" button in channel headers spawned a brand-new managed agent (new keypair) every time — even when that persona already had a running agent. This led to 79 agent instances and 89 unique bot pubkeys across 26 channels.
Solution: Strengthen the reuse logic so existing agents are attached to new channels by default. A guardrail UI (select dropdown) lets users explicitly opt into creating a fresh instance when isolation is needed.
File changes
desktop/src/features/agents/agentReuse.ts
New file. Extracted reuse helper functions:
findReusablePersonaAgent(existing logic, moved here),findReusableGenericAgent(new — matches on command + blank prompt), andfindReusableAgent(unified entry point for the UI hook).desktop/src/features/agents/channelAgents.ts
Refactored to import reuse helpers from
agentReuse.ts. AddedforceNewInstancegate to both persona and generic reuse paths so the UI escape hatch works. Added the new generic agent reuse block (command match + empty prompt guard).desktop/src/features/agents/hooks.ts
Re-exports
findReusableAgentfromagentReuse.tsso the detection hook can import it cleanly.desktop/src/features/channels/ui/AddChannelBotDialog.tsx
Integrates the reuse detection hook and renders the
AddChannelBotReuseGuardcomponent when a reusable agent is found. PassesforceNewInstanceinto the mutation inputs.desktop/src/features/channels/ui/AddChannelBotReuseGuard.tsx
New component. Select dropdown (label + select + helper text pattern, matching
RespondToField) that defaults to "Reuse existing agent" with opt-out to "Create new instance."desktop/src/features/channels/ui/useReusableAgentDetection.ts
New hook. Detects whether a reusable managed agent exists for the current dialog selection (single persona or blank generic) so the UI can show the guardrail before submission.
Reproduction Steps