From 3d4617303792e5e3719c1de647381c19884bf585 Mon Sep 17 00:00:00 2001 From: Ieuan Walker Date: Thu, 30 Apr 2026 17:33:09 +0100 Subject: [PATCH 1/2] fix(dotnet): add AgentId to SessionEvent base class Add the AgentId property to the SessionEvent base class in the .NET SDK, matching the agentId field present on all event interfaces in the Node.js generated types. This allows consumers to identify which sub-agent emitted a given event, replacing the deprecated ParentToolCallId pattern. The C# code generator (scripts/codegen/csharp.ts) was updated to emit this property when regenerating SessionEvents.cs. Fixes #1169 --- dotnet/src/Generated/SessionEvents.cs | 5 +++++ scripts/codegen/csharp.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/dotnet/src/Generated/SessionEvents.cs b/dotnet/src/Generated/SessionEvents.cs index 996f3f010..dfdaf2178 100644 --- a/dotnet/src/Generated/SessionEvents.cs +++ b/dotnet/src/Generated/SessionEvents.cs @@ -119,6 +119,11 @@ public partial class SessionEvent [JsonPropertyName("ephemeral")] public bool? Ephemeral { get; set; } + /// Sub-agent instance identifier. Absent for events from the root/main agent and session-level events. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("agentId")] + public string? AgentId { get; set; } + /// /// The event type discriminator. /// diff --git a/scripts/codegen/csharp.ts b/scripts/codegen/csharp.ts index 9c8332c09..01bd29cca 100644 --- a/scripts/codegen/csharp.ts +++ b/scripts/codegen/csharp.ts @@ -739,6 +739,8 @@ namespace GitHub.Copilot.SDK; lines.push(` [JsonPropertyName("parentId")]`, ` public Guid? ParentId { get; set; }`, ""); lines.push(...xmlDocComment(baseDesc("ephemeral"), " ")); lines.push(` [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]`, ` [JsonPropertyName("ephemeral")]`, ` public bool? Ephemeral { get; set; }`, ""); + lines.push(...xmlDocComment(baseDesc("agentId"), " ")); + lines.push(` [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]`, ` [JsonPropertyName("agentId")]`, ` public string? AgentId { get; set; }`, ""); lines.push(` /// `, ` /// The event type discriminator.`, ` /// `); lines.push(` [JsonIgnore]`, ` public virtual string Type => "unknown";`, ""); lines.push(` /// Deserializes a JSON string into a .`); From cb89b9b201bc2d889bddcba6820944a945e32482 Mon Sep 17 00:00:00 2001 From: Ieuan Walker Date: Thu, 30 Apr 2026 20:05:38 +0100 Subject: [PATCH 2/2] Add Tests --- dotnet/test/ForwardCompatibilityTests.cs | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/dotnet/test/ForwardCompatibilityTests.cs b/dotnet/test/ForwardCompatibilityTests.cs index d3f5b7785..8b61868b5 100644 --- a/dotnet/test/ForwardCompatibilityTests.cs +++ b/dotnet/test/ForwardCompatibilityTests.cs @@ -97,4 +97,41 @@ public void SessionEvent_Type_DefaultsToUnknown() Assert.Equal("unknown", evt.Type); } + + [Fact] + public void FromJson_WithAgentId_DeserializesAgentId() + { + var json = """ + { + "id": "12345678-1234-1234-1234-123456789abc", + "timestamp": "2026-06-15T10:30:00Z", + "parentId": null, + "agentId": "sub-agent-42", + "type": "future.feature_from_server", + "data": {} + } + """; + + var result = SessionEvent.FromJson(json); + + Assert.Equal("sub-agent-42", result.AgentId); + } + + [Fact] + public void FromJson_WithoutAgentId_AgentIdIsNull() + { + var json = """ + { + "id": "12345678-1234-1234-1234-123456789abc", + "timestamp": "2026-06-15T10:30:00Z", + "parentId": null, + "type": "future.feature_from_server", + "data": {} + } + """; + + var result = SessionEvent.FromJson(json); + + Assert.Null(result.AgentId); + } }