Repository navigation
Description
Follow-up to #1467. Not a regression versus main — #1467's example is an improvement on what preceded it. This is about a remaining hole in the worked example and a comment block that tells readers the hole is unavoidable.
What happens
docs/conventions/ecosystem-commands/examples/go.yaml's Buf freshness gate runs buf generate --clean and then inspects the result. On an unstaged hand-edit to a tracked generated file, the gate reports PASS and the edit is gone — --clean deleted it before any diff could observe it.
Measured by executing the literal cmd string with a real shell against real git repos, with a stub buf on PATH:
scenario want as-merged with pre-generation guard
clean + in sync PASS PASS PASS
staged hand-edit FAIL FAIL FAIL
unstaged hand-edit FAIL PASS +DESTROYED FAIL
stale committed output FAIL FAIL FAIL
A full 8-scenario run (orphaned output, untracked new output, gitignored output, staged regeneration) shows zero data loss for the guard version.
Why the comment block's framing should change
The merged reply and comment block state:
"this is a property of every regenerate-and-diff gate, not something a pathspec or diff form can fix"
Read literally that sentence is correct, and this issue is not disputing it. No pathspec and no diff form — git diff, git diff HEAD, git diff --cached, any combination — can recover data that --clean already deleted. Post-generation inspection genuinely cannot distinguish a reverted hand-edit from a clean tree.
What does not follow is the conclusion drawn from it: that this is "not a defect of this one," and that readers should "treat generated output as read-only rather than a place to hold in-progress edits." The destruction is preventable — not by inspecting differently, but by refusing to generate over uncommitted tracked output.
This matters more than a normal gate bug because the file is a worked example, published to be copied. Shipping it teaches downstream consumers a gate that silently eats uncommitted work, and the comment block tells them not to look for a fix.
Proposed fix
Bracket generation instead of chaining post-hoc checks — two checks rather than three:
test -z "$(git status --porcelain -uno -- '*.pb.go' '*.pb.gw.go')" && buf generate --clean && test -z "$(git status --porcelain -- '*.pb.go' '*.pb.gw.go')"
- Pre-check uses
-uno(tracked paths only) so it refuses to generate over uncommitted output — nothing is destroyed, and this closes the staged half too. - Post-check reports modified, untracked, and deleted in one command, replacing the
git diff HEAD+git ls-files --otherspair. - Untracked output stays outside the guard, so the primary "forgot to regenerate" flow still fails at the post-check rather than being caught by the guard.
Keeps the run-from: repo-root shape the example exists to illustrate. Note this is a pre-generation guard, a different mechanism from a pathspec or diff form — which is precisely why it escapes the impossibility the comment block describes.
Two things to verify when implementing:
- Git pathspec
*matches/, unlike shell globbing — confirm empirically that both checks catch a generated file in a nested directory, not only at the repo root. - The pre-check changes the failure a developer sees: the gate now refuses to run on a dirty tree rather than regenerating. Make the failure message say why it refused and what to do, or it will get worked around.
Implementing this also means correcting the comment block and the resolved thread reply, which currently assert the opposite.
Provenance
A signed implementation (c1995a1d, %G? = G) exists on branch wip/1467-nondestructive-gate. If that branch is not on the remote, treat the cmd above as the source of truth — it is reproducible from this issue alone.
Related
No linked issue. Follow-up to #1467.
Activity
kyle-sexton commentedon Jul 26, 2026
This was generated by AI during work-loop execution.
Staleness finding: already fixed, on the open PR this follows up on
Reproducing before touching anything (per this repo's Bug Investigation Rule): the destructive
behavior this issue describes is real on the
main/pre-#1467 form of the gate, and it is alreadyfixed — not by a new change, but by a commit already pushed to PR #1467's branch
(
docs/1462-run-from-repo-root-worked-example) before this item was dispatched:c9c1c8e5— "fix(ecosystem-commands): guard the proto gate against destroying output" — replaces the
three-check post-hoc form with the exact two-check bracket this issue proposes:
test -z "$(git status --porcelain -uno -- '*.pb.go' '*.pb.gw.go')" && buf generate --clean && test -z "$(git status --porcelain -- '*.pb.go' '*.pb.gw.go')".diff form can fix", "treat generated output as read-only") — confirmed absent from the current
file on that branch.
ecosystem-commandsCHANGELOG 1.2.1 entry to match.issue, via a PR review thread on docs(ecosystem-commands): worked run-from: repo-root example + multi-root gate failure format #1467 that found the same defect.
I re-verified independently rather than taking the commit message's word for it: executed the
literal
cmdstring with a real shell against a real git repo, with a stubbufonPATH.This matches every point in the issue's proposed fix and both "two things to verify" items (nested
pathspec depth, and the pre-check's refusal being distinguishable from the post-check's staleness
failure — see the shipped
remediationstring, which now names the two distinct failure points).Action taken
Per this skill's staleness rule ("If stale (work already done): close it with a comment... "), I'm
not opening a duplicate PR — a second PR touching the same lines would be a near-empty diff
guaranteed to conflict with #1467. But #1467 is not merged yet, and its body only carried
Closes #1462— merging it today would not have closed this issue. Rather than close #1516 now(which would assert a repo state — "fixed" — that isn't true until the PR lands, and would strand
this issue open forever if #1467 were abandoned or force-pushed), I added
Closes #1516to PR#1467's body (read-modify-write,
Closes #1462/Summary/Test plan/Related all preserved andverified after the edit) plus a
## Relatednote and a Summary bullet describing the fix. Thisissue will auto-close when #1467 merges, which is the truthful linkage.
Leaving this issue open, unassigned, with its existing labels — no new branch/PR against
#1516itself. If #1467 stalls or gets abandoned, this issue is the correct place to pick the fixback up (the
cmdin the issue body and commitc9c1c8e5are both a complete, verified source oftruth independent of that PR's fate).