Skip to content

fix(ecosystem-commands): go.yaml's buf gate destroys uncommitted generated-file edits #1516

Closed

Description

@kyle-sexton

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 --others pair.
  • 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:

  1. 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.
  2. 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

  1. added
    agent-ready
    on Jul 26, 2026
  2. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    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 already
    fixed
    — 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:

    I re-verified independently rather than taking the commit message's word for it: executed the
    literal cmd string with a real shell against a real git repo, with a stub buf on PATH.

    scenario                              old form              new form (shipped)
    clean + in sync                       PASS                  PASS (exit 0)
    unstaged hand-edit                    PASS + DESTROYED       refused (exit 1) + SURVIVED
    staged hand-edit                      (not separately run)   refused (exit 1) + SURVIVED
    nested-directory generated file       (not separately run)   caught by -uno pre-check
                                                                   (pathspec `*` matches `/`,
                                                                   confirmed at gen/nested/deep/*.pb.go)
    

    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 remediation string, 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 #1516 to PR
    #1467's body (read-modify-write, Closes #1462/Summary/Test plan/Related all preserved and
    verified after the edit) plus a ## Related note and a Summary bullet describing the fix. This
    issue 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
    #1516 itself. If #1467 stalls or gets abandoned, this issue is the correct place to pick the fix
    back up (the cmd in the issue body and commit c9c1c8e5 are both a complete, verified source of
    truth independent of that PR's fate).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-ready

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions