Skip to content

fix: a gateway installed from the module proxy knows its own version - #43

Merged
blakebauman merged 1 commit into
mainfrom
version-from-buildinfo
Aug 11, 2026
Merged

blakebauman merged 1 commit into
mainfrom
version-from-buildinfo

Conversation

@blakebauman

Copy link
Copy Markdown
Member

go run github.com/fold-run/fold/cmd/fold@latest — the install the README
leads with — produced a binary reporting its version as dev:

$ go install github.com/fold-run/fold/cmd/[email protected] && fold --version
fold dev
$ tar xzf fold_v1.10.0_linux_amd64.tar.gz && ./fold --version
fold v1.10.0

goreleaser stamps the version with -ldflags; the module proxy path cannot. So
every operator on that route got a gateway whose /api/federation, /health,
startup log and MCP clientInfo all claimed to be a development build.

It is not cosmetic. The console gates its own surfaces on that string and
treats an unparseable one as current, so those operators silently lost
version-skew detection and got unversioned documentation links. Go already
records the resolved module version in the binary; the gateway now reads it
when nothing stamped one.

Precedence is deliberate: a stamp wins where there is one, so releases are
unaffected. (devel) — what a build from a working tree records — is not a
version and leaves dev alone. That path is a developer's and should say so.

The part that could have gone wrong quietly

-X only writes a string variable whose initialiser is a constant.
version now has to be computed, so a flag still pointed at it would have
stopped applying and reverted every release to dev — this exact bug,
inverted, and invisible until someone checked a shipped binary.

The stamp target is gateway.ldflagsVersion, and .goreleaser.yaml,
deploy/docker/fold.Dockerfile, CLAUDE.md and the release runbook move with
it. Verified rather than assumed:

$ go build -ldflags "-X github.com/fold-run/fold/gateway.ldflagsVersion=v9.9.9" ./cmd/fold
$ ./fold --version
fold v9.9.9

Verified against the real path

Installed this branch from the module proxy — the channel that was broken:

$ go install github.com/fold-run/fold/cmd/fold@8e998f3
$ fold --version
fold v1.10.1-0.20260811210611-8e998f39323a
$ curl -s localhost:8098/api/federation | jq -r .version
v1.10.1-0.20260811210611-8e998f39323a

A pseudo-version because that is a commit; @latest resolves to a tag and
reports v1.10.0. Both parse in the console's version gate.

Testing

resolveVersion takes the module lookup as an argument so the tests can
exercise every build route. debug.ReadBuildInfo() inside a test binary
reports the test binary's metadata and can never be made to say v1.10.0, so
a test calling it directly could only ever cover whichever branch the machine
happened to produce. Five cases: stamped release, go install of a tag,
go install of a commit, working-tree build, no metadata.

make check passes locally (fmt, tidy, vet, build, race across all packages).
golangci-lint is not installed on this machine; CI covers it.

One consequence worth knowing

A gateway installed from a commit now reports a ~40-character
pseudo-version, which the console renders in its header lockup. For the
documented @latest path it is a clean v1.10.0. If the long form turns out
to look bad in practice, the fix belongs in the console's displayVersion
rather than in what the gateway reports about itself.

Changelog entry added as v1.10.1 — unreleased.

🤖 Generated with Claude Code

`go run github.com/fold-run/fold/cmd/fold@latest` — the install this README
leads with — produced a binary reporting version "dev". goreleaser stamps the
version with -ldflags and the module proxy path cannot, so every operator on
that route got a gateway whose /api/federation, /health, startup log and MCP
clientInfo all claimed to be a development build.

That is not cosmetic. The console gates its own surfaces on that string and
treats an unparseable one as current, so those operators silently lost
version-skew detection and got unversioned documentation links. Go already
records the resolved module version in the binary; the gateway now reads it
when nothing stamped one.

Precedence is deliberate: a stamp wins where there is one, so releases are
unaffected. "(devel)", which is what a build from a working tree records, is
not a version and leaves "dev" alone — that path is a developer's and should
say so.

THE PART THAT COULD HAVE GONE WRONG QUIETLY

`-X` only writes a string variable whose initialiser is a constant. `version`
now has to be computed, so a flag still pointed at it would have stopped
applying and reverted every release to "dev" — the exact bug this fixes,
inverted. The stamp target is `gateway.ldflagsVersion`, and .goreleaser.yaml,
deploy/docker/fold.Dockerfile, CLAUDE.md and the release runbook move with it.
Verified rather than assumed: a build with -X against the new symbol reports
v9.9.9.

resolveVersion takes the module lookup as an argument so the tests can exercise
every build route. debug.ReadBuildInfo() inside a test binary reports the test
binary's own metadata and can never be made to say "v1.10.0", so a test that
called it directly could only ever cover the branch this machine happens to
produce.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit 0bcdb46 into main Aug 11, 2026
7 checks passed
@blakebauman
blakebauman deleted the version-from-buildinfo branch August 13, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant