Where the 404 comes from#
Both public registries answer reads from a content delivery network. The registry's own database knows about the new version as soon as the publish call returns, but each edge node keeps its own copy of what it last served for a URL. If anything asked for that URL before the version existed, the edge may hold the 404 and hand it out again.
Caches are allowed to do this. RFC 9110 lists 404 among the status codes that are "heuristically cacheable", which means a cache may reuse one even without explicit freshness headers. Registries do send such headers. You can watch both from a shell; the version 999.0.0 does not exist in either registry:
$ curl -sI https://registry.npmjs.org/left-pad/-/left-pad-999.0.0.tgz
HTTP/2 404
age: 184
cache-control: public, max-age=300
server: cloudflare
$ curl -sI https://pypi.org/pypi/requests/999.0.0/json # second read
HTTP/2 404
x-cache: MISS, MISS, HIT
x-cache-hits: 0, 0, 1
npm's tarball 404 says any cache may keep it for five minutes, and the age header shows a shared cache had already held this one for three minutes. PyPI's 404 came from a cache hit at the last edge in the chain on the second read. The PyPI API policies say so directly: requests to the JSON API "are cached by our CDN provider", and the X-Cache and X-Cache-Hits headers tell you whether you hit the cache.
Who made the first request does not matter. A previous release job, a dependency bot, a mirror or your own retry from a failed attempt can each leave a 404 behind at one edge. Different edges expire at different times, so two consecutive reads from the same job can disagree.
What the check should do#
Publishing and verifying are separate steps, and the verifying step needs to know the difference between "not visible yet" and "wrong".
- Reread only 404. A 403, a 5xx that persists, a checksum mismatch or a missing file in an otherwise visible release is a real failure. Raise it at once.
- Reread only for a version you published in this run. A 404 for a version nobody published is the right answer, and a lookup tool that waits 20 minutes on it wastes everyone's time.
- Wait longer than the cache. Five minutes of
max-ageis a floor; the observed gaps below were 40 seconds and 14 minutes. Reading every 30 seconds for up to 20 minutes covers both without hammering the registry. - Name the URL when you give up. "Publications incomplete" sends someone to the logs; "still 404 after 20 minutes: URL" tells them which read to try by hand.
- Cover every read. The version metadata, the provenance record and each downloadable file are separate URLs with separate cache entries. A wait on the metadata does nothing for a file download that follows it.
The npm publish documentation describes the publish itself and makes no promise about when the tarball URL answers, so design the check for the delay instead of assuming none.
The lab#
The lab needs Python 3 and nothing else. A local server plays an edge that serves a cached 404 for three seconds after publish and then the file; one path always answers 403. The client rereads 404 every second for up to ten, the same policy scaled down from 30 seconds and 20 minutes.
import http.server, threading, time, urllib.request, urllib.error
PUBLISHED_AT = time.monotonic()
VISIBLE_AFTER = 3.0 # seconds until the edge stops serving its cached 404
class Edge(http.server.BaseHTTPRequestHandler):
def do_GET(self):
age = time.monotonic() - PUBLISHED_AT
if self.path == "/forbidden":
self.send_response(403)
elif age < VISIBLE_AFTER:
self.send_response(404)
self.send_header("Cache-Control", "public, max-age=300")
else:
self.send_response(200)
self.end_headers()
def log_message(self, *args):
pass
server = http.server.HTTPServer(("127.0.0.1", 0), Edge)
threading.Thread(target=server.serve_forever, daemon=True).start()
base = f"http://127.0.0.1:{server.server_port}"
def published(url, every=1.0, deadline=10.0):
"""Reread a 404 for a version we just published; refuse anything else at once."""
start = time.monotonic()
while True:
try:
with urllib.request.urlopen(url) as r:
return f"{r.status} after {time.monotonic() - start:.1f}s"
except urllib.error.HTTPError as e:
if e.code != 404:
raise
if time.monotonic() - start >= deadline:
raise RuntimeError(f"{url} still 404 after {deadline:.0f}s") from e
print(f" 404, rereading in {every:.0f}s")
time.sleep(every)
try:
urllib.request.urlopen(base + "/pkg/1.2.0")
except urllib.error.HTTPError as e:
print("one read:", e)
print("rereading:")
print(" ", published(base + "/pkg/1.2.0"))
try:
published(base + "/forbidden")
except urllib.error.HTTPError as e:
print("other status:", e)
Run it with python3 lab.py:
one read: HTTP Error 404: Not Found
rereading:
404, rereading in 1s
404, rereading in 1s
404, rereading in 1s
200 after 3.0s
other status: HTTP Error 403: Forbidden
A single read fails the release. The rereading check passes after three seconds, and the 403 still fails at once. To test your own check, make it deterministic: inject the clock and the HTTP call, feed it two 404s and a 200, then a 403, then 404s past the deadline, and assert each outcome. Then remove the retry and confirm the first case fails, so you know the test exercises it.
Do not purge your way out#
It is tempting to add a cache-busting query string or a Cache-Control: no-cache request header to the check. That proves the origin has the file, which you already knew from the publish response. It does not prove that your users, who will not add the query string, can install the version. The reread tests what an installer sees. If an installation from a clean machine is part of your release check, run it after the reread succeeds.
In production#
The fix behind this guide came in three steps over two weeks, each after a release run failed on a publication that had in fact succeeded.
- An npm SDK release listed the new version and its provenance, then a check read the tarball 40 seconds after publish and got one 404. The rerun passed unchanged. The fix rereads the tarball every 30 seconds for up to 20 minutes.
- A Python SDK release failed when PyPI's version JSON answered 404 for a release it had just accepted. The same URL answered 200 fourteen minutes later. The metadata and provenance reads got the same wait.
- A later Python release failed about 73 seconds after upload, when the verification read the version JSON through a second code path that still made a single request and reached an edge serving a cached 404. The fix moved that read, and each file download, onto the same rereading function. A test now refuses any direct, non-rereading call from the verifier.
Where this came from#
Proofline found this in its own public client release pipeline and shipped the fix in its production release of 18 November 2026, extending it to PyPI file downloads in a release tagged 1 December 2026. The 40-second, 14-minute and 73-second gaps above are from those release runs. Proofline reviews GitHub pull requests; new organizations get one calendar month of hosted code review without a cloud connection. Start a free GitHub review ยท Eligibility and fair-use terms
Questions#
How long should a post-publish check wait for a registry?
Longer than the 404's cache lifetime and the gaps you have seen. Rereading every 30 seconds for up to 20 minutes covered a 14-minute PyPI gap; npm marks a tarball 404 cacheable for five minutes.
Should the same check retry a 429 or a 503?
That is a different policy with its own limits. Read the guide to 429 and 503 responses and honor Retry-After; keep the post-publish wait for 404 only.
Is a 404 that later turns into a 200 a registry bug?
No. It is how shared caches behave, and the same thing happens with DNS answers cached past a failover. The registry did accept the upload; one edge had not yet dropped its old answer.