Skip to content

feat(server): add target and target_controls management APIs (2/7)#180

Draft
abhinav-galileo wants to merge 1 commit intoabhi/rfc-1-1-pr1-tenant-targetsfrom
abhi/rfc-1-1-pr2-target-apis
Draft

feat(server): add target and target_controls management APIs (2/7)#180
abhinav-galileo wants to merge 1 commit intoabhi/rfc-1-1-pr1-tenant-targetsfrom
abhi/rfc-1-1-pr2-target-apis

Conversation

@abhinav-galileo
Copy link
Copy Markdown
Collaborator

@abhinav-galileo abhinav-galileo commented Apr 20, 2026

Stacked on top of #178. Kept in draft until the full stack has been validated end-to-end.

Summary

  • Adds REST CRUD for targets: create, get, list (optional filter by target_type), delete.
  • Adds attach / detach / toggle-enabled / list endpoints for target_controls.
  • Adds a tenant-resolution dependency (get_tenant_id) that reads an optional X-Tenant-Id header and falls back to default-tenant when absent. Callers that omit the header continue to work unchanged.
  • Registers the new router under /api/v1/targets.

Scope boundaries

  • No runtime control resolution from targets - that ships in the next PR in the stack.
  • No tenant-aware filtering on agent/control/policy endpoints - that belongs to a separate PR.
  • No lazy target upsert - deferred; clients must create targets explicitly for now.
  • No SDK or UI changes.
  • Write paths accept a tenant via the header; reads on the target endpoints are tenant-scoped from day one because the new tables are the only thing this PR touches. Existing endpoints are not modified.

Design notes

  • Attach is idempotent via INSERT ... ON CONFLICT DO NOTHING keyed on (target_id, control_id); retrying with a different enabled value updates the row.
  • Detach is idempotent-404: absent attachment returns 404 with TARGET_CONTROL_NOT_FOUND so callers can detect "already gone" explicitly.
  • Cross-tenant access returns 404, not 403, to avoid leaking the existence of rows in other tenants.
  • Admin-key requirement mirrors the existing policy / control mutation endpoints.

New error codes

  • TARGET_NOT_FOUND
  • TARGET_CONTROL_NOT_FOUND
  • TARGET_CONFLICT

Test plan

  • make check clean locally (full lint + mypy + tests; 544 server tests including 21 new endpoint tests)
  • Endpoint coverage: happy path, duplicate external_id per tenant (409), same external_id allowed across tenants, target_type filter, cross-tenant 404, delete happy / 404, attach happy / idempotent / target-404 / control-404, detach happy / 404, toggle happy / 404, list attachments, default-tenant fallback for missing / whitespace header, admin-key requirement for writes
  • Validated end-to-end on a throwaway integration branch containing PR1 + PR2 merged (all checks pass)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

❌ Patch coverage is 97.46193% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rver/src/agent_control_server/endpoints/targets.py 93.67% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr1-tenant-targets branch from a79bcbb to 6ea16b3 Compare April 20, 2026 19:39
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr2-target-apis branch from 23b990f to 46ed17b Compare April 20, 2026 19:42
@abhinav-galileo abhinav-galileo changed the title (2/N) feat(server): target + target_controls management APIs feat(server): add target and target_controls management APIs (2/4) Apr 20, 2026
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr2-target-apis branch from 46ed17b to fe437c4 Compare April 20, 2026 20:23
CRUD endpoints for targets plus attach/detach/toggle/list endpoints for
target_controls. Tenant is resolved via optional X-Tenant-Id header with
fall-through to default-tenant. New target tables are not yet wired into
runtime control resolution (separate change).
@abhinav-galileo abhinav-galileo force-pushed the abhi/rfc-1-1-pr2-target-apis branch from fe437c4 to 7067673 Compare April 20, 2026 20:28
@abhinav-galileo abhinav-galileo changed the title feat(server): add target and target_controls management APIs (2/4) feat(server): add target and target_controls management APIs (2/5) Apr 20, 2026
@abhinav-galileo abhinav-galileo changed the title feat(server): add target and target_controls management APIs (2/5) feat(server): add target and target_controls management APIs (2/6) Apr 20, 2026
@abhinav-galileo abhinav-galileo changed the title feat(server): add target and target_controls management APIs (2/6) feat(server): add target and target_controls management APIs (2/7) Apr 21, 2026
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