{"record":{"id":"7b11345acc884529","repo":"xtekky/gpt4free","slug":"size-mismatch-got-d-expected-d-update-runtime","errorCode":null,"errorMessage":"size mismatch: got %d, expected %d (update runtime.json)","messagePattern":"size mismatch: got (.+?), expected (.+?) \\(update runtime\\.json\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"g4f-go/download.go","lineNumber":147,"sourceCode":"\t\tcopyErr = cerr\n\t}\n\tif copyErr != nil {\n\t\tos.Remove(partName(binDir))\n\t\treturn fmt.Errorf(\"download interrupted: %w\", copyErr)\n\t}\n\tif err := os.Rename(partName(binDir), cachePath); err != nil {\n\t\tos.Remove(partName(binDir))\n\t\treturn err\n\t}\n\tfmt.Printf(\"runtime: downloaded %s in %s\\n\", humanBytes(total), time.Since(start).Round(time.Second))\n\n\tif spec.Size > 0 {\n\t\tfi, err := os.Stat(cachePath)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif fi.Size() != spec.Size {\n\t\t\treturn fmt.Errorf(\"size mismatch: got %d, expected %d (update runtime.json)\", fi.Size(), spec.Size)\n\t\t}\n\t}\n\treturn verifyRuntime(cachePath, spec)\n}\n\n// verifyRuntime validates sha256 when pinned in the manifest.\nfunc verifyRuntime(cachePath string, spec *RuntimeSpec) error {\n\tif spec.SHA256 == \"\" {\n\t\treturn nil // unpinned; trust size/transport\n\t}\n\tf, err := os.Open(cachePath)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\th := sha256.New()\n\tif _, err := io.Copy(h, f); err != nil {\n\t\treturn err","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f-go/download.go#L129-L165","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n// size mismatch: got 29140615, expected 29999872 (update runtime.json)\n\n// after\n// runtime.json\n\"platforms\": {\n  \"linux-x64\": {\n    \"url\": \"https://host/runtime-linux-x64.tar.gz\",\n    \"size\": 29140615,   // corrected\n    \"sha256\": \"...\"     // recompute: sha256sum runtime-linux-x64.tar.gz\n  }\n}","handlingStrategy":"validation","validationCode":"resp, err := http.Head(spec.URL)\nif err == nil {\n    if cl := resp.Header.Get(\"Content-Length\"); cl != \"\" {\n        if n, _ := strconv.ParseInt(cl, 10, 64); n != spec.Size {\n            // manifest stale: fix runtime.json before downloading\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"err := downloadRuntime(binDir, cachePath, spec)\nif err != nil && strings.Contains(err.Error(), \"size mismatch\") {\n    // re-pin spec.Size (and sha256) in runtime.json to the current artifact\n}","preventionTips":["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"],"tags":["go","runtime-manifest","integrity","size-check","download"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}