Round #846
11 May 2026, 09:45· csharp· Meta-Llama-3.3-70B-Instruct· r15-firing-v3
- Complexity
- band 0
- ZP / UO / OBS
- 3 / 0 / 2
- Journey weight
- 389
- Lightshift ΔL
- +0.00
Prompt
Implement an IHealthCheck that returns Healthy when a TCP socket on a remote host responds within 500ms, and Unhealthy otherwise.
Zero-point index (what the engine surfaced)
ZPI-ZPI-0003 | 2026-05-11T09:45:32Z
Implement an IHealthCheck that returns Healthy when a TCP socket on a remote host responds within 500ms, and Unhealthy otherwise.
ZERO POINT — 3 entries (structural invariants)
● hsl(190.26, 100%, 27%) IHealthCheck [contract]
● hsl(302.56, 100%, 27%) HealthCheckResult [contract]
● hsl(190.42, 100%, 27%) IHealthCheckPublisher [contract]
UNOBSERVED — 0 entries (implied truths)
OBSERVED — 2 entries (explicit in request)
◉ hsl(37.95, 100%, 15%) when [feature]
◉ hsl(73.85, 100%, 15%) on [feature]
COMPLEXITY │ 5 entries │ spread: 36° │ band: LOW
Baseline response (no ZPI)
**TCP Health Check Implementation**
=====================================
Below is an example implementation of an `IHealthCheck` that checks the health of a remote host by attempting to establish a TCP connection within a specified timeout.
```csharp
using Microsoft.Extensions.Diagnostics.HealthChecks;
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
public class TcpHealthCheck : IHealthCheck
{
private readonly string _host;
private readonly int _port;
private readonly int _timeoutMs;
public TcpHealthCheck(string host, int port, int timeoutMs = 500)
{
_host = host;
_port = port;
_timeoutMs = timeoutMs;
}
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var endpoint = new IPEndPoint(IPAddress.Parse(_host), _port);
var task = socket.ConnectAsync(endpoint);
if (await Task.WhenAny(task, Task.Delay(_timeoutMs, cancellationToken)) != task)
{
return HealthCheckResult.Unhealthy("TCP connection timed out");
}
await task;
return HealthCheckResult.Healthy("TCP connection established successfully");
}
catch (SocketException ex)
{
return HealthCheckResult.Unhealthy($"TCP connection failed: {ex.Message}");
}
catch (Exception ex)
{
return HealthCheckResult.Unhealthy($"An error occurred: {ex.Message}");
}
}
}
```
**Example Usage**
-----------------
To use this health check, you can register it in the `Startup.cs` file of your ASP.NET Core application:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddHealthChecks()
.AddCheck<TcpHealthCheck>("tcp-check", new TcpHealthCheck("example.com", 80));
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/health");
});
}
```
In this example, the health check will attempt to establish a TCP connection to `example.com` on port 80. If the connection is successful within the specified timeout (500ms by default), the health check will return a healthy result. Otherwise, it will return an unhealthy result.
You can then access the health check results by visiting the `/health` endpoint of your application.
Enhanced response (with ZPI)
```csharp
using System;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
public class TcpHealthCheck : IHealthCheck
{
private readonly string _host;
private readonly int _port;
public TcpHealthCheck(string host, int port)
{
_host = host;
_port = port;
}
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var task = socket.ConnectAsync(_host, _port, cancellationToken);
if (await Task.WhenAny(task, Task.Delay(500, cancellationToken)) == task)
{
await task;
return HealthCheckResult.Healthy();
}
else
{
return HealthCheckResult.Unhealthy();
}
}
catch (Exception ex)
{
return HealthCheckResult.Unhealthy(ex.Message);
}
}
}
```
To register this health check in the DI container, you can use the following code:
```csharp
services.AddHealthChecks()
.AddCheck<TcpHealthCheck>("TCP Health Check", new TcpHealthCheck("remote-host", 1234));
```
This implementation creates a TCP socket and attempts to connect to the remote host within a 500ms timeout. If the connection is successful, it returns a healthy result; otherwise, it returns an unhealthy result. The `CheckHealthAsync` method is designed to be asynchronous to avoid blocking the calling thread. The `TcpHealthCheck` class takes the remote host and port as constructor parameters, making it reusable for different hosts and ports.
Grader chain
Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.
V1samba/Meta-Llama-3.3-70B-Instruct
WorseV4qwen2.5-coder-3b-instruct
BetterV5openrouter/qwen/qwen3-235b-a22b-2507
BetterV7qwen2.5-coder-7b-instruct
BetterV8openai/gpt-4.1
SameV9anthropic/claude-opus-4-7
WorseV12openai/gpt-4o
BetterComments
Our grader said what it said. What do you say? Comment as a guest below.
No comments yet. Be the first to say what you make of this round.