fix(pre-commit): add go build gate for staged Go changes (#1770) - #2303
Merged
Merged
Conversation
Catches the bot-generated-structurally-invalid-Go class that took staging Platform(Go) red for hours on 2026-04-22 (PR #1769 commit 66ea0b6 nested a function declaration inside another function's body). The patch tool applied it; the Go parser rejected it; every Go PR targeting staging during the window failed CI through no fault of its own. Hook now runs `cd workspace-server && go build ./...` when any .go file in workspace-server/ is staged. If the build fails, commit is rejected with the first 20 lines of build output. Skip-with-warning when go isn't installed (CI runners + bots without go bypass cleanly). Cost: ~5-10s per commit that touches Go on a warm cache. Acceptable for the class of bug it catches — the alternative (catch at PR-time via CI) is too late, the malformed commit is already shared. This is one of the three guards proposed in #1770. The other two (branch-protection on `Platform (Go)` as required check; SHARED_RULES clarification on bot-PR overrides) are admin / process changes that need your action. Closes the pre-commit half of #1770. Branch-protection + SHARED_RULES work tracks separately. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
HongmingWang-Rabbit
requested a review
from hongmingwang-moleculeai
as a code owner
April 29, 2026 17:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
go build ./...check to.githooks/pre-committhat runs whenever a.gofile inworkspace-server/is staged. Rejects the commit if the build fails.Why
Per #1770: bot agents have produced syntactically-broken Go that the patch tool applied (PR #1769 nested a function declaration inside another function's body). Staging Platform(Go) was red for hours; every Go PR targeting staging during that window failed CI through no fault of its own.
This is the pre-commit guard half of the three guards proposed in #1770. Skip-with-warning when
goisn't installed (so CI runners and bots without go bypass cleanly).Test plan
bash -n .githooks/pre-commit— shell syntax validcd workspace-server && go build ./...on current main — passes (no false positive)What this PR does NOT do
Platform (Go)a required check on staging — admin action, needs your settings change. Currently the job runs but isn't required, so a Lead override could still merge a red PR.These are tracked in #1770 as separate guards; this PR closes only the pre-commit guard half. The issue stays open for the other two.
🤖 Generated with Claude Code