Skip to content

fix: prevent agent settings from being silently deleted on channel deletion#752

Merged
wesbillman merged 3 commits into
mainfrom
fix/agent-settings-reset-on-channel-delete
May 26, 2026
Merged

fix: prevent agent settings from being silently deleted on channel deletion#752
wesbillman merged 3 commits into
mainfrom
fix/agent-settings-reset-on-channel-delete

Conversation

@wesbillman
Copy link
Copy Markdown
Collaborator

@wesbillman wesbillman commented May 26, 2026

Summary

  • Disable auto-deletion of managed agents on channel deletion. cleanupChannelAgents and cleanupManagedAgentIfOrphaned relied on relay kind:10100 events to determine whether an agent was "orphaned" — but relay data can be stale/incomplete, causing agents that are still active in other channels to be incorrectly deleted. This wiped all customized settings (ENV vars, MCP config, parallelism, system prompts). Both functions and their call sites have been removed entirely.

  • Make save_managed_agents use atomic writes. Previously used bare fs::write which can leave a corrupted/partial file if the process crashes mid-write. Now writes to a .json.tmp file first, then atomically renames it into place.

  • Remove legacy migration code. The com.wesb.sproutxyz.block.sprout.app data directory migration is no longer needed — all existing users have been migrated. Removes migration.rs and its call site entirely.

Root cause

When a channel is deleted, the frontend called cleanupChannelAgents(channelId), which:

  1. Fetched all channel members
  2. Queried relay kind:10100 events to check if each agent exists in other channels
  3. Deleted managed agent records for any agent it considered "orphaned"

The relay data used in step 2 can be stale or incomplete — an agent that IS still active in another channel may appear orphaned because its kind:10100 event hasn't been indexed yet. This causes the agent record (with all its customized settings) to be deleted.

Changes

File Change
desktop/src/features/channels/cleanupChannelAgents.ts Deleted — no-op cleanup functions removed entirely
desktop/src/features/channels/hooks.ts Removed cleanup imports, try/catch blocks, and removeChannelMemberWithManagedAgentCleanup helper
desktop/src/features/channels/ui/useMembersSidebarActions.ts Replaced cleanup helper with direct removeChannelMember call
desktop/src-tauri/src/managed_agents/storage.rs Atomic write-to-temp + rename for save_managed_agents
desktop/src-tauri/src/migration.rs Deleted — legacy directory migration no longer needed
desktop/src-tauri/src/lib.rs Removed mod migration and migrate_legacy_data_dir call

Net: -397 lines

Test plan

  • All 11 pre-commit hooks pass (rust-fmt, web-check, desktop-tauri-fmt, desktop-check, web-build, mobile-check, desktop-build, desktop-tauri-check, mobile-test, rust-clippy, rust-tests)
  • Manual verification: edit agent settings → delete a channel containing that agent → confirm settings are preserved
  • Manual verification: create agent in multiple channels → delete one channel → confirm agent and settings survive

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

…letion

cleanupChannelAgents relied on stale relay kind:10100 data to determine
orphan status, incorrectly deleting agents that were still in other
channels. Both cleanupChannelAgents and cleanupManagedAgentIfOrphaned
are now no-ops — agent records are cheap to keep and users can manually
remove orphans from the agents page.

Also makes save_managed_agents atomic (write-to-tmp + rename) to prevent
partial writes from corrupting the agent store on crash.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wesbillman wesbillman requested a review from a team as a code owner May 26, 2026 21:16
wesbillman and others added 2 commits May 26, 2026 14:33
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wesbillman wesbillman merged commit ab71ade into main May 26, 2026
15 checks passed
@wesbillman wesbillman deleted the fix/agent-settings-reset-on-channel-delete branch May 26, 2026 23:09
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