Skip to content

Commit 1e119c1

Browse files
stephentoubCopilot
andcommitted
Fix .NET build break and float hook timestamps for hooks.invoke
CLI 1.0.71 promoted hooks.invoke to an internal client-global RPC method. The C# codegen still emitted its internal request/result DTOs behind a public IHooksHandler surface, producing CS0050/CS0051 inconsistent-accessibility errors that broke the entire .NET build. It also registered a second, unwired hooks.invoke handler that would shadow the working handwritten one. Filter internal client-global and client-session methods in the C# code generator so no generated interface, handler property, or RPC registration is emitted for internal methods like hooks.invoke. The handwritten SetLocalRpcMethod(hooks.invoke, ...) registration continues to serve hooks. This mirrors, for .NET's static typing, the routing fixes already applied to Node, Python, and Go. Also tolerate hook timestamp epoch milliseconds encoded as either JSON integers or floats in UnixMillisecondsDateTimeOffsetConverter, covering the CLI 1.0.71 float serialization (matching the Rust fix). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 94a20428-6b0e-4733-a354-0abf2d186320
1 parent 6e748a5 commit 1e119c1

3 files changed

Lines changed: 23 additions & 156 deletions

File tree

dotnet/src/Generated/Rpc.cs

Lines changed: 0 additions & 152 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dotnet/src/UnixMillisecondsDateTimeOffsetConverter.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ namespace GitHub.Copilot;
1313
public sealed class UnixMillisecondsDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
1414
{
1515
/// <inheritdoc />
16-
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
17-
DateTimeOffset.FromUnixTimeMilliseconds(reader.GetInt64());
16+
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
17+
{
18+
// The CLI may serialize the epoch-millisecond timestamp as a JSON integer
19+
// or as a floating-point number (e.g. 1700000000000.0). GetInt64 throws on a
20+
// fractional token, so fall back to reading a double and truncating.
21+
long milliseconds = reader.TryGetInt64(out long value) ? value : (long)reader.GetDouble();
22+
return DateTimeOffset.FromUnixTimeMilliseconds(milliseconds);
23+
}
1824

1925
/// <inheritdoc />
2026
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) =>

scripts/codegen/csharp.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
findSharedSchemaDefinitions,
2828
postProcessSchema,
2929
propagateInternalVisibility,
30+
filterNodeByVisibility,
3031
resolveRef,
3132
resolveObjectSchema,
3233
resolveSchema,
@@ -2490,11 +2491,23 @@ function generateRpcCode(
24902491
let sessionRpcParts: string[] = [];
24912492
if (schema.session) sessionRpcParts = emitSessionRpcClasses(schema.session, classes);
24922493

2494+
// Client handler surfaces (interfaces, handler properties, RPC registration)
2495+
// are only generated for public methods. Internal client methods (e.g.
2496+
// `hooks.invoke`) are runtime transport plumbing and must not surface any
2497+
// generated code — including their request/result DTOs, which would
2498+
// otherwise leak as `internal` types referenced by a `public` handler
2499+
// interface (CS0050/CS0051 inconsistent accessibility).
24932500
let clientSessionParts: string[] = [];
2494-
if (schema.clientSession) clientSessionParts = emitClientSessionApiRegistration(schema.clientSession, classes);
2501+
if (schema.clientSession) {
2502+
const publicClientSession = filterNodeByVisibility(schema.clientSession, "public");
2503+
if (publicClientSession) clientSessionParts = emitClientSessionApiRegistration(publicClientSession, classes);
2504+
}
24952505

24962506
let clientGlobalParts: string[] = [];
2497-
if (schema.clientGlobal) clientGlobalParts = emitClientGlobalApiRegistration(schema.clientGlobal, classes);
2507+
if (schema.clientGlobal) {
2508+
const publicClientGlobal = filterNodeByVisibility(schema.clientGlobal, "public");
2509+
if (publicClientGlobal) clientGlobalParts = emitClientGlobalApiRegistration(publicClientGlobal, classes);
2510+
}
24982511

24992512
const lines: string[] = [];
25002513
lines.push(`${COPYRIGHT}

0 commit comments

Comments
 (0)