What the agent does
Python 3.12 removed the module-level ssl.wrap_socket function. Code that wrapped a socket with it, most often a small HTTPS server built on http.server, now fails the moment it tries to listen. The replacement is an ssl.SSLContext object that holds the certificate and the protocol settings and has its own wrap_socket method. JPHutchins/pgesmd_self_access has the classic form. In pgesmd_self_access/server.py, SelfAccessServer creates an HTTPServer on port 7999 and replaces its socket with ssl.wrap_socket(server.socket, certfile=..., keyfile=..., server_side=True), taking both paths from the API object's cert pair. The server receives notifications from a utility's data service, so when it cannot start, data stops arriving.
The agent looks at how the failure could have been missed. The package's tests, test_api.py and test_helpers.py, never construct the server, so a suite that passes says nothing about this line. On Python 3.11 the constructor works and prints DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.wrap_socket(). On Python 3.12 it raises the title's error at line 82. To see either, something has to start the server with a certificate, and the repository's cert directory holds no certificate, as it should.
So the agent makes a throwaway certificate with openssl req -x509 for localhost, writes a test that starts SelfAccessServer on a thread with close_after=True, and sends one HTTPS POST to /test, the path the handler answers with a bare 200. On the unmodified code and Python 3.12 the test fails with the AttributeError. Then it ports the call: ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER), load_cert_chain with the same two paths, and context.wrap_socket(server.socket, server_side=True). The same test then completes a handshake and reads the 200, with the client verifying the server against the throwaway certificate.
It checks the direction of every call it ports, because the two directions differ in risk. A server-side port like this one keeps its behaviour: same certificate, same key. A client-side ssl.wrap_socket call did no certificate or hostname verification by default, and a context from ssl.create_default_context() does both. That is the correct default and it can break a client that was quietly talking to a host with a self-signed or mismatched certificate. This repository has only the server-side call, and the agent says so. Where it finds client-side calls it ports them to the verifying context and lists each host affected instead of turning verification off.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "This project fails on Python 3.12 or later with \"AttributeError: module 'ssl' has no attribute 'wrap_socket'\". Fix it. Find every call to ssl.wrap_socket and ssl.match_hostname, and any use of ssl.PROTOCOL_SSLv23 or ssl.PROTOCOL_TLS passed to them. For each call record whether it is server side or client side, which certificate, key and CA arguments it passes, and which code path reaches it. Check whether the test suite exercises any of these paths; if not, write a test that does, using a self-signed certificate generated during the test run and never committing a private key. Show the test failing on the newest Python available before the change. For server-side calls, create an ssl.SSLContext with ssl.PROTOCOL_TLS_SERVER, load the same certificate chain, and call the context's wrap_socket. For client-side calls, use ssl.create_default_context(), pass server_hostname, and load a CA file if the old call specified one; this turns certificate and hostname verification on where the old function left it off, so list every host the client connects to and say which may be affected. Do not disable verification to make something pass. Do not change ports, handlers or protocol versions beyond what the port requires. Run the new test and the existing suite on each supported Python you can install, and report results, separating failures that need network access or credentials. 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
A pull request with a small change in server.py and one new test. The description shows the test's result in three states: failing with the AttributeError on Python 3.12 before the change, passing after it, and passing on the older interpreter too, since SSLContext has been available throughout the versions the package's python_requires allows. It notes that the certificate used is generated in a temporary directory at test time and that no key material is added to the repository.
The existing suite is reported honestly. Under pytest on Python 3.12 five of its six tests pass and test_token fails with a connection error, because it calls the utility's real token endpoint. That failure has nothing to do with TLS on the listening side, and the description says so and leaves the test as it is.
What a reviewer verifies is outside the sandbox's reach: that the production certificate and key load through load_cert_chain as they did before, and that the service which posts to this server still connects after deploy. The README describes the port forwarding that deployment relies on, and the description points to it.
Run it on every service that fails to start after a Python upgrade
A listener that dies at startup produces one traceback and then silence, so the signal comes from whatever watches the process, usually an error tracker that captures the exception. Most error trackers sign their own webhook deliveries and cannot send the Authorization: Bearer header a Rush webhook trigger requires. Put a small handler on your server between them. It receives the alert, keeps the ones whose text contains has no attribute 'wrap_socket', and posts the traceback to the trigger's URL with the trigger's secret.
The traceback is placed after the saved prompt as event text, and its top frame tells the agent whether the call is in your code or in a dependency. When it is a dependency, the run's result is a version bump to the first release that uses a context, or a report that none exists. Keep the automation's max runs per hour low, because a crash loop repeats the same alert.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
A TLS change is one you want to see work before it deploys, and seeing it work takes a certificate, a listening socket and a client, all on a Python new enough to have removed the old function. The agent assembles that in its own sandbox in a few commands, without touching your real certificate or your network, and the handshake result is kept in the session. A reviewer reads the test's output for the before and after states instead of trusting that a few lines of security-sensitive code are equivalent.
The sandbox is also the right place for the question the port raises on the client side. When verification switches on, some connection that used to succeed may now be refused, and the safe way to find out which is to try each one from an isolated machine and write down what happened. The agent does that and reports hosts and errors. It leaves the decision about any host that fails verification to the people who run it.
Frequently asked questions
What replaces ssl.wrap_socket?
The wrap_socket method of an ssl.SSLContext. For a server, create the context with ssl.PROTOCOL_TLS_SERVER, call load_cert_chain(certfile, keyfile), and wrap the listening socket with server_side=True. For a client, ssl.create_default_context() gives a context with sensible settings, and you pass server_hostname when wrapping.
Why does my client fail certificate verification after the change?
The old function did not verify the server's certificate unless asked to, and the default context does. A failure means the server presents a certificate your trust store does not accept or one issued for another name. Fix the certificate, or load the right CA file into the context. Switching verification off recreates the weakness the old function had.
Does this apply to the http.server one-liner for local HTTPS?
Yes, and it is the most common place to meet the error. Scripts that do httpd.socket = ssl.wrap_socket(httpd.socket, certfile=..., server_side=True) need the three-line context form. The change is the same as in this page's example.
Will the fixed code run on older Python versions?
Yes. SSLContext and PROTOCOL_TLS_SERVER both predate Python 3.8, so a package that supports 3.8 and later needs no version check. The agent confirms it by running the new test on the oldest interpreter it can install.
How does the agent test TLS without my certificate?
It generates a self-signed certificate for localhost inside the test, starts the server on a local port, and connects with a client that trusts only that certificate. That proves the code path. Your real certificate is checked when you deploy, which the pull request calls out as the reviewer's step.
More jobs like this: Fix a bug from an alert
- Fix "AttributeError: module 'streamlit' has no attribute 'beta_columns'" and the beta_expander Rename (Streamlit)
- Fix "AttributeError: module 'streamlit' has no attribute 'experimental_rerun'" (Streamlit)
- Fix "strings.Title Has Been Deprecated" (SA1019) in a Go CLI (Go strings)
- Fix "'Switch' is not exported from 'react-router-dom'" after upgrading to React Router 6 (React Router)
- Fix "It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin" after Tailwind CSS 4 (Tailwind CSS)
- Fix "ImportError: cannot import name 'Filters' from 'telegram.ext'" (python-telegram-bot)