Repository navigation
Description
Company
Independent
Component
Rust SDK
Describe what's wrong
sdk_rust_gen.py names each serde default helper with a global sequential counter:
# scripts/codegen/sdk_rust_gen.py:448
fn = "default_" + str(len(self.defaults))There are 2,578 defaulted fields today, so 2,578 helpers named default_0 … default_2577 (5,156 name occurrences in sdk/rust/src/wire_models.rs). Because the number is positional, inserting one defaulted field anywhere before the end renames every helper after it — the generated file churns by thousands of lines for a one-field change.
Measured on main at 9e82a7594, adding a single field (probe_stable: str = "probe" after sections in ContextPackOutput, server/memory/api/models_context.py) and regenerating:
git diff --no-index --numstat→ 4,963 added / 4,958 removed (9,921 changed lines)- the same two files with
default_[0-9]+normalised on both sides → 5 added / 0 removed
So 9,916 of those lines are the counter renaming helpers whose bodies did not change. The other SDK generations change almost nothing for the same insertion — Python 1 line, Python client 0, TypeScript 1, Ruby 0, Go 3 (see expected behaviour) — so this is specific to the Rust emitter — serde needs a named path for #[serde(default = "…")], and the name is taken from insertion order rather than from the field it belongs to.
Does it reproduce on the latest release or main?
Yes
How to reproduce
On main at 9e82a7594, with the pinned formatter (RUST_CODEGEN_VERSION: 1.85.1, rustfmt 1.8.0-stable):
# add one defaulted field to a model the registry emits, e.g. after `sections` in ContextPackOutput
python -m scripts.codegen.sdk_rust_gen
git diff --numstat sdk/rust/src/wire_models.rs
# -> 4963 4958 sdk/rust/src/wire_models.rs
git diff sdk/rust/src/wire_models.rs | grep -E '^[+-].*default_[0-9]+' | wc -l
# -> every helper after the insertion point
Normalising default_[0-9]+ on both sides leaves the inserted field, its attribute and its three-line helper.
Expected behavior
An inserted field should change only its own lines. The other SDKs already behave that way — the same insertion, regenerated, changes: Rust 9,921 lines today, Python 1, Python client 0, TypeScript 1, Ruby 0, Go 3. A helper's name should be a function of the struct and field it serves (default_<struct>_<field>), so the name is stable wherever the field sits.
Error message and logs
No error — the failure mode is a diff. It also costs merges: any two branches that regenerate this file conflict across thousands of unrelated lines.
Environment
main at 9e82a7594, Python 3.12.16, rustfmt 1.8.0-stable (Rust 1.85.1, the version CI pins for codegen).
Related issues and pull requests
Found while adding two optional output fields in #2011: the six semantic lines of that change carried 8,986 changed lines in sdk/rust/src/wire_models.rs, of which 8,684 were only a renumbered default_N.
How this was found
While preparing a PR: the diff for a small output-shape change was dominated by helper renames, and normalising the names showed the real change was six lines.
Additional context
The rule this breaks is general even though the mechanism is Rust-only: a generated identifier must be a stable function of what it names, never of insertion order. A test worth having downstream of the fix: insert one field, regenerate every SDK, and assert each diff is local — that is what would catch this class in any generator that starts emitting named helpers.
Activity