Skip to content

[Bug] Deploy team to channel force-mints new agent keypair per persona (bypasses reuse) #3639

Description

@matthewdcage

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):

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:

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 <B> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions