Fix Go session event attachment aliases#1515
Merged
Merged
Conversation
Contributor
Cross-SDK Consistency Review ✅This PR makes targeted changes to Go-specific codegen infrastructure ( No cross-SDK consistency issues found. Here's why:
This is a housekeeping fix for Go's generated code to stay in sync with the evolving runtime schema, and it does not create any API parity gaps with other language SDKs.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Go code generation so public aliases remain stable when runtime schemas promote formerly event-specific definitions into shared API/session-event definitions.
Changes:
- Filters legacy Go session-event compatibility aliases so stale or conflicting aliases are skipped.
- Moves public
ContextTierownership from manual Go code to generated aliases. - Regenerates Go public session-event aliases to preserve current-schema compatibility.
Show a summary per file
| File | Description |
|---|---|
scripts/codegen/go.ts |
Adds alias filtering and legacy ContextTier bridge generation. |
go/zsession_events.go |
Re-exports ContextTier and constants through generated aliases. |
go/types.go |
Removes the manual ContextTier type and constants. |
Copilot's findings
Files not reviewed (1)
- go/zsession_events.go: Language not supported
- Files reviewed: 2/3 changed files
- Comments generated: 0
4201799 to
c9e3f88
Compare
stephentoub
approved these changes
May 30, 2026
stephentoub
added a commit
that referenced
this pull request
May 30, 2026
…n collisions Follows up on #1515. Adds two pieces of generator hardening on top of the conditional alias emit that #1515 introduced. 1. `collectGoSharedAnyOfDiscriminatorAliasNames`: detect shared anyOf unions with a string-const discriminator property and synthesize the discriminator enum name + per-variant const names so the public `copilot` alias file re-exports them alongside the union and variant structs. Without this, schema-shared discriminated unions like `Attachment` (in the bumped schema) would expose `copilot.Attachment` and its variant structs but not `copilot.AttachmentType` / `copilot.AttachmentTypeFile` etc. 2. `collectHandWrittenGoPublicNames`: scan hand-written `go/*.go` files for exported type/const names and exclude them from the alias file so schema-shared definitions that happen to share a name with a hand-written declaration (e.g. `ContextTier`) don't double-declare in the `copilot` package and break `go build`. Note from #1515 explicitly flagged `ContextTier` as out-of-scope; this handles it. On the current 1.0.56 schema the only behavioural change is that the public `copilot` package now also re-exports the `UserToolSessionApprovalKind` discriminator enum and its 8 constants (which the `rpc` package was already exporting). On the bumped 1.0.57+ schema this lets the generator succeed (no more `assertNoGoRpcSessionEventConflicts` failure) and produces the expected `Attachment*` alias surface while letting hand-written `ContextTier` win. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-merge-queue Bot
pushed a commit
that referenced
this pull request
May 30, 2026
* Update @github/copilot to 1.0.57-2 - Updated nodejs and test harness dependencies - Re-ran code generators - Formatted generated code * Synthesize shared anyOf discriminator aliases and exclude hand-written collisions Follows up on #1515. Adds two pieces of generator hardening on top of the conditional alias emit that #1515 introduced. 1. `collectGoSharedAnyOfDiscriminatorAliasNames`: detect shared anyOf unions with a string-const discriminator property and synthesize the discriminator enum name + per-variant const names so the public `copilot` alias file re-exports them alongside the union and variant structs. Without this, schema-shared discriminated unions like `Attachment` (in the bumped schema) would expose `copilot.Attachment` and its variant structs but not `copilot.AttachmentType` / `copilot.AttachmentTypeFile` etc. 2. `collectHandWrittenGoPublicNames`: scan hand-written `go/*.go` files for exported type/const names and exclude them from the alias file so schema-shared definitions that happen to share a name with a hand-written declaration (e.g. `ContextTier`) don't double-declare in the `copilot` package and break `go build`. Note from #1515 explicitly flagged `ContextTier` as out-of-scope; this handles it. On the current 1.0.56 schema the only behavioural change is that the public `copilot` package now also re-exports the `UserToolSessionApprovalKind` discriminator enum and its 8 constants (which the `rpc` package was already exporting). On the bumped 1.0.57+ schema this lets the generator succeed (no more `assertNoGoRpcSessionEventConflicts` failure) and produces the expected `Attachment*` alias surface while letting hand-written `ContextTier` win. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix generated type collisions after Copilot update Remove handwritten ContextTier definitions now owned by generated schema types, update Attachment type references, and keep generated outputs in sync. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Rust import generation and Python test import ordering - Rust generator: merge crate::types imports in api_types.rs so the source matches what rustfmt produces on Linux (joining adjacent use crate::types::... lines). This unbreaks the Codegen Check on CI. - Python: sort the import block in test_event_forward_compatibility.py to satisfy ruff I001. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Go session event union decoding Register shared API union decoders when generating Go session event payload unmarshalling so event data can decode attachments and approvals referenced from the API schema. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Attachment/AttachmentTypefailure from the runtime bump workflow.Root Cause
Runtime
1.0.57-2promotesAttachmentand related attachment definitions into shared API/session-event schema definitions. Go session-event codegen still always emitted legacy compatibility aliases likeAttachment = UserMessageAttachment, but those oldUserMessageAttachment*generated names no longer exist once the sharedrpc.Attachment*definitions are generated.That made the runtime bump workflow fail during Go generation with duplicate/stale
AttachmentandAttachmentTypedeclarations.Fix
The session-event generator now validates compatibility aliases before emitting them:
With the new runtime schema,
Attachmentis emitted through the normal shared alias path asAttachment = rpc.Attachment, and the staleUserMessageAttachment*aliases are skipped.Out of Scope
This PR intentionally does not change
ContextTier. If the runtime bump exposes a separateContextTierduplicate after theAttachmentissue is fixed, that should be handled separately from this narrow generator fix.Validation
npm run generate:gonpx tsx go.ts <@github/copilot@1.0.57-2 session-events.schema.json> <@github/copilot@1.0.57-2 api.schema.json>git diff --check