Skip to content

fix(desktop): clean up managed agents when channel is deleted#152

Merged
wesbillman merged 1 commit intomainfrom
fix/cleanup-agents-on-channel-delete-ui
Mar 21, 2026
Merged

fix(desktop): clean up managed agents when channel is deleted#152
wesbillman merged 1 commit intomainfrom
fix/cleanup-agents-on-channel-delete-ui

Conversation

@wesbillman
Copy link
Collaborator

Summary

When a channel is deleted, managed agents that were created for that channel (via the "Add agents" dialog) are now automatically cleaned up. Previously, these agents would be orphaned — still running and visible in the Agents panel — after the channel was deleted.

What changed

New file: desktop/src/features/channels/cleanupChannelAgents.ts

  • Extracted helper that handles the cleanup logic
  • Fetches channel members, managed agents, and relay agents in parallel
  • Cross-references to find managed agents that are members of the channel
  • Only deletes agents that are NOT members of any other channel (multi-channel safe)
  • Uses Promise.allSettled for best-effort cleanup — individual failures don't block others

Modified: desktop/src/features/channels/hooks.ts

  • useDeleteChannelMutation now calls cleanupChannelAgents() before deleting the channel
  • Cleanup is wrapped in try/catch — if it fails, channel deletion still proceeds
  • onSettled invalidates managed-agents and relay-agents queries so the UI refreshes

Design decisions

  • Delete, not just stop: Since each agent is a duplicate created specifically for the channel, deleting it (stop process + remove config) is the right call
  • Multi-channel safe: Agents that are members of other channels are preserved
  • Best-effort: Cleanup failures are logged but never prevent channel deletion
  • No backend changes: This is a pure UI fix — the relay/database are untouched

Testing

Manually tested by the reporter — confirmed agents are cleaned up after channel deletion.

@wesbillman wesbillman merged commit 9b9a077 into main Mar 21, 2026
8 checks passed
@wesbillman wesbillman deleted the fix/cleanup-agents-on-channel-delete-ui branch March 21, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant