Repository navigation
Serde default helpers are named from their struct and field - #2094
Conversation
`default_attr` named each helper from a running counter, so a defaulted field inserted mid-file renumbered every later `#[serde(default = "default_N")]`. Adding one field to `ContextPackOutput` and regenerating changed 9,921 lines of `sdk/rust/src/wire_models.rs`; after normalising `default_\d+` the same diff is 5 lines. A helper is now `default_<struct>_<field>` in snake case, with a numeric suffix only when two helpers genuinely collide. `Emitter.defaults` stays keyed by the helper name, so the naming function still owns uniqueness. This regenerates `wire_models.rs` and the schema fixtures once: 2,578 helper names move together, and the file is structurally identical to the old one once names and their line wrapping are ignored. It is the last time they move; the name no longer depends on position in the file. The regression test generates two model sets that differ by one defaulted field and asserts every untouched helper keeps its name. A second test runs an inserted field through all six SDK generators and holds each artifact to a diff of that field's own lines, so a named helper that ever starts to churn in another language fails here. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
`test_a_genuine_helper_name_collision_takes_a_suffix` asked `default_attr` twice for the same `Contract.value` with different literals. That is one owner requesting two helpers, a case the emitter never meets from a real schema, so the test named for a collision could not fail if two distinct struct/field pairs stopped being told apart. Two owners collide when their snake-cased names coincide: `FooBar.baz` and `Foo.bar_baz` both flatten to `default_foo_bar_baz`. The new test emits both structs with different literals and asserts the second helper is `default_foo_bar_baz_2` with a body of its own. Flipping the base name back to `"default_" + str(len(self.defaults))` fails it on the first attribute, as it fails the renamed same-owner test. The same-owner case is kept under a name that says what it does: a second literal for one struct field takes a suffix. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
No blocking findings. The 2,578 generated helpers and seven fixture helpers retain their original bodies and field bindings. The focused generator suite passed all 53 tests, including suffix collisions and the six-SDK insertion check.
zlareb1
left a comment
There was a problem hiding this comment.
The generator preserves the existing defaults, but the regenerated Rust file exceeds CodeQL’s per-file limit. The Rust analysis stops before extraction.
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
Fixed as you suggested — the helpers now live in their own module.
Proofs: all five artifacts |
zlareb1
left a comment
There was a problem hiding this comment.
The generated defaults are in their own module. Both files are under CodeQL’s size limit, and the public model paths stay the same. All 105 focused generator and release-verifier tests passed.
zlareb1
left a comment
There was a problem hiding this comment.
The pinned Biome check finds the same unformatted dashboard assertion in this run and on clean main. The separate repair formats that assertion. Failed job · Repair #2107
zlareb1
left a comment
There was a problem hiding this comment.
GitHub reports a merge conflict with main in sdk/rust/src/wire_models.rs. Please reconcile the wire schema changes and regenerate the Rust models so CI can validate the combined tree.
main grew the registry (17 commits since 9e82a75; registry_contracts 379 -> 380) while this branch moved the serde default helpers into src/wire_defaults.rs, so the only conflicted path was the generated src/wire_models.rs: 54 hunks, all inside the RunCompleteOutput field block where main added attributes the branch had renamed. Resolved by taking main's registry-correct output and regenerating; no generated file was hand-edited: git checkout --theirs -- sdk/rust/src/wire_models.rs python -m scripts.codegen.sdk_rust_gen Both modules current after the merge: wire_models.rs 1,837,804 B (259,348 B under CodeQL's 2,097,152 B per-file limit), wire_defaults.rs 351,866 B. 2,586 serde helpers, 2,586 default attributes, every attribute resolving across the module boundary; lib.rs keeps `mod wire_defaults;` beside `mod wire_models;`, so the public model paths are unchanged.
|
This PR is too large for Bugbot to review. It changes 20,963 lines and 1,147,922 characters. Split the change into smaller pull requests to get a review. |
zlareb1
left a comment
There was a problem hiding this comment.
The enrollment spend assertion in this unit job also fails on the clean CI base. It passes with the fix in #2132 and on current main. The existing run still fails. Failed job Merged repair
|
@KaloyanNaumov please fix merge conflicts |
# Conflicts: # sdk/rust/src/wire_models.rs
zlareb1
left a comment
There was a problem hiding this comment.
The regenerated Rust models and default helpers still fit in separate files. The new worker mode is a Serde enum with the API’s string values. Both generator freshness checks passed, and all 55 focused generator tests passed.
Regenerate sdk/rust/src/wire_models.rs and sdk/rust/src/wire_defaults.rs with the Rust generator instead of merging them by hand. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com> Assisted-by: Claude Code:claude-sonnet-5-5 Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
Merged main (8c9e1dd) as 0c73ebd and regenerated |
zlareb1
left a comment
There was a problem hiding this comment.
The generated Rust models and default helpers are each below the CodeQL source limit. The generator matches the checked-in files, and all 55 focused generator tests passed.
sdk/rust/src/wire_models.rs and wire_defaults.rs are regenerated with scripts/codegen/sdk_rust_gen.py over the merged registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The analyser's per-file limit is 4 MiB on main, and the one generated file with stable helper names is 2.2 MiB, so the separate wire_defaults module has no reason left. Revert it, pass the field to default_attr once (snake already drops the r# prefix), and bound the Go diff for an inserted field at its one line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… bounds A struct claims its name once and each field asks for one helper, so the identical-body branch never ran; the loop suffixes on any taken name. The cross-SDK test now expects the exact lines one inserted field adds, the two-owner test checks each helper's literal, and the one-owner test, which covered a call sequence the emitter never makes, is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
sdk/rust/src/wire_models.rs is regenerated with scripts/codegen/sdk_rust_gen.py over the merged registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The Python client and Ruby generators read no output-model field, so their checks could not fail; the helper-subset assertion followed from the exact Rust bound. The formatter comment now says why each formatter is skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
zlareb1
left a comment
There was a problem hiding this comment.
The new naming keeps unrelated helper names steady until two fields flatten to the same name. Keep the existing helper stable when an earlier owner introduces a collision.
A numbered suffix made the second owner's helper name depend on emit order, so a colliding field added earlier renamed an existing helper. The name is now a function of its struct and field alone, and a collision is an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
sdk/rust/src/wire_models.rs is regenerated with scripts/codegen/sdk_rust_gen.py over the merged registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Serde default helpers are named from their struct and field
Closes #2093.
sdk_rust_gen.pynamed each serde default helper with a global counter ("default_" + str(len(self.defaults))), so the 2,578 helpers inwire_models.rswere positional: one inserted defaulted field renamed every helper after it — 9,921 changed lines for a five-line insertion, 9,916 of them pure renaming.Each helper is now named for the struct and field it serves —
default_context_pack_output_blocks— and nothing else, so no other struct's place in the emit order can rename it. Two owners that flatten to one name (FooBar.bazandFoo.bar_baz) stop generation with aValueError; the registry has none today.Emitter.defaultsbecame a dict keyed by helper name, and both emit sites join its values.This PR carries the one-time renumber: 2,578 helper names move once, ~10,370 changed lines in
wire_models.rsand 28 intests/schema_mapping.rs. Names-only it is identical — strippingdefault_[a-z0-9_]+and whitespace from old and new compares equal, the whitespace-blind compare being needed because longer names re-wrap a few attributes. This is the last time this renumber happens; every later insertion changes only its own field.Tests, each red against the old naming and green here:
test_inserting_a_defaulted_field_renames_no_other_helper— two model sets differing by one defaulted field; every untouched field keeps its helper name.test_two_struct_fields_flattening_alike_stop_generation—FooBar.bazandFoo.bar_bazboth flatten todefault_foo_bar_baz; either emit order stops generation with aValueErrornaming the helper.test_one_inserted_field_changes_only_its_own_lines_in_each_model_sdk— inserts a field, regenerates the four SDKs that emit output models and pins each diff: Rust 3, Python 1, TypeScript 1, Go 1 lines, each exactly (4 s locally). On the old naming the Rust diff was 9,083 lines.sdk_rust_gen.py --checkand--fixtures --checkare current under rustfmt 1.85.1 (the codegen pin);tests/unit/test_sdk_rust_codegen.pyandtest_rust_sdk_release.pyare 105 passed;cargo clippy --all-targets -- -D warningsis clean andcargo testis green across lib, client, generated contracts, models, schema mapping and registry contracts. The single generatedwire_models.rsis 2,294,672 bytes, under the 4 MiB per-file bound the SDK static analysis job reads.One note for the CI reader:
sdk/rust/tests/client.rshas a pre-existing timing flake — on a loaded machine the worker can return at its 5 s deadline after the listener is dropped, which surfaces astcp connect error 127.0.0.1:…. One run failed that way, then the suite passed 164/164 twice. A red client run is not this change; ask for a rerun.Note
Medium Risk
Touches all generated Rust wire models and serde default wiring; behavior is intended to be identical after the one-time rename, but codegen output volume and naming invariants are critical for future schema edits.
Overview
Rust SDK codegen no longer assigns serde
defaulthelpers with a global counter (default_0,default_1, …). Each helper is nameddefault_{struct}_{field}(e.g.default_response_label) using a newsnake()helper, andEmitter.defaultsis a dict keyed by that name instead of an append-only list.Emit sites join
em.defaults.values();default_attrnow takes model and field and fails generation if two different struct/field pairs would share the same flattened name.This PR includes the one-time rename of generated helpers in
schema_mapping.rsfixtures and the fullwire_models.rsoutput (not in the diff snippet but described in the PR text).Tests update expectations for the new names and add coverage that inserting a defaulted field does not rename other helpers, flatten collisions raise
ValueError, and regenerating Rust/Python/TypeScript/Go after one mid-model field insertion stays a small local diff (Rust: 3 lines vs thousands under the old scheme).Reviewed by Cursor Bugbot for commit 43e660b. Bugbot is set up for automated code reviews on this repo. Configure here.