Skip to content
Nilay Kabariya

Entry No.033·Deploy·Updated ·4 min read

Fix: Script startup exceeded CPU time limit (Workers 10021)

Cloudflare rejects your Worker deploy with Script startup exceeded CPU time limit. How to see which code is slow, and the fix that removes it, measured.

What changed on Nov 8, 2026: Deployed the same Worker 21 times to find the real cutoff: accepted up to 928 ms, unreliable from about 850 ms.

by Nilay#cloudflare#workers#wranglerDEPLOY

The error, verbatim

Jump to the fix ↓
X [ERROR] Your Worker failed validation because it exceeded startup limits.
  A request to the Cloudflare API (/accounts/.../workers/scripts/nk-repro-cpu/versions) failed.
   - Error: Script startup exceeded CPU time limit.
   [code: 10021]
✓ Reproduced on Windows 11 Pro

The fix that worked

Profile what runs at startup:

npx wrangler check startup
Not it? Every cause, tested ↓

Tested on

wrangler
4.139.0; 4.158.0 (limit search, November 8)
Worker
compatibility_date 2026-09-01
Plan
Workers Paid
OS
Windows 11 Pro

Everything at the top level of your Worker, outside the fetch handler, runs once when Cloudflare starts it up, before any request. Cloudflare checks how long that takes when you deploy, and rejects the upload if it’s too slow. Nothing about your requests is involved yet.

The fix

1. Find the slow code. When the deploy fails, wrangler writes a CPU profile of the startup for you and prints where:

A CPU Profile of your Worker's startup phase has been written to .wrangler\tmp\startup-profile-qtzDoy\worker.cpuprofile - load it into the Chrome DevTools profiler (or directly in VSCode) to view a flamegraph.

You can also make one before deploying:

npx wrangler check startup

2. Do that work ahead of time, not at startup. If the slow part builds a value that’s the same every time (a lookup table, a parsed file, a computed constant), compute it once in a build script and ship the result in the bundle.

What I measured

A Worker doing a big calculation at the top level, deployed to a test Worker with wrangler 4.139.0:

Top-level work Deploy
lighter version accepted, Worker Startup Time: 435 ms
heavier version rejected, Script startup exceeded CPU time limit [code: 10021]
result shipped as a constant accepted, Worker Startup Time: 2 ms

Wrangler’s own advice under the error:

Try reducing the amount of work done during startup (outside the event handler), either by removing code or relocating it inside the event handler.

Where the limit really is: about 850 to 930 ms, and it wobbles

Cloudflare’s docs say startup has to finish within one second. I wanted to know where the deploy actually starts saying no, so on November 8, 2026 I deployed the same Worker 21 times with wrangler 4.158.0, changing only how many times a loop runs at the top level, and wrote down what each deploy reported:

Terminal log of 21 wrangler deploys: loop sizes up to 185 million report Worker Startup Time between 449 and 823 ms; 200 million was rejected once with code 10021 and accepted four times at 887 to 907 ms; 210 million was rejected once and accepted once at 928 ms; 220 million was rejected three times.
Every deploy in the order I ran it. The first ten were logged without seconds. Full log.

What the log shows:

  • Nothing above 928 ms was accepted. That was the highest startup time any deploy reported. The largest size, 220 million loop rounds, was rejected all three times.
  • Below about 800 ms, every deploy passed. All the sizes that measured 449 to 823 ms went through each time.
  • In between it’s a coin toss. The 200-million version was rejected on its first deploy, then accepted four times in a row at 887 to 907 ms. The 210-million version failed once and passed once. Two sizes slightly smaller than 200 million (189 and 192 million) were each rejected on their only try.
  • The same code measured differently each time. The 180-million version reported 919 ms, then 791 ms, then 800 ms, a few minutes apart.

So the line isn’t a clean 1,000 ms. In practice the check started failing somewhere from roughly 850 ms, and it measures on whatever machine your upload lands on, so a Worker near the edge can pass today and fail on the next deploy with no change to the code. If your deploy log shows a startup time above 800 ms, treat it as a warning and cut the startup work now, before a routine deploy fails on a busy day.

wrangler check startup doesn’t tell you this either. It runs the startup on your own machine: for the 100-million version it reported 949 ms of active time on my PC, while Cloudflare reported 449 ms for the same file. Use it to find what is slow (the flamegraph), not to predict whether the deploy will pass.

Why moving it into the handler isn’t enough

“Relocate it inside the event handler” gets the deploy through, but the work still happens, just on a request instead. I moved the same calculation into fetch, computed once and then kept in a variable:

So only move it into the handler if it’s work that doesn’t have to happen on most requests. If every request needs it, precompute it.

Test setup

A test Worker on workers.dev, deployed with wrangler 4.139.0 on a Workers Paid account: a top-level loop sized so one version passed and one failed the startup check, the same loop moved lazily into fetch, and the result shipped as a constant. Startup times and errors are copied from wrangler’s output, and the per-request CPU from wrangler tail. Cloudflare’s limits page says startup must finish within 1 second.

November 8, 2026: the limit search above, 21 deploys of the same loop Worker at 11 sizes with wrangler 4.158.0 from Windows 11 to a Workers Paid account, plus one local wrangler check startup. The generator, config and full log are public.

— N.K., end of entry No.033

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.066

    Deno Deploy shutdown: move to Workers or Node, tested

    Deno Deploy closes in about six months. I moved a typical Deno Deploy app to Cloudflare Workers and to Node 26: every error, and what fixed each.

    > Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'jsr:'

    DEPLOY3 min
  2. No.032

    Fix: The uploaded script has no registered event handlers

    Cloudflare rejects your Worker with no registered event handlers (code 10068), or accepts it and serves a 404. Seven handler shapes tested, Hono included.

    > X [ERROR] A request to the Cloudflare API (/accounts/.../workers/scripts/nk-repro-cpu) failed.

    DEPLOY3 min
  3. No.025

    Fix: Error 1101 Worker threw exception (Cloudflare Workers)

    Cloudflare's 1101 page hides the real error. See it with one command, plus six causes reproduced on a deployed Worker, each with its exact log message.

    > Error 1101

    DEPLOY4 min

tip: paste the exact error text