What the agent does
The agent reads the manifest and the store before it touches a reducer. In an app like bezkoder/react-redux-jwt-auth, package.json lists redux ^4.0.5, react-redux ^7.2.1 and redux-thunk ^2.3.0, with redux-devtools-extension as a dev dependency, on react-scripts 3.4.3 and React 16.13. src/store.js calls createStore with composeWithDevTools(applyMiddleware(...middleware)), where middleware is [thunk]. src/actions/types.js holds seven string constants, src/actions/auth.js three hand-written thunks, and src/reducers/auth.js and message.js are switch reducers joined by combineReducers. Two lockfiles are committed and they disagree: package-lock.json (lockfile version 1) matches the manifest, while yarn.lock never mentions Redux, React Router, axios or Bootstrap. The agent installs with npm and reports the stale Yarn lockfile instead of regenerating it unasked.
It takes a baseline first. react-scripts 3.4.3 bundles with webpack 4.42, which hashes with MD4, so on Node 17 or later npm run build stops with ERR_OSSL_EVP_UNSUPPORTED. The agent sets NODE_OPTIONS=--openssl-legacy-provider on the command and changes nothing in the repository for it. The project has src/setupTests.js but no test file, so npm test with CI=true finds nothing and exits 1. Until the agent writes reducer tests of its own, the production build is the only check the repository offers.
Then the dependencies. Redux Toolkit 2 depends on Redux 5 and redux-thunk 3, and react-redux 7.2.1 declares a peer range that stops at Redux 4. After npm install @reduxjs/toolkit, npm ls redux therefore shows two copies: 4.0.5 kept for react-redux and 5.0.1 under the toolkit. The agent removes the direct redux, redux-thunk and redux-devtools-extension entries, because configureStore adds the thunk middleware and the DevTools hookup itself, and moves react-redux to the 8.1 line, whose peer range admits Redux 5 and still supports React 16.8. It stops short of react-redux 9, which needs React 18, and runs npm ls redux again until one copy is left.
The reducers convert mechanically: createSlice replaces the constants, the creators and the switch statements, and src/reducers/auth.js keeps its line that reads localStorage for the initial state. The thunks are where a careless conversion breaks the app. login and register take positional arguments and return Promise.reject() on failure, and the components rely on both. login.component.js calls dispatch(login(this.state.username, this.state.password)) and navigates to /profile in .then; register.component.js sets successful: true there. A createAsyncThunk payload creator receives a single argument, so the positional call would deliver the username and drop the password. The promise that dispatch returns for an async thunk also resolves when the thunk is rejected. Converted naively, a failed login would navigate and a failed registration would report success. The agent passes one object at each call site, adds .unwrap() so the rejection comes back, and keeps the message dispatch inside the thunk so the server's error text still reaches the message slice.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Migrate this React app from hand-written Redux to Redux Toolkit. Read package.json, both lockfiles if there are two, src/store.js, every file under src/actions and src/reducers, and every component that calls connect or dispatch before changing anything. Say which lockfile matches package.json and install with that package manager; do not regenerate the other one. Take a baseline with the build script and the test script and report exactly what each prints, including a failure that comes from the Node version rather than the code. Install @reduxjs/toolkit, then show npm ls redux. Remove direct dependencies the toolkit replaces (redux, redux-thunk, the DevTools extension package) and move react-redux only as far as needed for one copy of redux, without upgrading React. Replace createStore with configureStore and each reducer, its action types and its action creators with a slice, keeping the state shape exactly as it is so existing selectors and mapStateToProps functions do not change. Convert each thunk to createAsyncThunk. For every place a component awaits or chains on a dispatched thunk, check what the promise resolved or rejected with before and make it behave the same after, using unwrap where the component depends on a rejection, and adapt call sites that pass several positional arguments. Do not convert class components or connect to hooks. Add tests for each slice and each thunk with the HTTP service mocked, covering the rejected paths. Run the build and the tests and open a pull request that lists the dependency changes, the npm ls redux output before and after, each call site whose promise handling changed, and anything you left alone.",
"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
The pull request replaces src/store.js with a configureStore call, adds one slice file per reducer, deletes src/actions/types.js and the old creators, and edits the three files that dispatch thunks: App.js, login.component.js and register.component.js. package.json and package-lock.json change with it. The description opens with the dependency table and the two npm ls redux listings, so a reviewer can see that the second copy of Redux is gone and which package pulled it in.
The section to read slowly is the list of call sites. For each dispatch(...) that a component chains on, it names what the old thunk returned on success and failure and what the new one returns, and shows the .unwrap() that keeps the .catch branch reachable. The new tests exercise exactly that: a rejected login leaves isLoggedIn false, sets the message and rejects to the caller. State shape is unchanged (state.auth.isLoggedIn, state.auth.user, state.message.message), so the mapStateToProps functions in the four connected components are not in the diff.
Two things change that a reviewer may not expect. Action type strings become auth/login/fulfilled and the like, which matters only if something outside the reducers matches on the old constants; in this repository nothing does. And in development the store now runs the toolkit's immutability and serializability checks, so a non-serializable value put into state shows up as a console warning that plain Redux never raised. The pull request leaves connect, the class components and the stale yarn.lock as they are and says so.
Run it on every repository that still calls createStore
Teams usually have this pattern in several front ends at once. Find them with a code search for createStore( and send one POST /o/{org}/sessions per repository, each with its own resources URL and the same input. A key runs at most max_concurrent runs at once, 4 by default and within its creator's plan limit; requests past that answer 202 with status: "queued" and start as slots free, so the loop needs no pacing. Give each request a request_id, a UUID you generate per repository, so a retried call returns the run it already started.
If the key has a webhook_url, each run it starts posts run.completed there when it finishes, with the final answer included when it is under 16 KiB; for this job that answer ends with the pull request link. Review can then go repository by repository as the results arrive, and a run whose answer says a thunk's contract could not be preserved is the one to open first.
The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.
Why run it on Rush?
The risky part of this migration is invisible in a diff: whether a promise still rejects. Checking it means installing the real packages, building, and running tests that drive a thunk through its failure path. The agent does that in a sandbox that has nothing else in it, so the npm ls output it quotes is the tree your CI will resolve, not a tree shaped by whatever was already in a developer's node_modules. Every command and its output stays in the session's transcript at GET /o/{org}/sessions/{id}/messages.
It also keeps the old build out of your way. A webpack 4 project needs an OpenSSL flag or an older Node to build at all, and switching Node versions on a laptop to take a baseline is the sort of chore that makes people skip the baseline. In the sandbox the agent can try both and record which one it used. The sandbox parks when the turn ends, so if review asks for a different choice, a follow-up message to the same session continues from the installed tree.
Frequently asked questions
Do I have to move from connect to hooks in the same pull request?
No. connect works with a store made by configureStore, and the state shape does not change, so every mapStateToProps keeps working. Converting components is a separate job with its own risks, and mixing the two makes the promise changes harder to review.
Does Redux Toolkit 2 work with React 16?
Its peer range starts at React 16.9, so an app on 16.13 can install it. The constraint is react-redux: version 9 needs React 18, while the 8.1 line supports React 16.8 and later and accepts Redux 5. The agent reads these ranges from the registry at the time of the run and quotes them.
Will the Redux DevTools browser extension still work?
Yes. configureStore connects to the extension by default, which is why the redux-devtools-extension package and its composeWithDevTools wrapper can be removed. The action names you see there change to the slice form.
What happens to custom middleware?
The fixture described here has only thunk, which configureStore includes. If your store adds others, the agent passes them through the middleware option by concatenating onto the default list, and lists each one in the pull request with a note on whether the serializability check objects to what it puts in actions.
More jobs like this: Upgrade dependencies weekly
- Replace the Deprecated request Package With Native fetch (request)
- Replace rimraf and mkdirp With fs.rm and fs.mkdir in a Node.js Package (rimraf)
- Migrate Sass @import to @use and Clear the Dart Sass Deprecation Warnings (Sass)
- Migrate From satori/go.uuid to google/uuid in a Go App (satori/go.uuid)
- Migrate From sqlite3 to better-sqlite3 in a Node.js API (node-sqlite3)
- Replace golang.org/x/crypto/ssh/terminal With golang.org/x/term (golang.org/x/crypto)