What the agent does
Python 3.13 removed cgi and cgitb, and the first job is to find out when your users hit it. In a library like mail-ru-im/bot-python the answer is: after a successful install. setup.py does import bot to read bot.__version__, but bot/__init__.py only imports logging, so the build works. python_requires is >= 2.7 with a few early 3.x releases excluded, so pip installs the package on 3.13 without complaint. The failure comes on the first line of bot/bot.py, import cgi, which is the module every user imports: example/echo_bot.py starts with from bot.bot import Bot. The repository's workflow, .github/workflows/python-package.yml, tests a matrix of exactly one version, "3.11", so nothing told the maintainers.
The agent creates a 3.13 environment, installs requirements.txt, runs the import and keeps the traceback. Then it lists every use of the module, because the right replacement depends on the function. Here there is one, in LoggingHTTPAdapter._is_loggable: cgi.parse_header(headers.get("Content-Type", ""))[0], whose result is matched against a pattern that accepts text/... and four application/ types to decide whether a request or response body is written to the debug log. The module's removal notice points to email.message.Message for this: set the header on a message and call get_content_type().
That advice is correct for well-formed headers and wrong for this function, and the agent finds out by running both on the same inputs before it edits anything. With no Content-Type, cgi.parse_header("") returns an empty string, the pattern does not match and the body is not logged. Message.get_content_type() never returns an empty string: with no header, or one it cannot parse such as garbage, it answers text/plain. The pattern matches that, so after the documented replacement the adapter starts logging bodies it used to skip, including ones with no declared type. Since the code only wants the media type, the agent uses the smaller replacement that keeps the old answers, splitting the header at the first ; and stripping whitespace, and puts the comparison table in the pull request.
Then it runs what the repository has. The tests live in example/test_bot_new.py and start the HTTP server in example/server.py on localhost:8080 with a placeholder token, so they need no network access and no real bot. The agent runs pytest on 3.13 and on 3.11, adds a test for the header helper with the values from its table, and adds "3.13" to the workflow matrix. It also reports the other pins it had to look at on the new interpreter, such as requests ==2.31.0 and urllib3 ==1.26.18 in requirements.txt, and the classifiers in setup.py, which stop at 3.10. It changes those only if the install or the tests require it.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Importing this package on Python 3.13 fails with \"ModuleNotFoundError: No module named 'cgi'\". Create a Python 3.13 virtual environment, install the project's requirements, import the package's main module and run its tests, and save each traceback. List every use of cgi and cgitb in the package, scripts and examples, by function: parse_header, parse_multipart, FieldStorage, escape, parse_qs, cgitb.enable. Before editing, write a script that runs the old call on Python 3.11 and each candidate replacement on 3.13 with the same inputs, including an empty value, a value with parameters, mixed case, and a malformed value, and print the results side by side. Choose the replacement that keeps the old results for how this code uses them: for parse_header consider email.message.Message and a plain split on the first semicolon; for FieldStorage use the parser of the web framework in use or a maintained multipart library; cgi.escape is html.escape and parse_qs is urllib.parse.parse_qs. Do not add the legacy-cgi package unless nothing else fits, and say why if you do. Add tests for the replaced calls using the inputs from the script. Run the full suite on 3.13 and on the oldest version the CI workflow tests, add 3.13 to the workflow's version matrix, and open a pull request with the comparison table and the test output. List dependency pins or metadata you noticed but did not change.",
"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 that removes import cgi from bot/bot.py, adds a few lines that take the media type from a Content-Type value, adds a test file for them and widens the workflow matrix. The description leads with the table: each header value, what cgi.parse_header returned on 3.11, what Message.get_content_type() returns, what the chosen code returns, and whether the body would be logged in each case. It ends with the pytest summary on both interpreters.
The reviewer's question is whether logging behaviour changed, and the table answers it row by row. If they would rather follow the standard library's suggested replacement and accept that untyped bodies are logged as text, the description says which two rows change and the prompt has the line to edit. The classifiers and the old pins are listed as observations, so a reviewer can see that 3.13 support was proven by a test run and not by a metadata edit.
Run it on every GitHub issue labelled python-3.13
Users report this error as an issue with the traceback pasted in. Add an automation on the Project with a github trigger on issues.labeled and a label such as python-3.13, with the prompt above. The labelled issue is added after the prompt as event text, and the prompt remains the only instruction: the issue body reaches the agent marked as third-party data.
If you would rather find it before users do, a schedule trigger can run the same prompt weekly. A run that finds no cgi import reports that and opens no pull request.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
The risky part of this fix is not the import. It is that the suggested replacement returns a default where the old function returned nothing, and code written around the old answer keeps running with the new one. Seeing that takes two interpreters side by side, one that still has cgi and one that does not. The sandbox can hold both and run the same script on each, and the outputs are kept with the run, so the table in the pull request is copied from commands and not from memory of how a parser behaves.
It also checks the claim that matters to users: that a fresh 3.13 environment can install the pinned requirements, import the package and pass the tests. A laptop with one interpreter and a warm cache answers a different question.
Frequently asked questions
What is the replacement for cgi.parse_header?
The removal notice for the module recommends email.message.Message: assign the header value to msg["Content-Type"], then call msg.get_content_type() for the type and msg.get_params() for the parameters. It lowercases the type and falls back to text/plain when the header is missing or malformed. If your code treats a missing type as empty, handle that case before calling it.
Can I install legacy-cgi and move on?
Yes. legacy-cgi on PyPI is a copy of the removed modules and makes import cgi work again on 3.13 with no code change. It is a reasonable stopgap for an application you deploy yourself. For a library it adds a dependency to every user's install to keep one function call, which is why the agent prefers replacing the call.
Why did pip install the package on 3.13 if it does not work there?
pip checks python_requires, and a range with a lower bound and no upper bound admits every future interpreter. The classifiers that list supported versions are labels and are not enforced. The only check that would have caught this is a test run on the new version, which is what the agent adds to the workflow.
What about cgi.FieldStorage?
There is no standard library replacement for parsing uploaded form data. Inside a web framework, use the framework's request object. In a standalone script, use a maintained multipart parser. The agent names the option it picked and adds a test that posts a small file through it.