Skip to content

[Bug] Agent Builder: non-atomic three-step creation leaves orphaned agent on partial failure #263

@samzong

Description

@samzong

Description

The Agent Builder dialog creates an agent through three serial IPC calls:

  1. createAgent — creates the agent with name + workspace
  2. updateAgent — sets the model
  3. setAgentFile — writes IDENTITY.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

  1. Open AI Builder dialog, configure an agent
  2. Simulate a failure on step 2 or 3 (e.g., set an invalid model ID, or Gateway becomes temporarily unavailable after step 1)
  3. Observe: agent is created but incomplete
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1: Post-Launch Week 1Ship within one week after launcharea/gatewayGateway Integration WGkind/bugCategorizes issue or PR as related to a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions