All jobs

Review Pull Requests Automatically in a Flask App

An agent reviews a CTFd pull request that rejects a null max_attempts, runs 726 tests and ruff, and finds no blocking issue and six suggestions.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The pull request, CTFd/CTFd #3132, stops the challenges API from accepting a null or negative max_attempts. The agent reads the new validator in CTFd/schemas/challenges.py beside the model in CTFd/models/__init__.py, where Challenges.max_attempts is still a nullable db.Column(db.Integer, default=0), and the attempt check in CTFd/api/v1/challenges.py, which only enforces a limit when max_tries and max_tries > 0.

It also reads the data migration b7d2e4f6a8c1_set_null_challenge_max_attempts_to_0.py, the min="0" added to the admin template challenges/update.html, and how serializeJSON in the admin JavaScript sends a blank field, then runs pytest and ruff check on the PR head.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Review this pull request. Check it out, install dependencies with pip, run `pytest`, and read the diff with the surrounding code in the challenges API. Post one GitHub review that cites file and line for every finding, separates blocking issues from suggestions, and includes the test result. Do not push commits.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app/pull/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 CTFd/CTFd at afa27fb: pull request #3132 (4 files changed, 93 insertions(+), 1 deletion(-)), reviewed with no blocking findings and 6 suggestions, five of them citing file and line. tests/api/v1/test_challenges.py returned 75 passed, 190 warnings in 46.04s and ruff check printed All checks passed!. The full suite ended 1 failed, 725 passed: the failure, test_update_check_ignores_downgrades, is in update-check code the pull request does not touch. The review was not posted.

For the reviewer: whether validating in the API schema is enough or the column needs NOT NULL, and what an admin sees after clearing the field, which the run did not try in a browser.

Run it on every pull request into master

An automation with a github trigger on pull_request.opened and pull_request.synchronize, with branch_patterns set to master (CTFd's default branch), reviews each push. A pull request from a fork fires no trigger; this trial's pull request (#3132, from a fork) was started by hand on a clone checked out at pull/3132/head.

The use case this job follows, with its automation and trigger: Review every pull request.

Why run it on Rush?

The diff is small and its tests pass, so the useful findings sit outside it: a model column that still allows NULL for imports and plugins, a one-time migration that a backup taken before the upgrade can undo, and an admin form that may send an empty string the new message never covers. The run kept the failing update-check test, which the pull request does not touch, apart from the review and said it could not confirm it fails on master.

Frequently asked questions

What did the run install to get pytest going?

pip refused system installs and the image's venv lacked ensurepip, so it installed virtualenv, made a venv, then requirements.txt and the pyproject.toml dev group (pytest 8.4.2, xdist, cov, moto, Faker, ruff).

Which tests did it suggest adding?

The new test covers POST with None and PATCH with None, -1, 0 and 5. It suggests a POST with -1, a POST with max_attempts omitted that asserts it defaults to 0, and notes that nothing tests the migration.

More Flask jobs

The same job on other stacks

Keep reading