golang/go · error
internal error: build ID length mismatch %q vs %q
Error message
internal error: build ID length mismatch %q vs %q
What it means
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.
Source
Thrown at src/cmd/go/internal/work/buildid.go:722
cache.PutBytes(c, cache.Subkey(a1.actionID, "link-stdout"), a.output)
break
}
}
}
// Find occurrences of old ID and compute new content-based ID.
r, err := os.Open(target)
if err != nil {
return err
}
matches, hash, err := buildid.FindAndHash(r, a.buildID, 0)
r.Close()
if err != nil {
return err
}
newID := a.buildID[:strings.LastIndex(a.buildID, buildIDSeparator)] + buildIDSeparator + buildid.HashToString(hash)
if len(newID) != len(a.buildID) {
return fmt.Errorf("internal error: build ID length mismatch %q vs %q", a.buildID, newID)
}
// Replace with new content-based ID.
a.buildID = newID
if a.json != nil {
a.json.BuildID = a.buildID
}
if len(matches) == 0 {
// Assume the user specified -buildid= to override what we were going to choose.
return nil
}
// Replace the build id in the file with the content-based ID.
w, err := os.OpenFile(target, os.O_RDWR, 0)
if err != nil {
return err
}
err = buildid.Rewrite(w, matches, newID)View on GitHub (pinned to b6b368adc5)
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.
Example fix
// before — internal error after cache corruption $ go build ./... // error: internal error: build ID length mismatch "abc-X/Y" vs "abc-Z" // after $ go clean -cache $ go build ./...
Defensive patterns
Strategy: fallback
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/aa8ce9163ac07490.
Report an issue: GitHub.