-
Notifications
You must be signed in to change notification settings - Fork 30
[Bug] Agent Builder: non-atomic three-step creation leaves orphaned agent on partial failure #263
Description
Description
The Agent Builder dialog creates an agent through three serial IPC calls:
createAgent— creates the agent with name + workspaceupdateAgent— sets the modelsetAgentFile— writesIDENTITY.md
If step 1 succeeds but step 2 or 3 fails, an incomplete agent is left on the Gateway. When the user retries with the same name/workspace, the Gateway rejects the creation because the agent (or workspace directory) already exists.
Impact
- Orphaned agents accumulate on the Gateway with missing model or identity configuration
- Retry is blocked — user cannot recreate the agent without manually deleting the orphan first
- User confusion — the dialog shows an error but the agent partially exists in the agent list
Steps to reproduce
- Open AI Builder dialog, configure an agent
- Simulate a failure on step 2 or 3 (e.g., set an invalid model ID, or Gateway becomes temporarily unavailable after step 1)
- Observe: agent is created but incomplete
- Try to create the same agent again — fails with duplicate name/workspace error
Expected behavior
If any step in the creation sequence fails after the agent is created, the agent should be rolled back (deleted) to leave a clean state for retry.
Suggested fix
Wrap the three-step flow in a transaction-like pattern: if updateAgent or setAgentFile fails after createAgent succeeds, call deleteAgent to clean up before surfacing the error to the user.
Context
Raised in PR #261 review. Deferred as a known risk — the current implementation shows the error and keeps the dialog open, but does not roll back the partial creation.
References
- PR: [Feat] AI-guided agent creation dialog #261
- File:
packages/desktop/src/renderer/components/AgentBuilderDialog/index.tsx(handleCreate)