Skip to content

Fix codegen identifier sanitization#1285

Merged
stephentoub merged 6 commits into
mainfrom
stephentoub/fix-rust-generation
May 13, 2026
Merged

Fix codegen identifier sanitization#1285
stephentoub merged 6 commits into
mainfrom
stephentoub/fix-rust-generation

Conversation

@stephentoub
Copy link
Copy Markdown
Collaborator

String enum values from newer Copilot runtime schemas can contain path or URL separators, such as /chat/completions. Those values must continue to round-trip on the wire, but C#, Go, and Rust generators also need to turn them into valid language identifiers.

This updates the code generators to sanitize generated identifiers while preserving the original serialized values. Rust also now emits top-level discriminated unions from API schema definitions so newer schemas that reference union result types compile correctly.

Generated output was refreshed against the currently imported @github/copilot 1.0.46 schema. The rust/src/generated/api_types.rs diff is declaration reordering only; comparing public type bodies by name showed no added, removed, or changed generated Rust API definitions.

Validation performed:

  • cd scripts/codegen && npm run generate
  • cd nodejs && npm run build
  • python -m compileall -q python\copilot
  • cd go && go test ./... -run '^$'
  • cd dotnet && dotnet build test\GitHub.Copilot.SDK.Test.csproj --no-restore
  • cd rust && cargo check --all-features --all-targets

Sanitize generated string enum identifiers across C#, Go, and Rust so schema values containing path or URL separators produce valid language identifiers while preserving wire values. Also emit top-level Rust discriminated unions needed by newer schemas and refresh the Rust generated output from the currently imported 1.0.46 schema.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 13, 2026 16:29
@stephentoub stephentoub requested a review from a team as a code owner May 13, 2026 16:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Rust, Go, and C# code generators to better sanitize schema-derived identifiers (especially string-enum values containing path/URL separators) while preserving correct on-the-wire serialized values. It also adjusts Rust API type generation to emit top-level discriminated unions for union schema definitions, and refreshes/aligns Rust docs/examples with current generated request shapes.

Changes:

  • Update identifier splitting/sanitization logic across Rust/Go/C# generators to handle non-alphanumeric separators (e.g., /chat/completions) and avoid invalid identifiers.
  • Add Rust enum-variant uniqueness handling for discriminated unions and string enums; emit top-level discriminated unions for union definitions.
  • Refresh generated Rust API types ordering and update the Rust README example for SessionsForkRequest to use to_event_id.
Show a summary per file
File Description
scripts/codegen/rust.ts Adds Rust identifier sanitization + uniqueness helpers; improves union/string-enum variant naming; emits top-level union enums.
scripts/codegen/go.ts Broadens identifier word splitting for Go naming and enum const suffix generation to handle more separators.
scripts/codegen/csharp.ts Adds C# identifier sanitization + uniqueness helper and uses it for generated string-enum static members.
rust/src/generated/api_types.rs Generated Rust API types re-ordered (no type body changes intended).
rust/README.md Updates fork request example to use to_event_id and idiomatic .into().

Copilot's findings

  • Files reviewed: 4/5 changed files
  • Comments generated: 2

Comment thread scripts/codegen/csharp.ts
Comment thread scripts/codegen/go.ts
@SteveSandersonMS
Copy link
Copy Markdown
Contributor

@stephentoub Were all the per-language generators re-run? Haven't gone through it line by line but seems unexpected that the Rust generated code has new content but the other languages don't.

Comment thread scripts/codegen/rust.ts Outdated
@SteveSandersonMS
Copy link
Copy Markdown
Contributor

@stephentoub Optimally I think we should do the enum member normalization on the runtime side when we produce the JSON schema so that we can fail at that stage if it leads to a clash.

@stephentoub
Copy link
Copy Markdown
Collaborator Author

@stephentoub Were all the per-language generators re-run? Haven't gone through it line by line but seems unexpected that the Rust generated code has new content but the other languages don't.

I believe the generator changes just caused some of the output in Rust to be re-ordered, so the surface area is actually the same but it looks like a bunch of changes in the diff.

@stephentoub
Copy link
Copy Markdown
Collaborator Author

@stephentoub Optimally I think we should do the enum member normalization on the runtime side when we produce the JSON schema so that we can fail at that stage if it leads to a clash.

Agreed.

stephentoub and others added 5 commits May 13, 2026 13:18
Fail code generation when sanitized enum values collide with existing public member names instead of stabilizing arbitrary numeric suffixes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add the optional post-denial model turns so denied edit tests can replay deterministically if the CLI asks the model to summarize the denied tool result.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add the optional post-denial model turn for the shared multi-client replay snapshot so SDKs that wait for the final assistant message can replay deterministically.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Point the Rust denied-permission multi-client E2E test at the shared multi_client snapshot and remove the duplicate Rust-only copy.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub stephentoub merged commit 4d14749 into main May 13, 2026
42 of 44 checks passed
@stephentoub stephentoub deleted the stephentoub/fix-rust-generation branch May 13, 2026 19:08
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.

3 participants