[Bug] Deploy team to channel force-mints new agent keypair per persona (bypasses reuse)
- Dominant language
- Rust
- Stars
- 32.7k
- Forks
- 4.3k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 253
Description
## Summary
**Deploy team to channel** unconditionally mints a **fresh Nostr keypair** for every persona on every deploy, even when that persona already has a live managed instance on the same community. This inflates channel membership with same-display-name bots and breaks `@mention` targeting / agent coordination.
Root cause is explicit in `AddTeamToChannelDialog.tsx`: `forceNewInstance: true` is set for every persona input, which bypasses the existing reuse path in `provisionChannelManagedAgent()` (`findReusablePersonaAgent`).
## Root cause (upstream `main`)
`desktop/src/features/agents/ui/AddTeamToChannelDialog.tsx` (~line 152):
```tsx
personaId: persona.id,
teamId: team.id,
// One persona can be deployed under multiple teams with different instructions.
forceNewInstance: true,
role,
```
`forceNewInstance: true` skips reuse in `desktop/src/features/agents/channelAgents.ts`:
```tsx
if (
input.personaId &&
!input.forceNewInstance &&
context?.managedAgents &&
context.channelMemberPubkeys
) {
const reusable = findReusablePersonaAgent(/* … */);
// attach existing instance instead of createManagedAgent()
}
```
Meanwhile `create_managed_agent` in Tauri **always generates new keys** — there is no server-side dedup by `persona_id`. Frontend reuse is the only guard, and team deploy disables it.
### Why the original comment does not hold
The comment claims personas need distinct instances per team because of "different instructions." In current code, persona `systemPrompt` is persona-scoped (not team-scoped at mint time). `teamId` on the record is deployment provenance / runtime instruction layering — it does not require a new keypair. Re-attaching an existing instance to another channel achieves the same outcome without spawning parallel identities.
## Reproduction (single machine, single community)
1. Create managed instances for personas (e.g. Welcome team: Fizz, Honey, Bumble) and deploy the team to channel A — note instance pubkeys.
2. Deploy the **same team** (or overlapping personas) to channel B via **Deploy team to channel**.
3. `buzz channels members --channel ` shows **new bot pubkeys** with the **same display names** as step 1.
4. Repeat across N channels → N duplicate pubkeys per persona name on the relay.
Also: batch deploy within one channel did not refresh reuse context after each attach in `createChannelManagedAgents()`, so later personas in the same batch could still mint duplicates.
## Observed impact
Single ai-advantage community, single Desktop install:
- ~24 distinct bot pubkeys across channels vs **11** canonical running instances in `managed-agents.json`
- Duplicate groups: Fizz (×4), SEO Agent (×4), Google Ads (×2), Process Engineer (×2), Honey/Bumble short-name variants
- Manual channel cleanup restored **11 canonical pubkeys**, **0** stale bots
## Expected behavior
- Deploy team to channel should **reuse** existing managed instances (attach + membership).
- If persona already in channel, **skip mint** (idempotent deploy).
- Batch deploy refreshes reuse context after each attach.
- Optional hardening: backend refuse second instance per `persona_id` unless explicit `force_new_instance`; `--pubkey` on `draft-update`; Instance pubkey in `AGENTS.md`.
## Proposed fix
Validated locally (uncommitted WIP):
1. Remove `forceNewInstance: true` from `AddTeamToChannelDialog.tsx`
2. Add `findPersonaAgentInChannel()` in `provisionChannelManagedAgent()`
3. Refresh context in `createChannelManagedAgents()` after each attach
4. Hardening: `draft-update --pubkey`, `AGENTS.md` Instance pubkey column, buzz-acp roster poll
Tests: buzz-cli 261 ✅, buzz-acp 633 ✅, desktop JS 3779 ✅, Tauri `managed_agents` 42 ✅
## Related issues
- #2648 — duplicate identities on second Desktop install
- #2973 — cannot archive/remove stale duplicate agents
- #2423 — rename/re-add desynchronises identity
- #2515 — cross-community collision
Contributor guide
Research direction
Start in desktop/src/features/agents/ui/AddTeamToChannelDialog.tsx, then trace provisionChannelManagedAgent() and findReusablePersonaAgent in desktop/src/features/agents/channelAgents.ts. Run the listed desktop JS and Tauri managed_agents tests first. Done means team deployment reuses or skips existing persona instances, and batch deployment refreshes reuse context after each attach without minting duplicate keys.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, tauri, typescript
- Domain
- backend, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100