Skip to content

fix: autogenerate bare protocol versions#4696

Open
MasterPtato wants to merge 1 commit intomainfrom
04-22-fix_autogenerate_bare_protocol_names
Open

fix: autogenerate bare protocol versions#4696
MasterPtato wants to merge 1 commit intomainfrom
04-22-fix_autogenerate_bare_protocol_names

Conversation

@MasterPtato
Copy link
Copy Markdown
Contributor

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@railway-app
Copy link
Copy Markdown

railway-app Bot commented Apr 22, 2026

🚅 Deployed to the rivet-pr-4696 environment in rivet-frontend

Service Status Web Updated (UTC)
kitchen-sink ❌ Build Failed (View Logs) Web Apr 25, 2026 at 1:08 am
frontend-cloud 😴 Sleeping (View Logs) Web Apr 22, 2026 at 7:38 pm
website 😴 Sleeping (View Logs) Web Apr 22, 2026 at 7:37 pm
frontend-inspector ❌ Build Failed (View Logs) Web Apr 22, 2026 at 7:26 pm
mcp-hub ✅ Success (View Logs) Web Apr 22, 2026 at 7:26 pm
ladle ❌ Build Failed (View Logs) Web Apr 22, 2026 at 7:26 pm

@MasterPtato MasterPtato changed the title fix: autogenerate bare protocol names fix: autogenerate bare protocol versions Apr 22, 2026
@MasterPtato MasterPtato force-pushed the 04-22-fix_autogenerate_bare_protocol_names branch from 9c42c67 to a1d6d8b Compare April 22, 2026 21:58
@claude
Copy link
Copy Markdown

claude Bot commented Apr 22, 2026

Code Review: PR #4696 — fix: autogenerate bare protocol versions

Summary

This PR eliminates manually-maintained version constants by having each build.rs scan its schema directory and inject the highest version number into the generated combined_imports.rs file. It also renames the namespace.runner_config.vN.bare schema files to pegboard.namespace.runner_config.vN.bare (adding the pegboard. prefix for consistency), and updates all references in versioned/ and runner_configs.rs.

The intent is solid and the mechanics generally work. A few issues worth addressing before merge.


Issues

1. Silent zero version when schema directory is empty

In find_highest_version, if no .bare files match the expected vN.bare pattern, highest_version stays at 0. For ups-protocol this silently injects pub const PROTOCOL_VERSION: u16 = 0. epoxy-protocol protects against this by checking highest_version_path.exists() after the scan, but ups-protocol has no equivalent guard. Add an explicit panic/error when highest_version == 0.

2. Panic on filenames without a dot in find_highest_version

.split_once('.')
.unwrap()  // panics if no '.' in filename

If a file like README (no extension) ever lands in the schema directory, .unwrap() on split_once('.') returning None will panic the build. The data/build.rs approach (strip_suffix(".bare") + rfind(".v")) handles this more gracefully. The new copies in epoxy-protocol and ups-protocol propagate this fragility. A safer pattern: let Some((bare_name, _)) = file_name.split_once('.') else { continue; };

3. Duplicated find_highest_version across three crates

find_highest_version is copy-pasted verbatim into envoy-protocol/build.rs, epoxy-protocol/build.rs, and ups-protocol/build.rs. Any fix to the issues above must be applied in three places. Consider moving this into vbare_compiler (the natural home) or a shared build-utils crate.

4. Auto-detected PROTOCOL_VERSION decoupled from hardcoded module re-export

After this change:

  • pub use generated::v2::*; — still hardcoded
  • pub use generated::PROTOCOL_VERSION; — now auto-detected as highest version

If someone adds v3.bare, PROTOCOL_VERSION automatically becomes 3 while pub use generated::v2::* still re-exports v2 types. The two silently diverge. CLAUDE.md says "never modify an existing published *.bare runner protocol version" precisely to prevent accidental bumps, but this decoupling removes the compile-time check that kept them in sync. An assertion or co-located comment would make the invariant explicit.

5. PEGBOARD_RUNNER_ADDRESS_VERSION silently dropped

The old data/src/lib.rs exposed PEGBOARD_RUNNER_ADDRESS_VERSION: u16 = 1. The new code drops it because no pegboard.runner.address.vN.bare schema file exists. A grep confirms it was dead code — but this should be called out explicitly in the PR description so reviewers know it was intentional.


Minor / Style

  • Missing cargo:rerun-if-changed in ups-protocol/build.rs: verify incremental Cargo builds trigger a rebuild when schema files change.
  • Version narrowing from u32 to u16: parsed as u32, emitted as u16. Not a practical issue, but worth a comment.
  • result.sort_by(|(a, _), (b, _)| a.cmp(b)) can be simplified to result.sort_by_key(|(a, _)| a.clone()). Minor.

What's Working Well

  • Auto-generating version constants from schema files eliminates the class of bugs where someone adds vN.bare but forgets to bump the constant manually.
  • The pegboard. prefix rename is clean and makes the identifier-to-module-name derivation consistent.
  • find_schema_versions in data/build.rs correctly groups multiple schemas by identifier and takes the maximum version per identifier — more robust than the single-schema approach.
  • The pub use generated::PEGBOARD_* re-exports are clean and eliminate drift between manual constants and generated code.

Checklist

  • Guard against zero version in ups-protocol/build.rs when no schemas are found
  • Fix or document the .unwrap() panic risk on filenames without a dot in the new find_highest_version copies
  • Add a comment or assertion co-locating PROTOCOL_VERSION with pub use generated::vN::* to prevent silent version skew
  • Confirm PEGBOARD_RUNNER_ADDRESS_VERSION removal is intentional and note it in the PR description
  • Verify cargo:rerun-if-changed coverage for ups-protocol schema directory

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