What the agent does
The agent reads the server as it is. In a crate shaped like basics/todo in actix/examples it opens the workspace Cargo.toml and finds edition 2024, rust-version 1.98 and actix-web at 4.11, then the crate's own Cargo.toml with actix-files, actix-session on the cookie-session feature, sqlx 0.9 with runtime-tokio, tls-rustls and sqlite, tera 2 for templates and serde for the forms. In src/main.rs it sees HttpServer::new bind 127.0.0.1:8080 with two workers and register four services: / for the task list, /todo for creating one, /todo/{id} for toggling or deleting, and /static through Files, wrapped in Logger, a SessionMiddleware on a cookie store and an ErrorHandlers that swaps 400, 404 and 500 bodies for the HTML pages under static/errors.
There is no route a load balancer can poll, and the only place the database is touched is inside a page handler. src/db.rs builds the pool in init_pool with SqlitePoolOptions and a one-second acquire_timeout, and every handler in src/api.rs takes web::Data<SqlitePool>. So the agent adds two handlers to api.rs: health_live, which answers 200 with {"status":"ok"} and touches nothing, and health_ready, which takes the pool, runs sqlx::query("SELECT 1").execute(pool.get_ref()) and answers 200 with {"status":"ok","database":"ok"} or 503 with the error string when the pool cannot acquire a connection inside its timeout. Both are registered in main.rs as web::resource("/health/live") and web::resource("/health/ready") on GET, before the Files service so a static-file lookup never shadows them.
Two details the agent gets right because it read the code. The ErrorHandlers wrapper rewrites 500 responses into static/errors/500.html, so readiness must answer 503, not 500, or the JSON body would be replaced by an HTML page; the agent notes this in a comment beside the handler. And serde_json is not in the crate's dependency list even though serde is, so the agent adds it from the workspace dependency table with serde_json.workspace = true rather than pinning a version of its own, matching how every other dependency in the crate is declared.
Tests go in a #[cfg(test)] module in api.rs using actix_web::test: init_service builds an App with only the two health resources and a pool opened on sqlite::memory:, then TestRequest::get().uri("/health/ready") is sent and the status and JSON body asserted. A second case builds the pool against a path that cannot exist and asserts 503. The agent runs cargo test -p todo the way ci.yml runs the workspace, with DATABASE_URL=sqlite://./todo.db set and the migration under basics/todo/migrations applied by sqlx migrate run first, since the crate's query macros check the schema when SQLX_OFFLINE is off. Then it runs cargo clippy for the crate, as the repository's justfile does, and opens a pull request.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Add health checks to this Actix Web server. Add GET /health/live that returns 200 with a JSON status and GET /health/ready that runs SELECT 1 on the SQLite pool and returns 200 or 503 with a JSON body, register both in main.rs ahead of the static files service, keep the readiness failure at 503 so the ErrorHandlers middleware does not replace the body, add tests with actix_web::test for both routes including a 503 case, run cargo test and cargo clippy for the crate, and open a pull request.",
"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
What comes back is a pull request on its own branch. The diff adds two handlers and a test module to src/api.rs, two web::resource lines to src/main.rs, and one serde_json.workspace = true line to the crate's Cargo.toml. Cargo.lock changes only if serde_json was not already in the workspace graph. The description names both paths, shows the two JSON bodies, and says which one a Kubernetes readinessProbe or a load balancer should poll and why liveness must not touch the database.
The repository's CI runs the proof again. .github/workflows/ci.yml creates todo.db, runs sqlx migrate run --source=./basics/todo/migrations and then cargo test --workspace --all-features --no-fail-fast, so the new cases run on the pull request on stable Rust. The session's trajectory at GET /o/{org}/sessions/{id}/messages keeps every cargo test and cargo clippy invocation with its output, including a failing run if the agent had to fix a type error first.
Before merging, a reviewer checks that /health/ready answers 503 rather than 500 on a dead pool, that the readiness query goes through the shared web::Data<SqlitePool> and not a second connection, and that neither route is behind the session middleware's cookie in a way that would make a probe without cookies fail. The sandbox pushes one branch and nothing else.
Run it on every new Rust service
A team that runs several Actix Web services behind the same ingress starts one run per repository with POST /o/{org}/sessions, this prompt and that repository in resources. Each run reads its own main.rs and its own pool type, so a service on Postgres gets SELECT 1 through its PgPool and a service with a Redis client gets a ping on that as well, and each opens its own pull request. Send a request_id per run so a retried request does not start a second sandbox.
Set a webhook_url on the API key and every run the key starts posts run.completed or run.failed when it finishes, with a session_url for the result, so a script can collect the pull request links. The key runs at most max_concurrent sessions at once, 4 by default; a request beyond that is accepted as 202 with status: "queued", and that run starts, oldest first, when a slot frees.
The use case this job follows, with its automation and trigger: Hand off a long task.
Why run it on Rush?
Health checks are small, but testing them honestly in this crate means a SQLite database on disk, the migration applied with sqlx-cli, and a cargo test that compiles the query macros against it, which on a laptop is a tool install and ten minutes before the first assertion runs. On Rush the run has its own sandbox with a computer in it: the agent installs sqlx-cli the way ci.yml does, creates the database, runs the suite as many times as it takes, and your own checkout is never touched.
The result is a pull request with evidence rather than a note that says it works. The diff is a few dozen lines across three files, the CI workflow the repository already has runs the new tests on the pull request, and the trajectory keeps every cargo test and cargo clippy with its output so a reviewer can read the 503 case passing. Several services mean several sandboxes and pull requests at once.
Frequently asked questions
Why two routes instead of one /health?
Because they answer different questions. /health/live says the process is up and should answer even when the database is unavailable, so an orchestrator does not restart a healthy process for a database outage. /health/ready says the service can serve traffic, which for this crate means the SQLite pool can hand out a connection within its one-second acquire_timeout. If you want a single /health, say so in the prompt and the agent folds both into one body.
Why 503 and not 500 on a failed readiness check?
The ErrorHandlers middleware in main.rs rewrites every 500 into the static/errors/500.html page, so a JSON readiness body on 500 would never reach the probe. 503 is not in that handler list, so the JSON passes through unchanged, and it is the status a load balancer treats as temporarily out of rotation rather than broken.
Does the readiness check hold a connection open?
No. sqlx::query("SELECT 1").execute(pool) acquires a connection from the pool, runs the statement and returns it when the future completes. The cost is one trivial query per probe. If the pool is exhausted the call waits up to the pool's acquire_timeout and then errors, which is what the 503 reports.
How do the tests run without the app's cookie session?
The test module builds an App with only the two health resources and a pool, not the full middleware stack from main.rs, because the probes should not depend on a session. A reviewer who wants the integration path covered as well can ask for a case that builds the whole App closure and sends a request with no cookie, and the agent adds it.
Will it add a crate I did not ask for?
Only serde_json, for the JSON bodies, and only through the workspace's existing dependency table rather than a new version pin. actix-web already depends on it transitively, so Cargo.lock usually does not change. The pull request description lists every dependency line it touched.
More Actix Web jobs
The same job on other stacks
- Add Health Checks to an AdonisJS API (AdonisJS)
- Add Health Checks to an aiohttp App (aiohttp)
- Add Health Checks to an ASP.NET Core App from a Linear Issue (ASP.NET Core)