# Turn Linear Issues into Pull Requests for a FastAPI App

An agent adds soft delete and a restore route to the FastAPI full-stack template's items, with an Alembic migration and 5 tests; coverage stays at 92%.

[Run this on Rush](https://cloud.getrush.ai/run/linear-issue-to-pr/fastapi/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent ran the backend's `prestart.sh`, `test.sh` and `lint.sh` on the untouched clone first: all passed, 58 tests. It then added `deleted_at: datetime | None = None` to `Item` and `ItemPublic` in `backend/app/models.py` and let Alembic autogenerate `7a68868d1a05_add_deleted_at_to_item.py`.

In `backend/app/api/routes/items.py`, the list queries filter `deleted_at IS NULL`, read, update and delete answer 404 for a deleted item, DELETE sets `item.deleted_at = get_datetime_utc()`, and `POST /items/{id}/restore` clears it behind the same 404 and 403 guards. Five tests in `backend/tests/api/routes/test_items.py` cover them.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Do the work the Linear issue given as a resource describes: add a soft delete for items with a restore endpoint. Read the issue and its comments first. Follow this project's patterns: a nullable deleted_at on the Item model and ItemPublic, an Alembic autogenerated migration in app/alembic/versions, the list and read endpoints hiding deleted items, DELETE setting deleted_at instead of removing the row, and a POST /items/{id}/restore route with the same 404 and 403 guards as the other item routes. Add pytest tests beside tests/api/routes/test_items.py for delete, hidden-after-delete, restore and the permission refusal. Start Postgres, run bash scripts/prestart.sh, bash scripts/test.sh and bash scripts/lint.sh, regenerate the frontend client with scripts/generate-client.sh, and open a pull request whose description links the issue and quotes the coverage line. Do not merge.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    },
    {
      "url": "https://linear.app/your-org/issue/ENG-42"
    }
  ]
}
```

1. **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.
2. **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.
3. **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: 7 files changed, 219 insertions(+), 13 deletions(-). `backend/scripts/test.sh`, run from `backend/`, went from 58 to 63 passed and ended `TOTAL                          585     45    92%`; `backend/scripts/lint.sh` passed after one `ruff format` fix, and `scripts/generate-client.sh` exited 0. The run got no Linear issue: none was attached and its searches found none, so it worked from the request's own description, and nothing was pushed or opened. Without Docker, it installed Postgres 15 and uv 0.13.6, and reverted the `uv.lock` rewrite.

For the reviewer: restoring an item that was never deleted is a 200 no-op, deleting one twice is a 404, and restore is open to the owner and superusers. Autogenerate typed the column `sqlmodel.sql.sqltypes.UTCDateTime()` where the older migration used `sa.DateTime(timezone=True)`; the run left it unedited.

## Run it on every Linear issue labelled agent

An automation with a `linear` trigger on `linear.issue.labeled` and the label `agent` runs the recipe's prompt with the labelled issue as its context. This trial had no issue attached, so it had no acceptance criteria to check the soft-delete choices against.

## Why run it on Rush?

Soft delete is easy to half-do: the row survives, but a read, an update or a second delete still reaches it. This change answers 404 on all three, and the 403 test checks that a refused restore leaves the item deleted. The run also named a gap it did not close: the normal-user branch of the list route, lines 43 to 56 of `items.py`, has no test.

## Frequently asked questions

### Does the frontend get a restore button?

No. The regenerated client gains `ItemsService.restoreItem` and `deleted_at` on `ItemPublic`, but the frontend has no UI for restore.

### Where are the scripts the request names?

`prestart.sh`, `test.sh` and `lint.sh` live in `backend/scripts/`; the root `scripts/test.sh` needs Docker. `scripts/generate-client.sh` runs from the root after `bun install --frozen-lockfile`.

## More FastAPI jobs

- [Review Alembic Migrations in FastAPI Pull Requests](https://getrush.ai/run/review-database-migrations/fastapi/)
- [Review Pull Requests on a FastAPI API](https://getrush.ai/run/review-pull-requests/fastapi/)
- [Run a Security Audit on a FastAPI App](https://getrush.ai/run/security-audit/fastapi/)

## The same job on other stacks

- [Turn a Labeled Linear Issue Into a Pull Request on a Fastify API](https://getrush.ai/run/linear-issue-to-pr/fastify/)
- [Turn Linear Issues Into Pull Requests for a Flask App](https://getrush.ai/run/linear-issue-to-pr/flask/)
- [Turn Linear Issues Into Pull Requests for a Go Service](https://getrush.ai/run/linear-issue-to-pr/go/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
