Skip to content

Fix Go session event attachment aliases#1515

Merged
stephentoub merged 1 commit into
mainfrom
fix-go-codegen-shared-schema-collisions
May 30, 2026
Merged

Fix Go session event attachment aliases#1515
stephentoub merged 1 commit into
mainfrom
fix-go-codegen-shared-schema-collisions

Conversation

@dmytrostruk
Copy link
Copy Markdown
Contributor

@dmytrostruk dmytrostruk commented May 30, 2026

Summary

  • Make Go session-event compatibility aliases conditional so stale aliases are not emitted when the runtime schema promotes a name into shared generated RPC types.
  • Keep this PR scoped to the Attachment / AttachmentType failure from the runtime bump workflow.

Root Cause

Runtime 1.0.57-2 promotes Attachment and related attachment definitions into shared API/session-event schema definitions. Go session-event codegen still always emitted legacy compatibility aliases like Attachment = UserMessageAttachment, but those old UserMessageAttachment* generated names no longer exist once the shared rpc.Attachment* definitions are generated.

That made the runtime bump workflow fail during Go generation with duplicate/stale Attachment and AttachmentType declarations.

Fix

The session-event generator now validates compatibility aliases before emitting them:

  • the target generated name must exist
  • the alias name must not already be generated

With the new runtime schema, Attachment is emitted through the normal shared alias path as Attachment = rpc.Attachment, and the stale UserMessageAttachment* aliases are skipped.

Out of Scope

This PR intentionally does not change ContextTier. If the runtime bump exposes a separate ContextTier duplicate after the Attachment issue is fixed, that should be handled separately from this narrow generator fix.

Validation

  • npm run generate:go
  • npx 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

@dmytrostruk dmytrostruk requested a review from a team as a code owner May 30, 2026 05:55
Copilot AI review requested due to automatic review settings May 30, 2026 05:55
@github-actions
Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review ✅

This PR makes targeted changes to Go-specific codegen infrastructure (scripts/codegen/go.ts) and the generated output files (go/types.go, go/zsession_events.go).

No cross-SDK consistency issues found. Here's why:

  • The ContextTier type originates from the shared schema (session-events.schema.json / api.schema.json) and is available to all SDK implementations via their respective code generation pipelines. Moving Go's ContextTier from a manual definition to a generated alias simply aligns Go with how other SDKs already get this type — from the schema.
  • The fix to make compatibility aliases conditional (Attachment, ContextTier) is internal Go codegen logic with no bearing on Python, Node.js, or .NET — those SDKs have separate codegen pipelines.
  • No new public API surface is introduced; the change is source-compatible for existing Go consumers.

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.

Generated by SDK Consistency Review Agent for issue #1515 · ● 956.9K ·

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 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 ContextTier ownership 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

@dmytrostruk dmytrostruk force-pushed the fix-go-codegen-shared-schema-collisions branch from 4201799 to c9e3f88 Compare May 30, 2026 06:04
@dmytrostruk dmytrostruk changed the title Fix Go codegen shared schema alias collisions Fix Go session event attachment aliases May 30, 2026
@stephentoub stephentoub added this pull request to the merge queue May 30, 2026
Merged via the queue into main with commit 1d990a4 May 30, 2026
16 checks passed
@stephentoub stephentoub deleted the fix-go-codegen-shared-schema-collisions branch May 30, 2026 12:34
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>
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