{"record":{"id":"998c7ae90ec4ba51","repo":"microsoft/autogen","slug":"request-is-null","errorCode":null,"errorMessage":"Request is null.","messagePattern":"Request is null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs","lineNumber":146,"sourceCode":"            };\n            return new CallOptions(headers: metadata);\n        }\n    }\n\n    private readonly bool _strictMessageDeserialization;\n    public IProtoSerializationRegistry SerializationRegistry { get; } = new ProtobufSerializationRegistry();\n\n    public void Dispose()\n    {\n        this._shutdownCts.Cancel();\n        this._messageRouter.Dispose();\n    }\n\n    private async ValueTask HandleRequest(RpcRequest request, CancellationToken cancellationToken = default)\n    {\n        if (request is null)\n        {\n            throw new InvalidOperationException(\"Request is null.\");\n        }\n        if (request.Payload is null)\n        {\n            throw new InvalidOperationException(\"Payload is null.\");\n        }\n        if (request.Target is null)\n        {\n            throw new InvalidOperationException(\"Target is null.\");\n        }\n\n        var agentId = request.Target;\n        var agent = await this._agentsContainer.EnsureAgentAsync(agentId.FromProtobuf());\n\n        // Convert payload back to object\n        var payload = request.Payload;\n        var message = payload.ToObject(SerializationRegistry);\n\n        var messageContext = new MessageContext(request.RequestId, cancellationToken)","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs#L128-L164","documentation":"GrpcAgentRuntime.HandleRequest throws InvalidOperationException when an incoming RpcRequest message is entirely null. The handler performs defensive validation on the gRPC wire payload before doing any work; a null request means the message envelope itself is malformed, which under protobuf normally indicates a protocol/version mismatch or a broken custom sender rather than an application bug.","triggerScenarios":"The runtime's message router delivers a null RpcRequest to HandleRequest — typically from deserialization edge cases, a client built against an incompatible proto contract, or internal code calling HandleRequest(null) directly (e.g. in tests).","commonSituations":"Version skew between the agent process and the runtime host (older/newer AgentRpc proto); custom test doubles that pass null; bugs in message-routing glue after a package upgrade.","solutions":["Align Microsoft.AutoGen package versions (and the embedded AgentRpc contract) across all processes in the deployment.","If it reproduces, capture the raw gRPC frame/logging at the sender to find where the null envelope originates.","In tests, pass a valid RpcRequest with Target and Payload set."],"exampleFix":"// before (test double)\nawait runtime.HandleRequest(null); // throws\n\n// after\nvar request = new RpcRequest { Target = agentId.ToProtobuf(), Payload = payload, RequestId = rid };\nawait runtime.HandleRequest(request);","handlingStrategy":"validation","validationCode":"if (request is null) { /* drop/log the malformed frame; never route null into the handler */ }","typeGuard":"static bool IsValidRpcRequest(RpcRequest? r) => r is not null && r.Target is not null && r.Payload is not null;","tryCatchPattern":"try { await runtime.HandleRequest(request); }\ncatch (InvalidOperationException) { /* log the envelope, check proto version alignment */ }","preventionTips":["Pin identical Microsoft.AutoGen versions across all processes sharing the gRPC contract.","Wrap router glue with null-envelope guards and metric counters to detect protocol drift early."],"tags":["grpc","wire-protocol","validation","version-skew"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}