Pin protobuf field and enum value numbers in a sidecar artifact - #1304
Merged
Conversation
jwils
requested review from
BrianSigafoos-SQ,
bsorbo,
ellisandrews-toast,
jwondrusch,
marcdaniels-toast,
myronmarston and
rossroberts-toast
as code owners
July 8, 2026 23:21
This was referenced Jul 8, 2026
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
from
July 8, 2026 23:40
67b8198 to
f62a859
Compare
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
2 times, most recently
from
July 9, 2026 18:13
90e2af5 to
616dbfd
Compare
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
from
July 10, 2026 15:44
616dbfd to
74011e5
Compare
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
2 times, most recently
from
July 11, 2026 13:53
075e749 to
8d6e03f
Compare
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
from
July 11, 2026 13:59
8d6e03f to
0a476c1
Compare
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
2 times, most recently
from
July 16, 2026 14:21
7a57c87 to
26fe805
Compare
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
from
July 17, 2026 15:05
26fe805 to
8803f5e
Compare
jwils
added a commit
that referenced
this pull request
Jul 20, 2026
## Why - continue the pluggable ingestion serializer proposal after pulling JSON Schema into its own gem - revive the earlier protobuf prototype from #1056 on top of the new serializer extension points ## What - fill in the `elasticgraph-proto_ingestion` extension gem with core generation: `schema_artifacts:dump` emits a `proto3` `schema.proto` covering the schema's indexed types - map built-in ElasticGraph scalars to proto types, with `t.protobuf type:` for custom scalars (resolved via `type_ref.with_reverted_override` so built-ins renamed with `type_name_overrides` keep working) - generate messages for object/interface/union types and enums (with a zero-valued `*_UNSPECIFIED` entry), escaping proto reserved words and wrapping lists of lists so the output stays valid - keep `schema.proto` on public GraphQL field names; validate proto package names - hold extension state on a `ProtoIngestionState` container behind a single `proto_ingestion_state` reader (matching #1281) Field and enum value numbers are assigned sequentially in definition order in this PR; the stacked follow-up adds the `proto_field_numbers.yaml` sidecar that keeps them wire-stable across schema evolution. ## Stacked follow-ups 1. this PR — core `schema.proto` generation 2. wire-stable field/enum value numbers via a `proto_field_numbers.yaml` sidecar 3. `syntax: :proto2` support and custom file-level `headers:` 4. #1286 — enum value sourcing from existing proto enums + external proto type references ## Verification - `script/run_gem_specs elasticgraph-proto_ingestion` (100% line + branch coverage at this commit) - `script/type_check`, `script/lint`, `script/spellcheck` - `script/quick_build` green at the stack head (whose tree is identical to the previously reviewed single-PR revision) ## References - #1059 - #1056 - #1079 ## Update — 2026-07-10 - The current stack is #1080 → #1304 → #1306 → #1305 → #1286. - Proto extension state now uses a mutable Struct, and keyword package-name segments are validated without being rewritten. - Lists of lists now raise an actionable schema error instead of generating wrapper messages; this supersedes the earlier wrapping note above. --- ## Update — 2026-07-15 - Interface and union messages now wrap concrete subtype messages in a `oneof`, matching the JSON Schema `oneOf` representation. - Concrete subtype messages omit the redundant `__typename` discriminator. - Proto type rendering is now stateless: the generator selects the reachable type graph up front, then each extended type renders itself without mutating shared traversal state. - No-block extension coverage now completes the definitions so the fixture remains valid under CI GraphQL-schema validation. --- ## Update — 2026-07-19 - Replaced keyword suffixing with fully qualified local message and enum references, preserving source type and field names while disambiguating contextual protobuf words and built-in scalar names. - Removed the now-unnecessary keyword collision tracking and verified a generated schema containing contextual names with `protoc` 35.1.
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
from
July 25, 2026 15:30
156369c to
ec29566
Compare
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
from
July 29, 2026 19:17
ec29566 to
e8b37a2
Compare
jwils
added a commit
that referenced
this pull request
Jul 31, 2026
Today, every schema artifact is a pure function of the schema definition: the schema artifacts directory can safely be deleted and regenerated at any time. In #1304 (comment), @myronmarston pointed out that `proto_field_numbers.yaml` doesn't fit that model--it's an _input_ to `schema.proto` generation, not a pure output--and suggested treating it as part of the schema definition, stored as a sibling of `path_to_schema`, rather than as a schema artifact. For an extension to maintain a file there, schema definition state needs to know where the schema definition lives. `RakeTasks` already knows (it's how the schema gets loaded) but never passed it into the API. This PR stores `path_to_schema` on `SchemaDefinition::State`, allowing extensions to access it without expanding `SchemaArtifactManager`'s dependencies. Nothing in core uses the value yet, so there are no behavior changes to the core artifacts. #1304 builds on this to relocate `proto_field_numbers.yaml`. ## Update — 2026-07-29 After review, the path is carried by schema definition state rather than an extension-only `SchemaArtifactManager` instance variable. The manager continues to accept the narrower schema-definition results object.
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
5 times, most recently
from
August 6, 2026 15:54
4b5acdf to
bbe754f
Compare
myronmarston
requested changes
Aug 7, 2026
myronmarston
left a comment
Collaborator
There was a problem hiding this comment.
Not done reviewing but wanted to submit my feedback so far.
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
from
August 7, 2026 16:20
bbe754f to
92bff82
Compare
myronmarston
requested changes
Aug 8, 2026
myronmarston
left a comment
Collaborator
There was a problem hiding this comment.
not done but submitting my feedback so far
Field and enum value numbers were assigned sequentially in definition order, so reordering or removing a field renumbered everything after it — breaking wire compatibility with previously serialized data. `schema_artifacts:dump` now reads and writes a `proto_field_numbers.yaml` sidecar artifact: - Existing numbers stay fixed even if field order changes; new fields get the lowest unused numbers. - `schema.proto` keeps the public GraphQL field names while the sidecar stores private `name_in_index` overrides. - A field renamed with `field.renamed_from` reuses its existing number under the new public name. - Enum value numbers are pinned in an `enums` section; removed values keep their numbers reserved so they are never reused (`0` remains the generated `*_UNSPECIFIED` value). - The sidecar is safe to hand-edit but strictly validated: unknown keys, non-integer numbers, out-of-range numbers, and collisions raise clear errors instead of silently reassigning numbers. The parsed mappings are modeled by a `FieldNumberMappings` class that owns conversion to and from the dumped artifact format.
Protobuf field-number state only needs public wire names and stable\nnumbers. Leave public-to-index name translation to record preparation,\nso every field mapping has the same simple integer representation.
Store a per-message allocation cursor beside the stable field mappings.\nNew fields advance from that cursor instead of reclaiming gaps that may\nhave belonged to fields absent from a hand-edited mapping.
jwils
force-pushed
the
joshuaw/proto-field-numbers
branch
from
August 8, 2026 18:57
0ddfe16 to
11fc5c1
Compare
myronmarston
approved these changes
Aug 14, 2026
myronmarston
left a comment
Collaborator
There was a problem hiding this comment.
LGTM! Left some non-blocking feedback--use your judgement on what to address.
jwils
added a commit
that referenced
this pull request
Aug 19, 2026
…g formats (#1306) ## Why Mapping `DateTime` to `string` loses the type safety proto offers — a string can be malformed in ways a [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) cannot, and proto consumers get language-native timestamp types. For the remaining `string`-typed temporal scalars, the proto type is much wider than the ElasticGraph type, so the expected format deserves documentation at the point of use (per [review discussion](#1080 (comment))). ## What - Map `DateTime` to `google.protobuf.Timestamp`, importing `google/protobuf/timestamp.proto` automatically. A `Timestamp` is a UTC instant, so a publisher's original UTC offset is not preserved; `t.protobuf type: "string"` remains available as an override. - `t.protobuf` gains two options usable by any scalar: - `import:` maps a scalar to an externally defined proto type, emitting the needed `import` statement - `field_comment:` documents the expected format above each generated field - The built-in `string`-typed temporal scalars (`Date`, `LocalTime`, `TimeZone`) use `field_comment:` to document their formats (e.g. `// Must be formatted as an ISO 8601 date, e.g. "2024-11-25".`). Values are still validated at ingestion time, exactly as with JSON ingestion. - Each `protobuf` call replaces the full protobuf configuration, so an override that omits `import:` or `field_comment:` clears the value a prior call set. ## Risk Assessment Low — only affects the unreleased `elasticgraph-proto_ingestion` extension from #1080. ## References - Stacked on #1304 (→ #1080) - Addresses #1080 (comment) and #1080 (comment) ## Update — 2026-07-10 Nested-list wrapper comment propagation was removed after #1080 changed to reject lists of lists. Format comments continue to apply to supported scalar and single-list fields. ## Update — 2026-08-18 Addressed review feedback: - `comment:` is now `field_comment:`, and renders as `//` lines **above** the field rather than trailing the field line. Proto compilers attach leading comments to the code they generate for a field; a trailing comment is usually discarded. This also removed the reason the comment had to be a single line, so a multi-line `field_comment:` is now allowed. - Built-in temporal comments were reworded to read well above the field (e.g. `Must be formatted as an ISO 8601 date, e.g. "2024-11-25".`). - The "each `protobuf` call replaces the full configuration" behavior is now documented and covered in both directions (override that drops the import, and override that drops the field comment). - Enum and object types now answer `protobuf_import` with `nil`, so import rendering no longer greps for scalar types and a non-scalar type can start requiring an import without a change there. - Spec reorganization (moving scalar-related examples out of `schema_spec.rb`) is handled in a follow-up PR at the end of this stack. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
jwils
added a commit
that referenced
this pull request
Aug 19, 2026
## Why Some consumers need the generated messages to reference proto2 types — `protoc` forbids a proto3 message from referencing a proto2 enum — and language-specific file options (like `java_package`) shouldn't require baking any convention into the gem. ## What `proto_schema_artifacts` gains two options: - `syntax: :proto2` emits a proto2 file instead of the default proto3, labeling every field `optional` or `repeated` - `headers:` injects file-level lines (such as `option` declarations) verbatim as a contiguous section after the `package` declaration ## Risk Assessment Low — only affects the unreleased `elasticgraph-proto_ingestion` extension; both options are opt-in. ## References - Stacked on #1304 (which is stacked on #1080) ## Update — 2026-07-10 This PR is stacked directly on #1306 (→ #1304 → #1080).
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.
Why
With #1080's sequential numbering, reordering or removing a field renumbers everything after it — breaking wire compatibility with previously serialized data. Protobuf field numbers must stay stable across schema evolution.
What
schema_artifacts:dumpnow reads and writes aproto_field_numbers.yamlsidecar artifact: existing numbers stay fixed even if field order changes, and new fields allocate from each message's storednext_numberwithout backfilling earlier gapsschema.protoand the sidecar both use public GraphQL field names;name_in_indexremains an indexing-time concernfield.renamed_fromreuses its existing number under the new public nameenumssection; removed values keep their numbers reserved so they are never reused (0remains the generated*_UNSPECIFIEDvalue)Integer()silently truncateRisk Assessment
Low — only affects the unreleased
elasticgraph-proto_ingestionextension from #1080.References
Update — 2026-07-15
oneofalternatives now use the same stable message-field map: existing and removed subtype tags remain reserved, while new subtypes receive the next available tag.elasticgraph-proto_ingestionexamples pass with 100% line and branch coverage; GraphQL-schema validation, lint, spelling, and Steep are green.Update — 2026-07-29
path_to_schemato schema definition state #1316, which exposespath_to_schemathrough schema definition state without expandingSchemaArtifactManager's dependencies.elasticgraph-proto_ingestionexamples pass with 100% line and branch coverage; lint and Steep are green.Update — 2026-08-07
public_field_name: number, with noname_in_indexmetadata.next_numbercursor; new fields advance from that cursor instead of filling gaps, and older mapping files derive the cursor from their maximum mapped number.Indexer::RecordPreparer, which owns recursive public-to-index name translation and scalar preparation.elasticgraph-proto_ingestionexamples pass with 100% line and branch coverage; lint, spelling, and Steep are green.Update Aug 8, 12:35 CDT: Addressed the current review feedback.
next_numbercursors; cursor-less entries are invalid.name_in_indexfrom protobuf wire mappings, reserve removed fields and enum values in generated protos, and validate the sidecar with JSON Schema.from_parsed_yaml,FromYamlFile, andto_dumpable_hash, reduced allocation mutation, and grouped the mapping specs by behavior.elasticgraph-proto_ingestionexamples pass with 100% line and branch coverage; all 1,583elasticgraph-schema_definitionexamples pass with 100% coverage; lint and Steep are green.Update Aug 8, 12:59 CDT: Simplified JSON Schema validation coverage.
Update Aug 8, 13:57 CDT: Rebased the full four-PR stack onto main at 3256b4c.
Update Aug 14, 11:14 CDT: Addressed final non-blocking review feedback.