Skip to content

fix: Go codegen enum prefixes and type name reconciliation#883

Open
MackinnonBuck wants to merge 11 commits intoupdate-copilot-1.0.7from
fix/go-codegen-enum-prefixes
Open

fix: Go codegen enum prefixes and type name reconciliation#883
MackinnonBuck wants to merge 11 commits intoupdate-copilot-1.0.7from
fix/go-codegen-enum-prefixes

Conversation

@MackinnonBuck
Copy link
Collaborator

Summary

Fixes two Go codegen bugs introduced in #878 (Update @github/copilot to 1.0.7).

Bug 1: Build-breaking type name mismatch

RPC wrapper code computed type names via toPascalCase() (e.g., SessionMcpListResult) but quicktype generated different names following Go initialism rules (e.g., SessionMCPListResult). The Go SDK didn't compile.

Fix: After quicktype runs, extract actual generated struct names and use a resolveType() lookup instead of recomputing via toPascalCase. Also added mcp to goInitialisms.

Bug 2: Nonsense/missing enum prefixes

quicktype used whimsical prefixes for colliding enum constants (PurpleDisabled, FluffyFailed, TentacledFailed) and left non-colliding constants unprefixed (Running, Connected, Error). The canonical Go convention is TypeNameValue.

Fix: postProcessEnumConstants() renames all unprefixed constants inside const blocks and their associated marshal/unmarshal functions to follow TypeNameValue convention, while preserving struct field names.

Additional fix: Field name reconciliation

quicktype sometimes renames struct fields to avoid Go keyword conflicts. The wrapper code now extracts actual field names from quicktype output instead of recomputing them.

Breaking change

All Go enum constants now use TypeNameValue prefixes. Downstream code referencing old names (e.g., copilot.SessionIdle -> copilot.SessionEventTypeSessionIdle, rpc.Interactive -> rpc.ModeInteractive) must be updated.

Verification

  • go build ./... passes
  • go test ./... passes (2 pre-existing E2E failures unrelated to this change)

MackinnonBuck and others added 2 commits March 18, 2026 09:14
…names

Rename all references to copilot session event type and rpc constants
to use the new prefixed naming convention matching the generated code:

