Skip to content

C# playground server: intermittent 500 from non-deterministic root InputNamespace deserialization (name missing / mangled code model) #10914

@JoshLove-msft

Description

@JoshLove-msft

Summary

The C# playground server (csharp-playground-server.azurewebsites.net) intermittently returns 500 from POST /generate. The generator subprocess exits with code 1 and logs:

The JSON value could not be converted to Microsoft.TypeSpec.Generator.Input.InputNamespace. Path: $ | LineNumber: 6 | BytePositionInLine: 1.
   at Microsoft.TypeSpec.Generator.Input.InputNamespaceConverter.ReadInputNamespace(...)
   at Microsoft.TypeSpec.Generator.Input.TypeSpecSerialization.Deserialize(...)
   at Microsoft.TypeSpec.Generator.Input.InputLibrary.Load(...)

The stack trace points at InputNamespaceConverter.ReadInputNamespace, where the only JsonException for the root is name ?? throw — i.e. the root code model object has no name property (the root object ends by line 6, so the document the generator parsed is tiny/truncated).

Why this is suspicious

  • The failure is non-deterministic for specs that always declare a namespace.
  • Deserializing a fixed JSON document is deterministic and single-threaded, and the playground server writes each request to a unique temp dir, so the same bytes can't parse differently across runs.
  • Therefore the bytes reaching the generator must differ between runs — the code model appears to be mangled/truncated somewhere between the browser emitter producing it and the generator parsing it (transport, the server's write path, or the emitter's serialization).

Current gap

The bare throw new JsonException() produces an opaque could not be converted to InputNamespace with no indication of which field is missing, and the server keeps no fingerprint of the payload, so the corruption can't be localized from telemetry.

Proposed work (diagnostics first)

  1. Generator: make the exception name the missing name field (keep STJ Path/line/byte).
  2. Playground server: log a SHA-256 of the received code model (identical specs must hash identically), and add a write/read integrity check to flag server-side mangling.

Once telemetry confirms where the bytes diverge (transport vs. server write vs. emitter output) we can fix the root cause.

A first PR adding the diagnostics + a descriptive error is linked below.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions