fix: DeploymentStatus ORM binds by member name, Postgres enum expects .value#204
Draft
shehabyasser-scale wants to merge 1 commit intomainfrom
Draft
fix: DeploymentStatus ORM binds by member name, Postgres enum expects .value#204shehabyasser-scale wants to merge 1 commit intomainfrom
shehabyasser-scale wants to merge 1 commit intomainfrom
Conversation
Migration 2026_03_30_1900_deployments_4a9b7787ccd7 creates the Postgres
deploymentstatus enum with the string values (Pending/Ready/Failed), but
the ORM column was declared as SQLAlchemyEnum(DeploymentStatus) without
values_callable=. SQLAlchemy's default behavior serializes enum members by
NAME (PENDING/READY/FAILED), so every INSERT into deployments failed with:
asyncpg.exceptions.InvalidTextRepresentationError:
invalid input value for enum deploymentstatus: "READY"
This hit every agent registered after PR #181 landed (the versioned-
deployment rollout that introduced the deployments table). Agent pods
crash-looped on startup because Application startup failed after the
registration 500, and SGP deploys reported unhealthy.
Passing values_callable=lambda enum_cls: [e.value for e in enum_cls]
makes SQLAlchemy emit .value ("Ready") to match the migration's enum.
Added a code comment pointing at the migration file to make the coupling
obvious to future readers.
Linear: EE-45
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
One-line fix to the
DeploymentORM.statuscolumn — passvalues_callable=so SQLAlchemy serializes by the enum's.valueinstead of its member name, matching the Postgres enum created by the companion migration.Why
Migration
agentex/database/migrations/alembic/versions/2026_03_30_1900_deployments_4a9b7787ccd7.py:29creates thedeploymentstatusenum with'Pending', 'Ready', 'Failed'. The Python enum uses the same strings as.values:PENDING = "Pending", etc.But the ORM column at
agentex/src/adapters/orm.py:241was declared as plainSQLAlchemyEnum(DeploymentStatus), and SQLAlchemy's default is to serializeEnummembers by name. So every INSERT tried to write"READY"/"PENDING"/"FAILED"into a column that only accepts"Ready"/"Pending"/"Failed", and failed with:Introduced in #181. Any agent pod that registers with
AGENTEX_DEPLOYMENT_ID(SGP's versioned-deployment flow) crash-loops on startup becauseregister_agentgets a 500, Uvicorn exits withApplication startup failed, and k8s restarts the pod forever. Observed on sgp-dev today hitting every agent on the new registration path.Fix
Added a code comment calling out the coupling to the migration so future readers don't re-break this.
Test plan
agentex/tests/still green locally (make testor equivalent)AGENTEX_DEPLOYMENT_IDset — pod registers cleanly, deployment row lands withstatus = 'Ready', SGP rollout reaches healthyagent.acp_urlregistration path (nodeployment_id) continue to work unchangedDeploymentStatus.READYcomparisons indeployment_repository.py:96-99still match DB values round-tripped through this bindingLinked
[ ] Verify migration applies cleanlywas unchecked)🤖 Generated with Claude Code