Repository navigation
Serde default helpers are named from their struct and field - #2094
KaloyanNaumov wants to merge 7 commits into
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.
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— with a_2,_3suffix only when a genuine name collision arises (none today).Emitter.defaultsbecame a dict keyed by helper name so the naming function still owns uniqueness, 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_take_a_suffix—FooBar.bazandFoo.bar_bazboth flatten todefault_foo_bar_baz, so the second takes_2; each declaration's attribute and both helper bodies are asserted, so the suffix is required rather than cosmetic.test_a_second_literal_for_the_same_struct_field_takes_a_suffix— one owner asking twice (the dedupe loop), which an earlier version of this test mislabelled as a collision.test_one_inserted_field_changes_only_its_own_lines_in_every_sdk— inserts a field, regenerates all six SDKs and bounds each diff: Rust ≤6, Python ≤2, Python client 0, TypeScript ≤2, Ruby 0, Go ≤4. Red on the old naming gaveassert 9083 <= 6.sdk_rust_gen.py --checkand--fixtures --checkare current under rustfmt 1.85.1 (the codegen pin); the six generated-SDK suites are 78 passed;cargo test --lockedis green across lib, client, generated contracts, models, schema mapping and registry contracts.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
Low Risk
Codegen and generated Rust SDK layout only; behavior of defaults is unchanged aside from stable naming and file split.
Overview
Renames generated Rust serde default helpers from positional names (
default_0, …) to stable names derived from struct and field (default_knowledge_add_output_probe_stable), with_2suffixes only on real collisions.Emitter.defaultsis now a dict keyed by helper name so attributes stay tied to the right function.Splits serde default functions into a new generated
wire_defaults.rs, imported fromwire_models.rs, so neither file exceeds a static analyser’s per-file size limit. Full registry generation writes both files;--outpreviews still emit a single artifact with helpers inlined. Release packaging and docs listwire_defaults.rsas a owned/generated artifact.This PR includes the one-time bulk rename of ~2,578 helpers in generated output. New unit tests lock in naming stability (inserting a field doesn’t rename unrelated helpers), suffix rules, and bounded line churn when a model gains one defaulted field across SDK generators.
Reviewed by Cursor Bugbot for commit 0c73ebd. Bugbot is set up for automated code reviews on this repo. Configure here.