What the agent does
The agent looks at how the existing timestamp was done, because the new one should match it or improve on it knowingly. In an app like fastapi/full-stack-fastapi-template, User and Item in backend/app/models.py each declare created_at: datetime | None = Field(default_factory=get_datetime_utc), where get_datetime_utc returns datetime.now(UTC). Revision fe56fa70289e added those columns as DateTime(timezone=True), nullable and without a backfill, so rows older than that revision have no creation time. Nothing records when a row last changed. The agent then finds every place a row is updated: update_item in app/api/routes/items.py, update_user_me, update_password_me and the superuser's update_user in routes/users.py, crud.update_user, and a quieter one in crud.authenticate, which saves a new hashed_password when verify_password returns an upgraded hash.
That list is the reason it does not set the field by hand in each function. Several call sites today means one more tomorrow that forgets. The column gets its value from the model instead: updated_at is declared with the same default factory and with sa_column_kwargs={"onupdate": get_datetime_utc}, so SQLAlchemy fills it in whenever it emits an UPDATE for the row, through the ORM or through a Core update() statement. The agent names the column type explicitly as a timezone-aware DateTime so the new column is the same kind as the one the earlier migration created. It then states the two limits of this approach in the pull request. A write that bypasses SQLAlchemy, such as SQL typed into a console, does not touch the column, and a request that changes nothing produces no UPDATE and so leaves the timestamp where it was.
The migration is generated the way backend/README.md describes, uv run alembic revision --autogenerate, and then edited, because autogenerate writes only the add_column. Existing rows need a value, and created_at cannot be relied on to supply it, so the backfill sets updated_at to created_at where there is one and to the migration's own time where there is not. The agent reads the generated file for anything it did not ask for, in particular a type change on created_at, since that field names no column type in the model and the revision that created it does; an unrelated difference is reported, not shipped inside this revision. The downgrade drops the two columns.
The API shows the field through ItemPublic and UserPublic, which already carry created_at, and the frontend's typed client is generated from the OpenAPI document by scripts/generate-client.sh, so the agent regenerates it and commits the result. To test, it installs PostgreSQL from system packages in place of the db service in compose.yml, runs uv run bash scripts/prestart.sh to apply migrations and seed the superuser, and adds tests beside the existing ones in tests/api/routes: update an item and see updated_at move past created_at; update a user; change a password; send an update with identical values and see the timestamp stay. The migration is applied up, down and up again on a database that holds rows, and scripts/tests-start.sh and scripts/lint.sh run last.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "codex",
"input": "The linked issue asks for a last-modified time on users and items in this FastAPI and SQLModel backend. Read backend/app/models.py, every Alembic revision, app/alembic/env.py, app/crud.py, every route file, the tests, backend/README.md, scripts/generate-client.sh and the backend test workflow first. Note how created_at is declared in the models and how the revision that added it defined the column. List every code path that updates a user or an item, including ones that are not update endpoints. Add an updated_at field to both table models that is set on insert and changes automatically on every update SQLAlchemy emits, without setting it by hand in routes or CRUD helpers, and give it an explicit timezone-aware column type. Add it to the public response models. Generate the migration with Alembic's autogenerate as the README describes, then edit it to backfill existing rows from created_at, falling back to the current time where created_at is null, and read the generated file for changes you did not ask for; report those instead of including them. Install PostgreSQL from system packages and say which version. Apply the migration up, down and up again on a database that already has rows. Add tests for updating an item, updating a user, changing a password and an update that changes nothing, and run the prestart, test and lint scripts as CI does. Regenerate the frontend client with the repository's script. In the pull request, say which kinds of write do not change updated_at with this approach and what a database trigger would add.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
A pull request with two new fields in backend/app/models.py, one Alembic revision, the regenerated client under frontend/src/client, and new tests. No route or CRUD function is edited to set the field, and the description says so first, since that is the design decision: the list of update paths is there, each marked as covered by the column's own onupdate.
The migration section shows the revision as edited, with the backfill statement and the reasoning for its fallback, and the output of applying it up, down and up on a seeded database. If autogenerate proposed anything besides the new columns, that diff is quoted with a sentence on why it was left out. The test and lint script output from the sandbox follows, with the PostgreSQL version it ran on.
The reviewer has two things to judge. One is whether ORM-level updating is enough or whether other writers exist, such as a reporting job that updates rows with raw SQL, in which case the trigger described at the end of the pull request is the follow-up. The other is the password rehash on login: it is a real write to the user row, so it moves updated_at, and the team may or may not want a login to count as a modification.
Run it on every Linear issue labelled schema
Small schema additions like this one are filed as issues and wait for someone with a free afternoon. Add an automation to the Project in the console with a linear trigger on linear.issue.labeled and schema in its labels. Keep the saved prompt general: read how existing columns are declared and migrated, list every write path, generate and then edit the migration, apply it both ways on a database with rows, regenerate the client. The issue is added after the prompt and names the tables and the field.
The trigger needs a Linear connection for the person the automation runs as, made under Settings → Connections, and it fires only when someone in your Rush org adds the label. Two schema issues at once mean two branches that each add an Alembic revision on the same parent, so merge one and let the second run be repeated on the new head.
The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.
Why run it on Rush?
A migration that backfills data has to be run against data. The agent creates a PostgreSQL database in its own sandbox, seeds it through the application, and applies the revision up, down and up with rows present, which is the case that fails when a backfill is wrong. Each command and its output is kept in the run's record, so the pull request quotes real alembic output and not a description of what should happen.
The run also carries the change across the boundary that usually gets forgotten. Models, migration, response schemas, the generated frontend client and tests arrive in one branch. Nobody's local database ends up on a revision that the final pull request no longer contains, because the experiment happened somewhere that is thrown away afterwards.
Frequently asked questions
Why not use a database default and trigger instead?
A trigger is the stronger guarantee, since it fires for every writer including raw SQL. It also puts logic in the database that the models do not show, and it needs a hand-written migration per table. The agent uses the ORM hook by default, explains the difference, and writes the trigger version if the issue asks for it.
Does updated_at change when a request sends the same values?
No. SQLAlchemy emits an UPDATE only for attributes that changed, and with nothing changed there is no statement for the hook to attach to. One of the new tests pins this, so the behaviour is a documented choice and not a surprise.
Will the new column be nullable like created_at?
After the backfill every row has a value, so the agent can make it non-null in the same revision and says which it chose. It leaves created_at as it found it. Tightening that column is a different change with its own backfill question.
Does this work with SQLite or MySQL?
The model declaration is the same on any database SQLModel supports. The migration's backfill is plain SQL that the agent writes for the dialect your Alembic configuration targets, and it runs the tests on that database in the sandbox.