Skip to content

Guard against duplicate agent_ids across agents#66

Merged
even-steven merged 2 commits into
mainfrom
stevenchand/sc-16755/when-adding-a-client-id-to-an-agent-ensure
Jun 12, 2026
Merged

Guard against duplicate agent_ids across agents#66
even-steven merged 2 commits into
mainfrom
stevenchand/sc-16755/when-adding-a-client-id-to-an-agent-ensure

Conversation

@even-steven

Copy link
Copy Markdown
Contributor

Summary

  • Backend conflict check: CheckAgentIDConflict added to AgentsRepo; called in both POST and PATCH /api/v1/admin/agents before writing — returns 409 Conflict with a message naming the conflicting ID and its owner agent.
  • Deterministic fallback: GetByAgentID now includes ORDER BY id so behaviour is consistent if duplicates somehow reach the DB.
  • Intra-record dedup: parseAgentIDs deduplicates within a single agent's array, preventing badge-count inflation.
  • UI validation: CreateAgentModal and EditAgentModal check the cached agent list before submitting; on conflict the error alert lists each duplicate ID and the agent that owns it (e.g. vmclient is already in use by "AMP").
  • Better error extraction: errorMessage helper now prefers err.response.data.error.message (the API body) over the raw axios status line, so backend errors like 409 surface their human-readable text.
  • Observability: agentByAgentID in Invocations.tsx logs a console.warn when a collision is detected.

Test plan

  • Create two agents; add the same agent ID to both — confirm the second save is blocked with the descriptive error in the UI
  • Verify the same ID can be re-saved on the agent that already owns it (edit modal excludes self from the check)
  • Confirm go test ./internal/... passes
  • Confirm the Invocations page still resolves agent badges correctly with non-duplicate data

Made with Cursor

- Backend: add CheckAgentIDConflict to AgentsRepo; call it in POST and
  PATCH /admin/agents handlers, returning 409 with a descriptive message
  when a submitted agent_id is already owned by a different agent
- Backend: add ORDER BY id to GetByAgentID so resolution is deterministic
  even if duplicates exist in the DB
- Backend: deduplicate within parseAgentIDs to prevent badge inflation
  when the same ID appears twice in one agent's array
- UI: client-side conflict validation in CreateAgentModal and
  EditAgentModal before the API call fires; error lists each conflicting
  ID and the name of the agent that owns it
- UI: extract API response body in errorMessage helper so 409 (and other
  backend errors) show the human-readable message instead of the raw
  axios status line
- UI: console.warn in agentByAgentID map when a duplicate is detected

Co-authored-by: Cursor <cursoragent@cursor.com>
@shortcut-integration

Copy link
Copy Markdown

This pull request has been linked to Shortcut Story #16755: When adding a client_id to an agent ensure unique.

Comment thread internal/api/handlers.go Outdated
Move CheckAgentIDConflict before the UpdateEnabled call so we validate
all inputs before making any writes, per PR review feedback.

Co-authored-by: Cursor <cursoragent@cursor.com>
@even-steven even-steven merged commit e8b6cf9 into main Jun 12, 2026
3 checks passed
@even-steven even-steven deleted the stevenchand/sc-16755/when-adding-a-client-id-to-an-agent-ensure branch June 12, 2026 18:27
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.

2 participants