Skip to content

Derive session event envelopes from schema#1184

Merged
stephentoub merged 3 commits intomainfrom
stephentoub/session-event-schema
May 1, 2026
Merged

Derive session event envelopes from schema#1184
stephentoub merged 3 commits intomainfrom
stephentoub/session-event-schema

Conversation

@stephentoub
Copy link
Copy Markdown
Collaborator

@stephentoub stephentoub commented May 1, 2026

Session-event wrappers in C#, Go, and Python were relying on hard-coded sets of top-level envelope properties, so schema-level fields like agentId could be omitted from language base event models. This derives shared envelope fields from the SessionEvent schema variants and shares that schema discovery across generators, keeping SDKs aligned as the envelope evolves.

  • Add shared codegen helpers to resolve SessionEvent variants and collect envelope properties present on every variant.
  • Update C#, Go, and Python generated session-event models to include and preserve top-level agentId while keeping language-specific emission local.
  • Add round-trip and forward-compatibility coverage for top-level agentId on known and unknown event types.
  • Leave Node/TypeScript unchanged because its generated event interfaces already include top-level agentId.

stephentoub and others added 2 commits May 1, 2026 10:22
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 1, 2026 14:27
@stephentoub stephentoub requested a review from a team as a code owner May 1, 2026 14:27
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

Updates the C# session-events generator to derive top-level (envelope) properties directly from the SessionEvent schema variants so the generated .NET model stays aligned with schema evolution (e.g., adds support for agentId).

Changes:

  • Refactors the C# session-events generator to compute shared envelope fields from the schema variants instead of hard-coding a fixed set.
  • Regenerates dotnet/src/Generated/SessionEvents.cs to include SessionEvent.AgentId (and keep existing envelope fields).
  • Extends .NET tests to cover serialization and forward-compatibility behavior for agentId on known and unknown events.
Show a summary per file
File Description
scripts/codegen/csharp.ts Adds schema-driven extraction of shared SessionEvent envelope properties and emits them into the generated base class.
dotnet/src/Generated/SessionEvents.cs Regenerated output reflecting the new envelope property (AgentId) in SessionEvent.
dotnet/test/SessionEventSerializationTests.cs Verifies agentId is emitted when serializing events that set AgentId.
dotnet/test/ForwardCompatibilityTests.cs Verifies agentId deserializes for both known and unknown event types.

Copilot's findings

  • Files reviewed: 3/4 changed files
  • Comments generated: 1

Comment thread scripts/codegen/csharp.ts Outdated
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Generated by SDK Consistency Review Agent for issue #1184 · ● 848.9K

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

@stephentoub This looks great!

Since Copilot mentions that a similar fix would help Go/Python codegen, I wonder if it's worth moving some of this "shared property" utility code into the shared utils file and consuming it from the other codegenerators too.

Longer term - probably after May - I'm super keep to rip up most of our per-language codegen logic and replace the whole thing with something a lot more coherent. Right now it's so expensive to have to keep extending codegen with more and more logic on a per-language basis. Longer term I would love to pick whichever one of our codegenerators is best (probably the C# one) and generalize it into something that maps the JSON schema an intermediate representation of all the types/properties/methods, and then have very simple per-language generators that render that out into the syntax for each language. As far as I can tell, there isn't that much per-language semantic difference to worry about so it seems like it should work.

@stephentoub
Copy link
Copy Markdown
Collaborator Author

Since Copilot mentions that a similar fix would help Go/Python codegen, I wonder if it's worth moving some of this "shared property" utility code into the shared utils file and consuming it from the other codegenerators too.

Yeah, I'm cleaning that up now. I hadn't realized the others were missing it as well until I saw copilot's review.

replace the whole thing with something a lot more coherent.

Sounds good.

Share schema-level session event envelope discovery across code generators and use it for Go and Python session-event wrappers so top-level envelope fields like agentId round-trip consistently.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub stephentoub changed the title Generate C# session event envelope properties Derive session event envelopes from schema May 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Cross-SDK Consistency Review ✅

This PR is a well-targeted consistency improvement. Here's the cross-SDK analysis:

What's changing

SDK Change agentId type
Node.js/TS Unchanged (already had it) agentId?: string on all 78 event variants
Python Added agent_id to base SessionEvent agent_id: str | None = None
Go Added AgentID to base SessionEvent struct AgentID *string
.NET Added AgentId to base SessionEvent class string? AgentId

Consistency assessment

✅ Naming conventions — all four SDKs follow their respective language idioms correctly: agentId (TS camelCase), agent_id (Python snake_case), AgentID (Go PascalCase with the standard ID suffix), AgentId (.NET PascalCase).

✅ Type equivalence — all SDKs model agentId as an optional/nullable string, consistent with the schema semantics ("absent for events from the root/main agent").

✅ Structural approach — Node.js uses TypeScript union types so the field lives on each variant; the other three SDKs use class/struct hierarchies where it naturally belongs on the base type. Both patterns provide the same access pattern for consumers.

✅ Codegen alignment — extracting getSessionEventVariantSchemas and getSharedSessionEventEnvelopeProperties into utils.ts is the right structural fix; future envelope field additions will now propagate to all generators automatically.

✅ Test coverage — all three modified SDKs have added round-trip and forward-compatibility tests for agentId on both known and unknown event types.

No consistency issues found. The PR closes the gap that existed between Node.js and the other SDKs.

Generated by SDK Consistency Review Agent for issue #1184 · ● 726.2K ·

@stephentoub stephentoub merged commit f8cf846 into main May 1, 2026
33 checks passed
@stephentoub stephentoub deleted the stephentoub/session-event-schema branch May 1, 2026 15:57
jeremiahjordanisaacson pushed a commit to jeremiahjordanisaacson/copilot-sdk-supercharged that referenced this pull request May 1, 2026
* Generate C# session event envelope properties

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

* Remove unused session event initializer helper

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

* Derive session event envelopes across SDKs

Share schema-level session event envelope discovery across code generators and use it for Go and Python session-event wrappers so top-level envelope fields like agentId round-trip consistently.

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