Skip to content

cmd: cross-check update checksums with the GitHub release (PRINFRA-6744) - #584

Merged
somanshreddy merged 3 commits into
mainfrom
11-16-update_followups
Nov 16, 2026
Merged

somanshreddy merged 3 commits into
mainfrom
11-16-update_followups

Conversation

@somanshreddy

Copy link
Copy Markdown
Collaborator

Scope

Surfaces: CLI | Module: Self-update

Summary

Follow-ups to the CDN self-update in #583. A stable update now installs only when the CDN's checksums.txt matches the one on the GitHub release, and update --check and the update notice offer only releases built for this platform. Live on the next release.

How it works

  • The archive still comes from the CDN. Before installing, the update also reads checksums.txt from the GitHub release for the same version. The two files must be identical. If they differ, or either is missing, the update stops and the installed binary stays as it was.
  • The GitHub download follows redirects only to GitHub's own asset hosts.
  • update --check, update and the notice report a new release only if its checksums.txt lists an archive for this platform. Otherwise they report no update, as the GitHub-based updater did.
  • A refused or failed stable-pointer request reports the HTTP status. Only --version lookups call a 403/404 "not found".
  • If replacing the binary fails and restoring the old one also fails, the error says how to reinstall.
  • SKILL.md and RELEASE.md describe the stable --version rule and the cross-check.

Testing

  • New cases with a local fake CDN and GitHub cover: checksums that differ between the two, a missing GitHub checksums.txt, a redirect off GitHub's asset host, a lookalike file name listed before the real entry, a release without this platform (--check and notice agree), a refused stable pointer, and a HEYGEN_CDN_BASE_URL value having no effect.
  • Each new check was broken on purpose and its test failed.
  • Updated a v0.10.0 build to v0.11.0 against the real CDN and GitHub.
  • Confirmed the CDN and GitHub checksums.txt are byte-identical for existing releases.

Closes PRINFRA-6744.

🤖 Generated with Claude Code

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at a716482c.

What I checked in update_cdn.go:

  • UpdateTo reads the CDN checksums.txt once. It takes want from those bytes, requires bytes.Equal against the GitHub release's copy, and only then downloads and hashes the CDN archive against want. The bytes compared are the bytes used, so there is no second fetch to race. When the GitHub copy is missing or unreadable, the update stops before any download.
  • GitHub client: the start URL is a constant (not affected by HEYGEN_CDN_BASE_URL). Redirects are capped at 3 hops and must stay on release-assets.githubusercontent.com / objects.githubusercontent.com. The CDN client still refuses every redirect.
  • DetectLatest, --check and the notice now resolve the same way: pointer, then this platform's entry in that release's CDN checksums.txt. A 403/404 on that file, or no entry for this platform, means "no update". Any other status surfaces as an error.
  • fetchStablePointer no longer turns a refused pointer into "not found"; only expectedChecksum maps 403/404 to errReleaseNotFound.
  • The rollback-failure message wraps the original error and names the reinstall command.

Tests on Go 1.26: the update tests pass. I broke each check on purpose:

Mutation Result
skip the bytes.Equal cross-check caught (GitHub_release_lists_different_checksums)
allow any redirect host caught
DetectLatest ignores the platform entry caught (release_lacks_this_platform)
notice back to fetchStablePointer caught
403 no longer means missing / objectMissing off caught (missing_version_answers_403)
entry match via strings.Contains (survived on #583) now caught (StableInstallsVerifiedArchiveFromCDN, lookalike line)
drop the https scheme check in githubAssetRedirect survives
ignore the GitHub fetch error survives, harmlessly: nil never equals a real file, so the update still refuses with a less precise message

Notes, none blocking:

  1. The "immutable" premise is not true for this repo yet. The comment on updateGitHubReleaseURL says published releases are immutable, but the releases API reports "immutable": false for v0.8.1, v0.9.0, v0.10.0 and v0.11.0. The cross-check still means someone has to tamper with both stores to ship a bad binary, which is the real win. But today a token that can edit releases can rewrite an existing version's GitHub checksums.txt after it ships. Turning on immutable releases in the repo settings would make the comment true. Otherwise, reword the comment.
  2. The scheme check has no test. The fakes are plain-HTTP servers, so nothing exercises u.Scheme == "https". Exposure is small, because the redirected bytes still have to match the CDN copy exactly. A unit test of githubAssetRedirect with http://release-assets.githubusercontent.com/... would pin it.
  3. New behavior: stable updates now need github.com as well as static.heygen.ai. A network that blocks github.com but allows the CDN can still run install.sh, but heygen update will now fail there. That trade-off is probably right; a sentence in RELEASE.md would save a support question.
  4. Unrelated, so you know it's not from this PR: a full go test ./cmd/heygen/ on a loaded box failed TestGenBuilder_*_Wait_Timeout_* twice, a different case each time. Those are timing-sensitive tests unrelated to this diff.

— Rames

@somanshreddy
somanshreddy force-pushed the 11-16-update_followups branch from a716482 to 63eb240 Compare November 16, 2026 04:01

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 63eb240. Approving.

  • The rebase onto #582 is clean. git range-diff shows the cross-check commit unchanged (a716482 = 9f1753a).
  • The new comment is accurate. GET /repos/heygen-com/heygen-cli/immutable-releases returns enabled: true, and v0.7.0 through v0.11.0 all report immutable: false. So the protection that holds today is the two-source match, which is what the comment now says.
  • The new TestGitHubAssetRedirect catches both mutations I tried. Dropping the https check fails it on the http:// case, and replacing the exact host match with a prefix match fails it on the .example.com lookalike.
  • The RELEASE.md network note is accurate: scripts/install.sh never references github.com.

Go 1.26.11: the update tests pass, and go vet and gofmt are clean.

Review by Rames

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at e8e39ae, which is one new commit on top of 63eb240. Approving.

Error mapping. It reads correctly.

  • expectedChecksum now returns a failed read unchanged and wraps only the "no entry for this platform" case.
  • DetectLatest treats only that case as "no update".
  • DetectVersion still treats 403/404 as not found, through objectMissing.
  • No references to the old errReleaseNotFound remain.
  • The notice worker still swallows the failure, so users see no notice rather than an error. It returns before writeUpdateCache, so the next check runs again.
  • release-stable.yml uploads releases/<tag>/, including checksums.txt, before it flips stable. So a normal publish never makes this new error visible.

Mutations, both caught:

  • Putting objectMissing back into DetectLatest fails TestUpdateCheck_UnreadableChecksumsForLatestIsAnError.
  • Dropping it from DetectVersion fails TestUpdate_VersionResolvesItsCDNFolder.

withRollbackHint. It is correct, and it is defensive today. In go-selfupdate v1.5.0, Updater.UpdateTo returns update.Apply's error unwrapped, through decompressAndUpdate. So the outer layer already matches on both paths, and RollbackError really does only type-assert (err.(*rollbackError)). The errors.Unwrap loop is harmless.

Non-blocking nits:

  • Nothing tests the hint. Changing the loop to check only the outer layer passes the suite. A small fake error that wraps an update.Apply rollback failure would pin it.
  • On the dev updater the hint suggests install.sh, which installs the latest stable. That is still a sensible recovery for a missing binary, but it moves a dev-channel user onto stable. Consider wording it that way.

Go 1.26.11: the full cmd/heygen package passes.

Review by Rames

@somanshreddy
somanshreddy merged commit d0e552c into main Nov 16, 2026
12 checks passed
@somanshreddy
somanshreddy deleted the 11-16-update_followups branch November 16, 2026 04:44
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.

2 participants