- copilot.SessionCompactionStart -> copilot.SessionEventTypeSessionCompactionStart
- copilot.ExternalToolRequested -> copilot.SessionEventTypeExternalToolRequested
- copilot.PermissionRequested -> copilot.SessionEventTypePermissionRequested
- copilot.ToolExecutionStart -> copilot.SessionEventTypeToolExecutionStart
- copilot.AssistantReasoning -> copilot.SessionEventTypeAssistantReasoning
- copilot.Abort -> copilot.SessionEventTypeAbort
- rpc.Interactive -> rpc.ModeInteractive
- rpc.Plan -> rpc.ModePlan
- rpc.Warning -> rpc.LevelWarning
- rpc.Error -> rpc.LevelError
- rpc.Info -> rpc.LevelInfo
(and all other constants listed in the rename)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add 'mcp' to goInitialisms so toPascalCase produces SessionMCP* matching quicktype
- Post-process enum constants to use canonical Go TypeNameValue convention
  (replaces quicktype's Purple/Fluffy/Tentacled prefixes and unprefixed constants)
- Reconcile type names: extract actual quicktype-generated struct names and use them
  in RPC wrapper code instead of recomputing via toPascalCase
- Extract field name mappings from quicktype output to handle keyword-avoidance renames
- Update all handwritten Go references to use new prefixed constant names

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@MackinnonBuck MackinnonBuck requested a review from a team as a code owner March 18, 2026 17:13
Copilot AI review requested due to automatic review settings March 18, 2026 17:13
Copy link
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

Fixes Go SDK build/regeneration issues introduced by updated schemas by reconciling quicktype-generated names with wrapper code and normalizing enum constant naming.

Changes:

  • Post-processes quicktype Go output to normalize enum constant prefixes and reconcile type/field names used by RPC wrapper generation.
  • Updates Go SDK code, samples, and E2E tests to use the new enum constant names.
  • Regenerates Go RPC/session-events generated files reflecting the new naming rules (including MCP-related types).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/codegen/go.ts Adds enum-constant post-processing and extracts quicktype-generated type/field names for wrapper emission.
go/session.go Updates event-type and RPC enum constant references to the new prefixed names; updates LogOptions docs/examples.
go/samples/chat.go Updates sample event-type constants to the new prefixed names.
go/rpc/generated_rpc.go Regenerated RPC types/wrappers with normalized enum constants and MCP naming (e.g., MCPRpcApi, SessionRpc.MCP).
go/internal/e2e/testharness/helper.go Updates error event constant to new prefixed name.
go/internal/e2e/session_test.go Updates session event-type and log-level constants to new prefixed names.
go/internal/e2e/rpc_test.go Updates Mode enum constants to new Mode* names.
go/internal/e2e/permissions_test.go Updates tool execution event constant to new prefixed name.
go/internal/e2e/multi_client_test.go Updates external tool/permission event constants to new prefixed names.
go/internal/e2e/compaction_test.go Updates compaction event constants to new prefixed names.
go/generated_session_events.go Regenerated session-events types with normalized enum constants (including SessionEventType* values).

You can also share your feedback on Copilot code review. Take the survey.

@github-actions
Copy link
Contributor

SDK Consistency Review ✅

I've reviewed PR #883 for cross-SDK consistency. This PR fixes Go-specific codegen bugs without creating inconsistencies across the SDK implementations.

Summary

Scope: Go codegen only (no changes needed in other SDKs)

Changes:

  1. Enum constant naming: Fixes Go enums to follow canonical TypeNameValue convention (e.g., AgentModeInteractive, ExtensionStatusRunning instead of quicktype's whimsical prefixes like PurpleDisabled, FluffyFailed)
  2. Type name reconciliation: Extracts actual generated type names instead of recomputing them, fixing build-breaking mismatches
  3. Field name reconciliation: Extracts actual field names from quicktype output (e.g., correctly uses Error instead of LevelError)

Cross-SDK Consistency Check

Each SDK follows its own language's enum conventions idiomatically:

SDK Enum Pattern Example
TypeScript String literal unions "interactive" | "plan" | "autopilot"
Python Enum with UPPERCASE AgentMode.INTERACTIVE, AgentMode.PLAN
C# PascalCase enum UserMessageDataAgentMode.Interactive
Go TypeNameValue (after this fix) AgentModeInteractive, AgentModePlan

The field name fix (LevelErrorError) brings Go in line with Node.js and Python, which both correctly use the error field name.

Conclusion

No cross-SDK consistency issues found. The changes are appropriate Go-specific fixes that align Go codegen with both Go conventions and cross-SDK API semantics. No similar changes are needed in other language implementations.

Generated by SDK Consistency Review Agent for issue #883 ·

MackinnonBuck and others added 5 commits March 18, 2026 10:28
The generated enum constant was renamed from copilot.File to
copilot.AttachmentTypeFile to follow Go's TypeNameValue convention.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…onyms

The Python codegen used toPascalCase() to compute type names like
SessionMcpListResult, but quicktype generates SessionMCPListResult
(uppercase MCP). This caused runtime NameError in Python scenarios.

Apply the same approach as go.ts: after quicktype runs, parse the
generated output to extract actual class names and build a
case-insensitive lookup map. Use resolveType() in emitMethod() and
emitRpcWrapper() instead of recomputing names via toPascalCase().

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- TestAgentSelectionRpc: CLI now returns built-in agents, so instead of
  asserting zero agents, verify no custom agents appear when none configured
- TestMultiClient: increase broadcast event timeout from 10s to 30s

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The generated Rpc.LogAsync method added a 'url' parameter between
'ephemeral' and 'cancellationToken', causing a type mismatch when
Session.LogAsync passed cancellationToken as the 4th positional arg.

Added the 'url' parameter to Session.LogAsync to match the generated
Rpc method signature and pass it through correctly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…, add pr/ado

- valuePascal now uses goInitialisms so 'url' -> 'URL', 'mcp' -> 'MCP', etc.
- Phase 2 regex uses [\s\S]*? to match multi-line func bodies
- Added 'pr' and 'ado' to goInitialisms

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor

Cross-SDK Consistency Review

I've reviewed this PR for consistency across the Node.js, Python, Go, and .NET SDKs. Here are my findings:

✅ Go Enum Naming Convention Change

The primary change in this PR—standardizing Go enum constants to use the TypeNameValue convention—is Go-specific and appropriate. Each SDK follows its own language conventions:

  • TypeScript: String literal union types (no enum constant names)
  • Python: SCREAMING_SNAKE_CASE without type prefixes (e.g., AttachmentType.FILE)
  • .NET: PascalCase with context-specific enum type names (e.g., UserMessageDataAttachmentsItemGithubReferenceReferenceType.Issue)
  • Go: TypeNameValue convention (e.g., AttachmentTypeFile, ReferenceTypePR)

The Go change brings it in line with Go best practices and avoids name collisions—this is good.

⚠️ Potential Consistency Issue: Session.LogAsync() URL Parameter

The .NET Session.cs was updated to add a url parameter to LogAsync() (line 762), but the equivalent high-level methods in other SDKs have not been updated:

Current state:

  • Generated RPC types: All SDKs (Node, Python, Go, .NET) have url in SessionLogParams (generated from schema)
  • .NET high-level API: Session.LogAsync() now exposes url parameter
  • Node.js high-level API: Session.log() does NOT expose url (line 750-755)
  • Python high-level API: Session.log() does NOT expose url (line 769-801)
  • Go high-level API: Session.Log() does NOT expose URL field in LogOptions

Recommendation:
Unless the url parameter addition to .NET was unintentional, the other three SDKs should be updated to expose it as well to maintain feature parity. If this was added as part of a separate change that hasn't been propagated yet, please track it separately.

Summary

  • Go codegen fixes: ✅ Language-specific, no action needed
  • Python type resolution: ✅ Language-specific improvement
  • Session.log() url parameter: ⚠️ .NET added it, but Node/Python/Go haven't—should be addressed for consistency

Generated by SDK Consistency Review Agent for issue #883 ·

MackinnonBuck and others added 2 commits March 18, 2026 11:04
The CLI now returns built-in/default agents even when no custom agents
are configured. Update the assertion to verify no custom test agent
names appear in the list, rather than asserting the list is empty.
Matches the pattern used in the Go E2E test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CLI 1.0.7 no longer delivers broadcast external_tool events to
secondary clients. Skip the 'both clients see tool request and
completion events' test in all three languages with a clear note.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
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

Fixes Go (and related Python wrapper) codegen regressions introduced by the @github/copilot 1.0.7 update by reconciling generated names with quicktype output and normalizing Go enum constant naming.

Changes:

  • Go codegen now post-processes quicktype output to enforce TypeNameValue enum constant naming and to reconcile wrapper type/field names with actual generated identifiers.
  • Python codegen now resolves RPC params/result type names from quicktype-emitted classes to avoid casing/initialism mismatches (e.g., MCP).
  • E2E tests are adjusted for CLI 1.0.7 behavior changes (multi-client external_tool broadcasts), including skips and updated assertions.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
scripts/codegen/python.ts Resolve wrapper type names against quicktype-emitted Python classes to avoid casing mismatches.
scripts/codegen/go.ts Add enum post-processing + resolveType/field-name extraction to align Go wrappers with quicktype output.
python/e2e/test_multi_client.py Skips multi-client external_tool broadcast test due to CLI behavior change.
python/e2e/test_agent_and_compact_rpc.py Makes agent-list assertion resilient to built-in/default agents.
python/copilot/generated/rpc.py Regenerated Python RPC wrapper now references MCP-cased types.
go/session.go Updates Go SDK usage to new prefixed session event + enum constant names.
go/samples/chat.go Updates sample to new prefixed session event constants.
go/rpc/generated_rpc.go Regenerated Go RPC types/wrappers with normalized enum constants and MCP naming.
go/internal/e2e/testharness/helper.go Updates event-type comparisons to new prefixed constants.
go/internal/e2e/session_test.go Updates tests to new prefixed session event + enum constant names.
go/internal/e2e/rpc_test.go Updates tests to new prefixed enum constants (e.g., ModeInteractive).
go/internal/e2e/permissions_test.go Updates tests to new prefixed session event constants.
go/internal/e2e/multi_client_test.go Skips multi-client external_tool broadcast test; updates event constants.
go/internal/e2e/compaction_test.go Updates tests to new prefixed compaction event constants.
go/internal/e2e/agent_and_compact_rpc_test.go Makes agent-list assertion resilient to built-in/default agents; updates naming.
go/generated_session_events.go Regenerated with TypeNameValue enum constants (incl. SessionEventType*).
dotnet/test/MultiClientTests.cs Skips multi-client external_tool broadcast test due to CLI behavior change.
dotnet/src/Session.cs Adds optional url parameter to Session.LogAsync and forwards to RPC.
docs/features/image-input.md Updates Go docs to use renamed attachment type constant.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 1240 to 1244
Fleet *FleetRpcApi
Agent *AgentRpcApi
Skills *SkillsRpcApi
Mcp *McpRpcApi
MCP *MCPRpcApi
Plugins *PluginsRpcApi
self, mctx: MultiClientContext
):
"""Both clients see tool request and completion events."""
pytest.skip("CLI 1.0.7 no longer broadcasts external_tool events to secondary clients")
t.Cleanup(func() { client2.ForceStop() })

t.Run("both clients see tool request and completion events", func(t *testing.T) {
t.Skip("Skipped: CLI 1.0.7 no longer broadcasts external_tool events to secondary clients")
private CopilotClient Client2 => _client2 ?? throw new InvalidOperationException("Client2 not initialized");

[Fact]
[Fact(Skip = "CLI 1.0.7 no longer broadcasts external_tool events to secondary clients")]
MackinnonBuck and others added 2 commits March 18, 2026 11:59
Remove the t.Skip/pytest.skip/Fact(Skip=...) additions that were
disabling the multi-client broadcast tests across Go, Python, and C#.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
resolveType() already handles type name reconciliation from quicktype
output, so these initialisms aren't needed and would cause an unnecessary
breaking change to the SessionRpc.Mcp field name.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor

✅ SDK Consistency Review: No Issues Found

This PR fixes Go-specific codegen bugs and maintains cross-SDK consistency. The changes are Go-specific implementation details that align with Go conventions.

Summary of Changes

  • Go codegen: Fixed enum constant naming to follow Go's TypeNameValue convention (e.g., SessionEventTypeAssistantMessage, AttachmentTypeFile)
  • Go SDK & tests: Updated all references to use the new prefixed constants
  • Documentation: Updated Go examples to reflect the new enum names
  • Breaking change: Downstream Go code must update enum references

Cross-SDK Consistency ✅

Each SDK follows language-specific idioms for enum/constant representation:

SDK Pattern Example
TypeScript String literals event.type === "assistant.message"
Python Enum with UPPER_SNAKE_CASE SessionEventType.ASSISTANT_MESSAGE
.NET Class-based pattern matching case AssistantMessageEvent:
Go (after this PR) Prefixed constants SessionEventTypeAssistantMessage

Why This Is Consistent

While the syntax differs, the semantic consistency is maintained:

  • All SDKs expose the same underlying event types and values
  • Each follows its language's conventions (TypeScript unions, Python Enums, C# polymorphism, Go constants)
  • The Go prefix pattern (TypeNameValue) prevents name collisions and follows Go best practices
  • API users in each language get an idiomatic experience

Verification

✅ Documentation updated for Go examples
✅ No equivalent changes needed in other SDKs (they already follow their own conventions)
✅ This is purely a Go codegen fix, not a feature addition

Recommendation: Approve. This PR fixes Go-specific issues while maintaining appropriate cross-SDK consistency.

Generated by SDK Consistency Review Agent for issue #883 ·

@MackinnonBuck
Copy link
Collaborator Author

We should fix https://github.com/github/copilot-agent-runtime/pull/5035 before merging this.

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.

2 participants