Skip to content

bug: Duplicate agent check relies on Docker state, not database #108

Closed

Description

@vybe

Summary

The agent creation endpoint checks for duplicate names by querying Docker containers (get_agent_by_name() → docker_client.containers.get()). If the container doesn't exist or was removed, the check passes and a duplicate agent is created with HTTP 200.

Root Cause

File: src/backend/services/agent_service/crud.py line 87-88

if get_agent_by_name(config.name):
    raise HTTPException(status_code=400, detail="Agent already exists")

get_agent_by_name() calls docker_client.containers.get(f"agent-{name}") which only finds running/stopped containers. If a container was removed but the DB record exists, the check passes.

Expected Behavior

Creating an agent with an existing name should return 409 Conflict (or 400). The check should also query the agent_ownership database table.

Fix

Add a database check alongside the Docker check:

if get_agent_by_name(config.name) or db.get_agent_ownership(config.name):
    raise HTTPException(status_code=409, detail="Agent already exists")

Also update HTTP status from 400 to 409 for semantic correctness.

Activity

  1. added
    priority-p1
    type-bug
    on Mar 14, 2026
  2. added a commit that references this issue on Mar 16, 2026
    dec3362
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-p1type-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions