What the agent does
Python 3.8 removed time.clock. Python 3.7 still runs it and, with warnings on, says what is coming: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead. That warning names two replacements because the old function measures two different things. On Unix it returns processor time used by the process; on Windows it returns wall-clock time. Picking a replacement means deciding which of the two the code wanted. hurlenko/memetic-algorithm is a small, honest example: one file, ma.py, whose README says it is written in Python 3 and needs only numpy. Its main wraps each configuration in start_time = time.clock() on line 167 and fin_time = time.clock() on line 177.
The agent runs python ma.py on a current interpreter and gets the error at line 167, before any work is done, so the fault is the script's first and only obstacle. Then it reads what the two readings are used for. Line 178 prints them as the last column of a semicolon-separated row: dimension, population size, generations, best fitness and fin_time - start_time. That column is the program's result as much as the fitness is. Anyone who collected those rows on Linux under Python 3.7 or earlier collected processor seconds.
So the choice changes numbers, and the agent shows by how much instead of asserting it. time.process_time() keeps the Unix meaning: time the process spent computing, with sleeps and waiting excluded. time.perf_counter() measures elapsed time and includes them. For a single-threaded numpy loop the two stay close; they part ways when the machine is busy, when the code sleeps or waits on input, or when a library computes on several threads, where processor time can exceed elapsed time. The agent times a few seconds of sleeping and computing with both clocks to make the gap visible, then picks process_time for this script, since old result rows should stay comparable with new ones, and says in the description what a reader on Windows would have been measuring.
It finishes by checking the rest. A grep for time.clock finds every call, including ones behind sys.platform checks and helpers that alias the function, such as timer = time.clock. Each call gets the same question about what it measured. When the traceback's top frame is inside an installed package and not the repository, the fix is a dependency upgrade and the agent treats it as one: it finds the first release without the call, bumps to it, and reruns. The repository has no tests, so the agent proves the script with a shortened configuration list and leaves the committed lists as they were.
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.8 or later with \"AttributeError: module 'time' has no attribute 'clock'\". Fix it. Reproduce the error first on the newest Python you can install and keep the traceback. If the top frame is inside an installed dependency and not this repository, find the first release of that dependency that no longer calls time.clock, upgrade to it, and report what else the upgrade changes. For calls in this repository, find every use of time.clock, including aliases such as timer = time.clock and branches on sys.platform. For each one, read how the value is used and decide what it measured: processor time of this process (use time.process_time) or elapsed time (use time.perf_counter). Where the measured value is printed, logged, stored or compared with a threshold, say which meaning the old code had on Linux and on Windows, choose the replacement that keeps recorded results comparable, and state the choice and its consequence. Never use time.time for intervals. Do not change what is being timed. Show the difference between the two clocks with a small measurement if the choice matters. Run the tests if there are any; if there are none, run the program with a reduced input that finishes quickly and show its output, without committing the reduction. 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 that changes one name per call. For a script like ma.py that is two lines. The description quotes the traceback from before the change and the program's output after it, produced with a shortened run so the proof does not have to wait for the full sweep over population sizes up to 500.
The description spends most of its words on the choice. It says which clock replaced each call and what the old call measured on each operating system. Where a timing is part of the program's output, it says whether numbers recorded before the change can still be compared with numbers recorded after it. If the agent chose process_time and your earlier results came from Windows, that sentence is the one to read twice.
A reviewer checks that the choice matches what the team believes the number means. A benchmark column, a timeout and a progress estimate each want a different answer, and the agent's reasoning for each call is written next to the diff. Nothing else in the file should change, and the description says so.
Run it on every GitHub issue that quotes the error
For a public script or library, this bug arrives as an issue from someone who ran it on a new Python and pasted the last line of the traceback. Create an automation in the Project with a github trigger on issues.labeled, set its labels to one a maintainer applies after reading the report, and save this prompt. The issue is placed after the prompt as event text, so the reporter's traceback and Python version reach the agent.
Only labels added by a repository owner, member or collaborator fire the trigger, which keeps a stranger from starting runs by opening issues. The trigger fills in nothing in the prompt, so the prompt stays general and the issue supplies the specifics. Set the automation's max runs per hour to a small number; a burst of duplicate reports then waits in line instead of opening a pile of identical pull requests.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
The edit is trivial and the judgment is not, and the judgment benefits from measurement. In its own sandbox the agent can install the Python that still had time.clock and the Python that removed it, run the same timing on both, and put the numbers in front of the reviewer. That evidence is kept in the session's transcript next to the commands that produced it. A local fix usually skips this step because the developer has one interpreter installed and the error is gone after the first rename.
Old scientific and benchmarking code is where this error concentrates, and such repositories rarely come alone. A lab or a team tends to have dozens of small scripts that all timed themselves the same way. Each run works in its own machine on its own branch, so the whole set can be handled side by side, and each pull request carries its own reasoning about what its timings meant.
Frequently asked questions
What should I use instead of time.clock?
time.perf_counter() for elapsed time, which is what most benchmarks and timeouts want. time.process_time() for processor time used by your process, which is what time.clock returned on Unix. Both exist since Python 3.3, so the change needs no version check on any Python 3 still in use.
Why are my timings different after switching to perf_counter?
On Linux and macOS the old function counted only processor time, so time spent sleeping, waiting for a disk or waiting for input was invisible. perf_counter counts everything that elapses. If you need numbers comparable with old Unix results, use process_time.
The traceback points into a library, not my code. What then?
Then the library is too old for your Python. The agent reads the frame, finds the package and version, and looks for the first release without the call. The pull request is a version bump with the import working, plus a note on anything else that release changes.
Can I keep supporting Python 2 and Python 3.8 with one code path?
Yes, with a small guard such as timer = getattr(time, 'perf_counter', None) or time.clock. The agent adds one only when the project's metadata still declares Python 2 support. Otherwise it uses the Python 3 function directly.
Does the agent change what the code measures?
No. The request forbids moving the start and stop points or changing the work between them. Only the clock function changes, and where two clocks would give different numbers the description says which one was chosen and why.
More jobs like this: Fix a bug from an alert
- Fix "_pickle.UnpicklingError: Weights only load failed" from torch.load in PyTorch 2.6 and Later (PyTorch)
- Fix "AttributeError: module 'tornado.web' has no attribute 'asynchronous'" after a Tornado upgrade (Tornado)
- Fix CryptographyDeprecationWarning: TripleDES Has Been Moved in a Paramiko Tool (Paramiko)
- Fix "AttributeError: module 'tweepy' has no attribute 'StreamListener'" (Tweepy)
- Fix "AttributeError: type object 'Qt' has no attribute 'AlignCenter'" When Moving to PyQt6 (PyQt6)
- Fix "uninitialized constant Fixnum (NameError)" on Ruby 3.2 and later (Ruby)