What the agent does
gulp 4 changed the signature of gulp.task. In gulp 3 the second argument could be an array of task names to run first. In gulp 4 it must be a function, and an array there fails an assertion inside undertaker, the task registry gulp 4 is built on: AssertionError [ERR_ASSERTION]: Task function must be specified. The error is thrown while the gulpfile is being loaded, so it does not matter which task you asked for. Every gulp command fails, including tasks that are written correctly.
numbers/numbers.js, a mathematics library, is in exactly this state. Its package.json asks for "gulp": "^4.0.0" and the lockfile holds 4.0.0, but gulpfile.js is still written for gulp 3. Ten tasks are defined and five use the array form: build on line 15, concat on line 23, default on line 30, format on line 54 and minimize on line 62. Line 15 is the first to execute, so that is where the load stops. The breakage went unnoticed because nothing automatic loads the gulpfile: .travis.yml names no script, so it runs npm test, which is mocha -u tdd. Only the g-build, g-format, g-lint and g-test scripts go through gulp, and the README documents them as alternatives.
The agent reproduces the error with npx gulp --tasks and rewrites the five definitions. A task with dependencies and a body, such as concat, becomes gulp.series("clean:src", function ...). One that only groups other tasks, such as format, becomes gulp.parallel("format:lib", "format:test"), or gulp.series where order matters. Then it deals with what the mechanical rewrite breaks. gulp 4 resolves a task name at the moment gulp.series is called, so gulp.task("build", gulp.series("minimize")) on line 15 fails with Task never defined: minimize while minimize is still defined on line 62. The agent reorders the file so that each task comes after the ones it names, or turns the tasks into named functions and composes those.
One more defect only shows once the file loads. clean:src calls del([DEST], cb), passing gulp's callback as a second argument. The del version in the lockfile returns a promise and never calls it, and gulp 4, which is strict about completion, stops with "The following tasks did not complete" and "Did you forget to signal async completion?". The fix is return del([DEST]). The agent then runs each task: gulp test and gulp lint first, since they write nothing, then gulp build, comparing the regenerated src/numbers.js and src/numbers.min.js with the committed copies and reporting any difference instead of committing new build output unasked.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Running any gulp task in this repository fails with \"AssertionError [ERR_ASSERTION]: Task function must be specified\". Read package.json and the lockfile and report which gulp version is declared and which is installed. Install dependencies from the lockfile, run npx gulp --tasks and save the error with its stack. Read the gulpfile and list every gulp.task call, marking the ones that pass an array of task names as the second argument. Rewrite those for gulp 4 with gulp.series and gulp.parallel: use series where a task must finish before the next starts (cleaning before building), parallel where tasks are independent. gulp 4 looks up task names when series or parallel is called, so order the definitions so that every task is defined before another one names it, or convert tasks to named functions. After the file loads, run every task one at a time and fix what gulp 4 reports: tasks that never signal completion (return the stream or promise, or call the callback), gulp.watch calls with gulp 3 arguments, and run-sequence or gulp.start if they are used. Do not upgrade unrelated plugins unless a task cannot run without it, and say why if you do. If a build task rewrites files that are committed, compare the new output with the committed files and report the difference; do not commit regenerated build output. Also say whether CI ever runs gulp, and if it does not, add the cheapest gulp task to the CI script so the gulpfile is loaded on every push. Open a pull request with the before and after task list and the output of each task.",
"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 gulpfile.js and, if CI never loaded it, one line of the CI configuration. The description shows the task list gulp prints once the file loads, a before and after of each rewritten definition, and the output of every task the agent ran. Completion fixes such as the del call are listed separately from the signature changes, since they are different bugs that the same upgrade exposed.
A reviewer reads the series and parallel choices. Two tasks that write to the same directory must not be made parallel, and a clean step must stay ahead of the build that follows it. They check the order of definitions if the file was rearranged, and that task names are unchanged, because the npm run g-* scripts and anyone's shell history refer to them. If a task could not run in the sandbox, for example one that opens a browser, the description says so and that task is marked as rewritten but unrun.
Run it on every GitHub issue labelled build-broken
A broken gulpfile is usually reported by the next person who tries to build: a contributor opens an issue with the assertion pasted in. Give the Project an automation with a github trigger on issues.labeled and the label you use, and a prompt that reads the issue, reproduces the failing command and fixes the build script. The issue is added after the prompt as event text. Only an issue that a repository owner, member or collaborator opened fires it, whoever adds the label, so when the report came from outside, open an issue of your own with the assertion in it and label that one.
If you maintain several front-end repositories that were bumped to gulp 4 together, there is no need to wait for reports. Send the request above once per repository from a script. Each run works in its own sandbox with that repository's lockfile, and runs past the key's concurrency limit wait as queued until a slot frees.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
This fix cannot be checked by reading. A rewritten gulpfile either loads and completes every task or it does not, and the failures arrive one at a time: first the signature, then the definition order, then a task that never finishes. The agent installs the exact plugin versions from the lockfile in a clean sandbox and runs each task for real, so the pull request reports observed output, kept in the session, for all ten tasks and not only the one someone happened to try.
Old build tooling is also what people avoid installing on their own machine. Plugins from the gulp 3 era pull in hundreds of transitive packages, some with native parts that may not build on the Node version you use for everything else. In a sandbox that cost is nobody's problem: the dependencies are installed, used and discarded with the machine.
Frequently asked questions
Can I pin gulp back to 3.9 instead?
Only on an old Node. gulp 3 fails on Node 12 and later with ReferenceError: primordials is not defined, so going back trades this error for that one unless the Node version goes back as well. Rewriting the task definitions is the smaller change.
When should a task use gulp.series and when gulp.parallel?
gulp 3 ran the tasks in a dependency array at the same time, so gulp.parallel is the literal translation. Use gulp.series wherever the old file relied on one task depending on another to force an order, such as clean before build. The agent decides per task from what each one reads and writes.
After the rewrite I get "Task never defined". Why?
gulp 4 resolves names when gulp.series or gulp.parallel is called, not when the task runs. A task that names another must come after it in the file. Reorder the definitions, or pass function references instead of strings.
What does "Did you forget to signal async completion?" mean?
gulp 4 needs every task to say when it is done: by returning a stream or a promise, or by calling the callback it receives. gulp 3 was lenient about this. The agent runs each task and fixes the ones that never finish, which a rewrite of the signatures alone does not reveal.
More gulp jobs
More jobs like this: Fix a bug from an alert
- Fix "Handlebars: Access has been denied to resolve the property" With Mongoose Documents (Handlebars)
- Fix "TypeError: handler() missing 1 required positional argument: 'path'" in websockets 14 (websockets)
- Fix "TypeError: Client.__init__() got an unexpected keyword argument 'proxies'" in httpx (HTTPX)