What the agent does
random.shuffle(x, random) took an optional second argument: a function returning floats in the range 0 to 1, used in place of the module's generator. Python 3.9 deprecated it and 3.11 removed it. A call that passes it positionally now fails with Random.shuffle() takes 2 positional arguments but 3 were given, and one that passes random= fails with got an unexpected keyword argument 'random'. The fix that makes the error go away is to delete the argument. Whether that is correct depends on why the argument was there, so the agent reads each call for its purpose before it edits.
The common purpose is to shuffle two lists the same way. wenyudu/Natural-Language-Processing-A-Machine-Learning-Perspective, the code for an NLP textbook, does this in ten training scripts under chapter2 to chapter5. Each loads sentences and labels as two parallel lists and runs random.shuffle(X,lambda: 0.1) and then random.shuffle(y,lambda: 0.1) under the comment # shuffle data and label with the same seed. A function that always returns 0.1 makes the shuffle a fixed permutation that depends only on the list's length, so both lists are rearranged identically and sentence i still has label i. There are 28 such calls in all, 14 pairs, because two of the chapter4 scripts repeat the pair three times each.
Delete the second argument from both lines and the two lists are shuffled independently. Nothing fails. Each sentence is now paired with some other sentence's label, the model trains on noise, and the script prints a lower accuracy that looks like an ordinary bad result. This is the outcome the agent is there to prevent. It replaces each pair with one shuffle of the joined data: it zips the lists, shuffles the pairs with a random.Random instance built from a fixed seed, and unzips. It writes that as one helper and uses it in every script, instead of repeating four lines 14 times.
It also reports what the old line really did, because the comment is wrong in a way that matters. A constant is not a seed. With 0.1 the result is close to a rotation: a list of ten items comes out as [9, 2, 3, 4, 5, 6, 7, 8, 0, 1]. The scripts then keep the first part as training data, as NaiveBayes(data,0.5) does in chapter2/NB/WenyuDu/main.py, so which sentences are used was decided by that fixed pattern. A real seeded shuffle picks a different subset, and any accuracy figures quoted alongside the code move with it. The agent offers both paths: a helper that reproduces the old permutation exactly with the same swap loop, for anyone who needs published numbers to match, and the seeded shuffle as the better default. It says which one the pull request uses.
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.11 or later with \"TypeError: Random.shuffle() takes 2 positional arguments but 3 were given\" (or \"got an unexpected keyword argument 'random'\"). Find every call to random.shuffle that passes a second argument, positionally or as random=. For each call, work out why the argument is there: to shuffle two or more parallel lists identically, to make a run reproducible, to plug in a different generator, or to bias the order in a test. List adjacent calls that shuffle related lists as one group. Do not simply delete the argument. For each group of parallel lists, replace the calls with a single shuffle of the zipped items using a random.Random instance with an explicit seed, then unzip, and prove with a test that item i of every list still belongs with item i of the others. Put the logic in one helper and call it everywhere. Separately, write a small function that reproduces the exact permutation the old call produced (the same swap loop with the same function), and say for each group whether downstream results such as a train and dev split or reported metrics depend on that exact order. State clearly which behaviour the pull request keeps. If the function passed was a constant, explain in the description that it is a fixed permutation and not a seed, and show the permutation for a list of ten items. Run every changed script far enough to pass the shuffle, or its tests if they exist, and include the commands and output. Open a pull request listing every call, its group and its purpose.",
"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 adds one helper and replaces each group of calls with a call to it. The description lists every call by file and line, grouped, with the purpose the agent found for the second argument. For the textbook repository that would be 14 groups in ten files, all with the same purpose. A test builds two lists where each label encodes its sentence's index, shuffles them through the helper and asserts that every pair still matches.
The description then covers the choice that changes results. It shows the old permutation for a short list, explains that a constant function is not a seed, and states whether the pull request keeps that exact order or moves to a seeded shuffle. If it moves, it says which numbers a reader should expect to differ: any metric computed after a split that follows the shuffle. A reviewer checks the pairing test first, then that decision. For teaching code, a correct shuffle is probably worth changed numbers. For an experiment with published results, the exact-order helper is the conservative choice until the numbers are rerun.
Run it on every failed scheduled job
Training and data-preparation scripts usually run from a scheduler, and they fail on the first run after the image's Python moves forward. If the scheduler can call a URL with a custom header when a job fails, point it at a webhook trigger on an automation that holds the prompt above, sending Authorization: Bearer with the trigger's secret and the job's log tail as the body. The body becomes the event text after the prompt. If it cannot set that header, have a handler on your server receive its notification and call the trigger.
Send the trigger's URL an Idempotency-Key header carrying the job run's id, so a retried notification starts nothing new. Set the automation's max runs per hour low, so a nightly batch of scripts that all share the broken call does not start a run for each of them.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
The wrong fix here passes every check a person normally makes: the script starts, trains and prints a number. Catching it takes a test built for the purpose and a run of the old behaviour to compare against, which needs a Python from before the removal next to a current one. The agent installs both in its sandbox, records the old permutation, and the comparison is kept with the session, so the claim that the pairing still holds comes with output behind it.
The call is also usually copied across many files, and each copy has to be read, because one of them may pass a real generator for a real reason. Reading 28 near-identical lines carefully is work people do badly. The run lists every one with its group and purpose, and a reviewer can confirm the list is complete with one search.
Frequently asked questions
What replaces random.shuffle(x, random=f)?
If f was there for reproducibility, use random.Random(seed).shuffle(x). If it was a different generator, subclass random.Random and override random(), then call shuffle on an instance. The standard library has no direct replacement for passing a function.
How do I shuffle two lists in the same order now?
Shuffle them as one list of pairs: pairs = list(zip(X, y)), shuffle pairs, then X[:], y[:] = zip(*pairs). Shuffling a list of indices and applying it to each list also works. Two random.Random instances built from the same seed also give matching orders for lists of equal length, but that breaks without warning if the lengths ever differ.
Was passing lambda: 0.1 a seeded shuffle?
No. It is a single fixed rearrangement determined by the list length. It looked reproducible because it was the same every time, and it kept parallel lists aligned, but the order it produces is close to a rotation and not a random sample.
Will my model's accuracy change after the fix?
If the script takes a subset or a split after shuffling, yes, unless the fix reproduces the old order exactly. The agent states which option the pull request takes and can include a helper that keeps the previous permutation for comparison.
More jobs like this: Fix a bug from an alert
- Fix "ReactDOM.render is no longer supported in React 18. Use createRoot instead" (React)
- Fix "TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines'" in pandas 2 (pandas)
- Fix "Error: req#logout requires a callback function" in Passport 0.6 and later (Passport)
- Fix "LookupError: Resource punkt_tab not found" in word_tokenize (NLTK)
- Fix "ImportError: cannot import name 'SafeConfigParser' from 'configparser'" on Python 3.12 (configparser)
- Fix "DEPRECATION WARNING [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0" (Sass)