What the agent does
The agent reads read_items in backend/app/api/routes/items.py before changing it. It had two copies of the same query, one for superusers and one filtered to the caller's owner_id, each with its own count statement. Adding q to both would have meant four statements to keep in step.
So it builds one list of conditions: the owner filter for non-superusers, and col(Item.title).icontains(q, autoescape=True) when q is not empty. The count and the page share that list, so skip, limit and count apply to the filtered set. Five tests in backend/tests/api/routes/test_items.py cover a normal user's own items, a superuser across owners, pagination, an empty q, and % treated literally.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Implement the GitHub issue supplied after this prompt in this FastAPI repository. Read the issue and the routes it names before changing anything, and keep the existing owner and superuser rules. Add tests beside the existing route tests for each acceptance criterion. Run the backend tests against a disposable local Postgres and the backend lint script, before and after. Open a pull request whose description includes Closes #<issue>, the test and lint output, and any reading of the issue a reviewer should confirm. If no issue follows this prompt, stop and say so.",
"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
Tried on fastapi/full-stack-fastapi-template at f4bcfab: an issue written for this trial, asking GET /api/v1/items/ to take an optional q. 2 files changed, 131 insertions(+), 24 deletions(-) in items.py and test_items.py. bash scripts/test.sh went from 58 passed, 55 warnings in 8.82s to 63 passed, 60 warnings in 10.22s, and bash scripts/lint.sh ended 19 files already formatted before and after. The first version failed mypy on the type of conditions, which the agent fixed.
For the reviewer: % and _ in q match literally; treating them as wildcards is the other reading of the issue. q has no length cap and no index supports the ILIKE, and the generated frontend client needs regenerating to use it.
Run it on every GitHub issue labelled api
An automation with a github trigger on issues.labeled and the label api runs this prompt when a maintainer labels a feature request filed by an owner, member or collaborator. Acceptance criteria written in the issue, like an empty q being ignored, become the tests the agent writes first.
The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.
Why run it on Rush?
The obvious change adds q to each branch of read_items and leaves a count that ignores the filter. This run merged the branches first, so the filtered count is right by construction, and a test proves count is 3 when one of three matches is returned.
Frequently asked questions
Does the lint script check the new tests?
No. backend/scripts/lint.sh runs mypy and ruff on app only. The agent ran ruff format on the test file, but ruff check and mypy never see tests/.
What database did the tests run on?
A local Postgres 16.4 started as a plain process, with migrations applied by scripts/prestart.sh. The first attempts failed with 58 errors from setup faults, a SQL_ASCII cluster and a missing uuid-ossp, not from the code.