Skip to content

fix(server): require control data on create#139

Merged
lan17 merged 5 commits intomainfrom
fix/issue-138-atomic-control-create
Mar 20, 2026
Merged

fix(server): require control data on create#139
lan17 merged 5 commits intomainfrom
fix/issue-138-atomic-control-create

Conversation

@lan17
Copy link
Contributor

@lan17 lan17 commented Mar 20, 2026

Summary

  • require data on PUT /api/v1/controls instead of allowing name-only shell control creation
  • validate the control definition before insert so invalid create requests return 422 and persist nothing
  • update Python SDK, TypeScript SDK, UI API types, tests, and shipped examples to use the single-request atomic create flow
  • keep legacy empty-control behavior only for existing rows/read paths covered by targeted compatibility tests

Bug Explanation

For a create-with-definition flow, the client did:

  1. PUT /api/v1/controls with just name
  2. the server inserted an empty shell control
  3. PUT /api/v1/controls/{id}/data with the definition
  4. if step 3 returned 422, the empty shell from step 2 was still in the DB

That is the concrete bug this PR fixes. Invalid create requests were not atomic, so callers could end up with persisted empty {} controls even though the overall create-with-definition flow had failed.

One nuance: the agent association part was caller-flow dependent. The root server-side invariant failure was the persisted shell control after invalid data, and that is what this change removes.

Testing

  • cd server && uv run pytest tests/test_controls.py tests/test_controls_additional.py tests/test_controls_validation.py tests/test_agents_additional.py tests/test_auth.py tests/test_control_compatibility.py tests/test_error_handling.py tests/test_evaluation_e2e.py tests/test_evaluation_error_handling.py tests/test_init_agent.py tests/test_init_agent_conflict_mode.py tests/test_new_features.py tests/test_policies.py tests/test_policy_integration.py -q
  • make lint
  • make typecheck
  • make sdk-ts-build
  • make ui-typecheck (still fails on pre-existing unrelated UI dependency/type issues)

Closes #138

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
sdks/python/src/agent_control/controls.py 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@lan17 lan17 changed the title fix(server): create controls atomically when data is provided fix(server): require control data on create Mar 20, 2026
Copy link
Collaborator

@abhinav-galileo abhinav-galileo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving - but let's address this:
#139 (comment)

@lan17 lan17 merged commit 3e4935b into main Mar 20, 2026
6 checks passed
@lan17 lan17 deleted the fix/issue-138-atomic-control-create branch March 20, 2026 22:18
galileo-automation pushed a commit that referenced this pull request Mar 20, 2026
## [2.1.0](ts-sdk-v2.0.0...ts-sdk-v2.1.0) (2026-03-20)

### Features

* **examples:** Feat/crewai examples expansion port ([#142](#142)) ([905e83b](905e83b))

### Bug Fixes

* **server:** require control data on create ([#139](#139)) ([3e4935b](3e4935b)), closes [#138](#138)
* **server:** separate compose host port overrides from runtime ports ([#137](#137)) ([da05f98](da05f98))
@galileo-automation
Copy link
Collaborator

🎉 This PR is included in version 2.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(server): when creating invalid control, an empty control is created in DB

3 participants