Skip to content

Strip the generator version stamp from generated protos - #46

Merged
stevendborrelli merged 1 commit into
mainfrom
fix-protobuf-check-version-churn
Oct 8, 2026
Merged

stevendborrelli merged 1 commit into
mainfrom
fix-protobuf-check-version-churn

Conversation

@stevendborrelli

Copy link
Copy Markdown
Member

protobuf-check fails on routine dependency PRs for a reason that has nothing to do with the protos.

The problem

ts-proto writes its own version and protoc's into a // versions: header block in every generated file. Bumping ts-proto rewrites those comment lines, the CI drift check sees changes under src, and the PR goes red until someone regenerates and commits.

On the currently-open renovate PR #45 (ts-proto 2.12.4 → 2.13.0), that is the entire diff — three files, one comment line each, no generated code change at all:

 // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
 // versions:
-//   protoc-gen-ts_proto  v2.12.4
+//   protoc-gen-ts_proto  v2.13.0
 //   protoc               v7.36.2

This is why main carries commits like "regen protos" and "allow protoc to run" — the check has been demanding hand-regeneration for comment churn, which trains everyone to regenerate-and-commit on reflex. That is exactly the habit you do not want around a check whose job is to catch unintended changes to generated code.

The fix

scripts/protoc-gen.sh strips the // versions: block after generation, so the output depends only on the .proto input and the generator flags — which is what the check is meant to police.

The // Code generated by protoc-gen-ts_proto. DO NOT EDIT. and // source: lines are untouched, so the files are still clearly marked as generated. The versions themselves remain recorded in package.json and in the workflow's protoc pin, so provenance is not lost, just not duplicated into a file that is diffed byte-for-byte in CI.

Verification

The check has to stop firing on noise without going blind. Both directions tested locally:

scenario before after
regenerate under ts-proto 2.13.0 3 files changed no drift
add a field to run_function.proto caught still caught (23 lines in run_function.ts)

npm run build, typecheck, lint and all 136 tests pass.

Also

Added set -euo pipefail to the script, so a protoc failure stops the run rather than leaving half-generated output for the new post-processing step to rewrite.

Deliberately left alone: the # Update this version when ts-proto in package.json is updated comment above the protoc pin in ci.yaml. It is misleading — protoc's version is independent of ts-proto — but it is outside the scope of this fix.

Once this lands, #45 can be rebased and should go green without a regen commit.

🤖 Generated with Claude Code

protobuf-check fails on routine dependency PRs. ts-proto writes its own
version and protoc's into a "// versions:" header block in every generated
file, so bumping ts-proto rewrites those three comment lines, the CI drift
check sees changes under src, and the PR goes red until someone regenerates
and commits.

Measured on the open renovate PR #45 (ts-proto 2.12.4 -> 2.13.0), that is
the entire diff: three files, one comment line each, no generated code
change at all.

Drop the version block in scripts/protoc-gen.sh after generation, so the
output depends only on the .proto input and the generator flags -- which is
what the check is meant to police. The versions themselves stay recorded in
package.json and in the workflow's protoc pin, and the "Code generated ...
DO NOT EDIT" and "source:" header lines are untouched.

Verified: with this change, regenerating under ts-proto 2.13.0 produces no
diff, while adding a field to run_function.proto is still caught.

Also add set -euo pipefail, so a protoc failure stops the run rather than
leaving half-generated output for the post-processing step to rewrite.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
@stevendborrelli
stevendborrelli merged commit 7e86220 into main Oct 8, 2026
7 checks passed
@stevendborrelli
stevendborrelli deleted the fix-protobuf-check-version-churn branch October 8, 2026 14:42
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