{"record":{"id":"aa8ce9163ac07490","repo":"golang/go","slug":"internal-error-build-id-length-mismatch-q-vs-q","errorCode":null,"errorMessage":"internal error: build ID length mismatch %q vs %q","messagePattern":"internal error: build ID length mismatch %q vs %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/buildid.go","lineNumber":722,"sourceCode":"\t\t\t\tcache.PutBytes(c, cache.Subkey(a1.actionID, \"link-stdout\"), a.output)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\t// Find occurrences of old ID and compute new content-based ID.\n\tr, err := os.Open(target)\n\tif err != nil {\n\t\treturn err\n\t}\n\tmatches, hash, err := buildid.FindAndHash(r, a.buildID, 0)\n\tr.Close()\n\tif err != nil {\n\t\treturn err\n\t}\n\tnewID := a.buildID[:strings.LastIndex(a.buildID, buildIDSeparator)] + buildIDSeparator + buildid.HashToString(hash)\n\tif len(newID) != len(a.buildID) {\n\t\treturn fmt.Errorf(\"internal error: build ID length mismatch %q vs %q\", a.buildID, newID)\n\t}\n\n\t// Replace with new content-based ID.\n\ta.buildID = newID\n\tif a.json != nil {\n\t\ta.json.BuildID = a.buildID\n\t}\n\tif len(matches) == 0 {\n\t\t// Assume the user specified -buildid= to override what we were going to choose.\n\t\treturn nil\n\t}\n\n\t// Replace the build id in the file with the content-based ID.\n\tw, err := os.OpenFile(target, os.O_RDWR, 0)\n\tif err != nil {\n\t\treturn err\n\t}\n\terr = buildid.Rewrite(w, matches, newID)","sourceCodeStart":704,"sourceCodeEnd":740,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/buildid.go#L704-L740","documentation":"In updateBuildID, after computing a content-hash-based new ID by replacing the suffix of a.buildID, the code asserts len(newID)==len(a.buildID) because build IDs are rewritten in-place inside the binary (the old ID is overwritten byte-for-byte). A length mismatch is an internal invariant violation — it should never happen with well-formed inputs.","triggerScenarios":"Effectively unreachable in normal use. It would fire if buildid.HashToString returned a string of unexpected length, or if a.buildID lacked the buildIDSeparator. Indicates memory corruption, a malformed build ID, or a regression in buildid.HashToString.","commonSituations":"A custom toolchain that injects a non-standard build ID format; a Go toolchain regression; a tampered binary where the build ID was edited to change its length.","solutions":["Run 'go clean -cache' — a stale/corrupt cache entry can carry a malformed build ID.","Rebuild from scratch with a released Go toolchain.","If reproducing on a released toolchain, file a Go bug with the binary and build ID values from the error.","Avoid manually editing build IDs in compiled artifacts."],"exampleFix":"// before — internal error after cache corruption\n$ go build ./...\n// error: internal error: build ID length mismatch \"abc-X/Y\" vs \"abc-Z\"\n\n// after\n$ go clean -cache\n$ go build ./...","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'go clean -cache' when encountering any 'internal error' from the build.","Use released Go toolchains; report internal invariant violations upstream.","Never hand-edit build IDs inside compiled artifacts."],"tags":["build","buildid","internal","build-cache"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}