xtekky/gpt4free · error
size mismatch: got %d, expected %d (update runtime.json)
Error message
size mismatch: got %d, expected %d (update runtime.json)
What it means
After a successful download and rename to the cache path, downloadRuntime in g4f-go/download.go stats the file and compares its size to spec.Size from runtime.json. A mismatch aborts with 'size mismatch: got %d, expected %d (update runtime.json)' — the manifest's pinned size no longer matches the artifact actually served.
Source
Thrown at g4f-go/download.go:147
copyErr = cerr
}
if copyErr != nil {
os.Remove(partName(binDir))
return fmt.Errorf("download interrupted: %w", copyErr)
}
if err := os.Rename(partName(binDir), cachePath); err != nil {
os.Remove(partName(binDir))
return err
}
fmt.Printf("runtime: downloaded %s in %s\n", humanBytes(total), time.Since(start).Round(time.Second))
if spec.Size > 0 {
fi, err := os.Stat(cachePath)
if err != nil {
return err
}
if fi.Size() != spec.Size {
return fmt.Errorf("size mismatch: got %d, expected %d (update runtime.json)", fi.Size(), spec.Size)
}
}
return verifyRuntime(cachePath, spec)
}
// verifyRuntime validates sha256 when pinned in the manifest.
func verifyRuntime(cachePath string, spec *RuntimeSpec) error {
if spec.SHA256 == "" {
return nil // unpinned; trust size/transport
}
f, err := os.Open(cachePath)
if err != nil {
return err
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
return errView on GitHub (pinned to 973504e177)
Solutions
- Check the real artifact size (curl -sI <spec.URL> | grep -i content-length) and update spec.Size in runtime.json
- Refresh your runtime.json from the upstream repo so size and sha256 match the current release
- If the served bytes look wrong (small/HTML), suspect a broken mirror and use the official URL
- Clear the cached download (.g4f-runtime/runtime.download / cache file) and retry after fixing the manifest
Example fix
// before
// size mismatch: got 29140615, expected 29999872 (update runtime.json)
// after
// runtime.json
"platforms": {
"linux-x64": {
"url": "https://host/runtime-linux-x64.tar.gz",
"size": 29140615, // corrected
"sha256": "..." // recompute: sha256sum runtime-linux-x64.tar.gz
}
} Defensive patterns
Strategy: validation
Validate before calling
resp, err := http.Head(spec.URL)
if err == nil {
if cl := resp.Header.Get("Content-Length"); cl != "" {
if n, _ := strconv.ParseInt(cl, 10, 64); n != spec.Size {
// manifest stale: fix runtime.json before downloading
}
}
} Try / catch
err := downloadRuntime(binDir, cachePath, spec)
if err != nil && strings.Contains(err.Error(), "size mismatch") {
// re-pin spec.Size (and sha256) in runtime.json to the current artifact
} Prevention
- Regenerate size AND sha256 together whenever you re-publish an artifact
- Automate manifest generation from the built artifact instead of hand-editing
- Use immutable, content-addressed URLs so sizes never drift under a pinned manifest
When it happens
Trigger: The hosting server silently re-uploaded/replaced the runtime archive while runtime.json still pins the old size; a truncated-but-200 response (rare when Content-Length is honored); or a locally edited manifest with a stale size.
Common situations: Upstream re-publishes an asset without cutting a new manifest; users editing runtime.json by hand; CDN serving a different (e.g. HTML error) body that still returned 200.
Related errors
- download failed: HTTP %s
- sha256 mismatch: got %s, want %s
- no runtime in manifest for platform %q
- download failed: %w
- download interrupted: %w
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/7b11345acc884529.
Report an issue: GitHub.