fix(render-node): match job sizes per encoder; blank batch entries name no preset

A node announced one size limit, the largest of all its encoders (managed
MJPEG at 65535 px), so it claimed H.264 jobs larger than its H.264 encoder
takes. Each offered encoder now carries its own limit and the server matches
codec and size per encoder; the node-wide limit is the largest offered one,
for encoders that announce none. A hand-written batch with null or blank
entries no longer throws when a job is posted or examined.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-03 09:39:17 +00:00
1 parent 559292ddbb
commit 1e255fb075
6 files changed
+55 -15

No files matched your search

+3 -2
View File
@@ -76,11 +76,12 @@ public static class ProcessingJobs
];
}
/// <summary>The batch presets of an export besides its own, each once.</summary>
/// <summary>The batch presets of an export besides its own, each once (blank entries of a hand-written batch are skipped).</summary>
internal static IEnumerable<string> BatchPresets(ExportSettings export)
{
var main = ExportResolver.Resolve(export).BasePresetId;
return export.Batch.Distinct(StringComparer.OrdinalIgnoreCase).Where(id => !id.Equals(main, StringComparison.OrdinalIgnoreCase));
return export.Batch.Where(id => !string.IsNullOrWhiteSpace(id)).Distinct(StringComparer.OrdinalIgnoreCase)
.Where(id => !id.Equals(main, StringComparison.OrdinalIgnoreCase));
}
/// <summary>A batch preset rendered with its own values, named and placed like the export it belongs to.</summary>
@@ -73,15 +73,15 @@ public sealed class RenderNodeClient : IAsyncDisposable
}
/// <summary>
/// The encoders this node offers: every single-file capability of the host's providers, hardware ones only when the
/// user lets renders use them (<see cref="ProcessingOptions.AllowsHardware"/>).
/// The encoders this node offers, each with its largest output: every single-file capability of the host's
/// providers, hardware ones only when the user lets renders use them (<see cref="ProcessingOptions.AllowsHardware"/>).
/// </summary>
public IReadOnlyList<NodeEncoder> Encoders =>
[
.. _processing.Encoders.SelectMany(p => p.Capabilities)
.Where(c => VideoCodecInfo.DefaultContainer(c.Codec) != ContainerFormat.ImageSequence
&& (!c.Hardware || _processing.AllowsHardware(ExportResolver.CustomId)))
.Select(c => new NodeEncoder(ProcessingJobs.CodecName(c.Codec), c.Name, c.Hardware, c.SupportsTenBit)),
.Select(c => new NodeEncoder(ProcessingJobs.CodecName(c.Codec), c.Name, c.Hardware, c.SupportsTenBit, c.MaxWidth, c.MaxHeight)),
];
/// <summary>Completes when the node has stopped: asked to, or refused by the server (signed out, no render-node right,
@@ -107,9 +107,10 @@ public sealed class RenderNodeClient : IAsyncDisposable
/// <summary>Registers this node (again) and returns its id.</summary>
public async Task<Guid> RegisterAsync(CancellationToken cancellationToken)
{
var capabilities = _processing.Encoders.SelectMany(p => p.Capabilities).ToList();
var request = new RegisterNodeRequest(_options.ClientName, Encoders, capabilities.Count > 0 ? capabilities.Max(c => c.MaxWidth) : 0,
capabilities.Count > 0 ? capabilities.Max(c => c.MaxHeight) : 0);
// Each encoder carries its own limit; the node-wide one (for servers that read only that) is the largest offered.
var encoders = Encoders;
var request = new RegisterNodeRequest(_options.ClientName, encoders, encoders.Select(e => e.MaxWidth).DefaultIfEmpty().Max(),
encoders.Select(e => e.MaxHeight).DefaultIfEmpty().Max());
var node = await _client.RegisterNodeAsync(request, cancellationToken).ConfigureAwait(false);
_nodeId = node.Id;
return node.Id;
+9 -2
View File
@@ -22,10 +22,17 @@ public sealed record JobDto(
/// <summary><c>POST /api/v1/jobs</c>: kind = render, deep-analyse, proxies, thumbs, verify, scan, rebuild, maintenance…</summary>
public sealed record CreateJobRequest(string Kind, IReadOnlyList<Guid> Target, string? ParametersJson);
/// <summary><c>POST /api/v1/nodes/register</c>: a client offers its GPU encoders (BRIEF §14.7).</summary>
/// <summary>
/// <c>POST /api/v1/nodes/register</c>: a client offers its GPU encoders (BRIEF §14.7). <see cref="MaxWidth"/> ×
/// <see cref="MaxHeight"/> is the largest output of any of them, for encoders that announce no limit of their own.
/// </summary>
public sealed record RegisterNodeRequest(string ClientName, IReadOnlyList<NodeEncoder> Encoders, int MaxWidth, int MaxHeight);
public sealed record NodeEncoder(string Codec, string Name, bool Hardware, bool TenBit);
/// <summary>
/// One encoder of a render node. <see cref="MaxWidth"/> × <see cref="MaxHeight"/> is its largest output (0 = not announced:
/// the node's own limit applies), so jobs go only to a node with an encoder of their codec that takes their size.
/// </summary>
public sealed record NodeEncoder(string Codec, string Name, bool Hardware, bool TenBit, int MaxWidth = 0, int MaxHeight = 0);
public sealed record RenderNodeDto(Guid Id, string ClientName, string Username, IReadOnlyList<NodeEncoder> Encoders, DateTimeOffset LastHeartbeat, string State);
+10 -5
View File
@@ -250,11 +250,16 @@ public sealed class RenderNodeService(
}
}
/// <summary>The node has an encoder for the job's codec and handles its resolution (0 = no announced limit).</summary>
private static bool CanEncode(RegisterNodeRequest node, RenderJobParameters job) =>
node.Encoders.Any(e => string.Equals(e.Codec, job.Codec, StringComparison.OrdinalIgnoreCase))
&& (node.MaxWidth <= 0 || job.Width <= node.MaxWidth)
&& (node.MaxHeight <= 0 || job.Height <= node.MaxHeight);
/// <summary>
/// The node has an encoder for the job's codec that handles its resolution: the encoder's own limit, else the node's
/// (0 = no announced limit).
/// </summary>
internal static bool CanEncode(RegisterNodeRequest node, RenderJobParameters job) =>
node.Encoders.Any(e => string.Equals(e.Codec, job.Codec, StringComparison.OrdinalIgnoreCase)
&& Fits(job.Width, e.MaxWidth > 0 ? e.MaxWidth : node.MaxWidth)
&& Fits(job.Height, e.MaxHeight > 0 ? e.MaxHeight : node.MaxHeight));
private static bool Fits(int size, int limit) => limit <= 0 || size <= limit;
internal static string? AppendLog(string? tail, string? line)
{
@@ -87,6 +87,8 @@ public sealed class RenderNodeClientTests(TestContext context)
var id = await node.RegisterAsync(context.Cancellation);
var registered = (await client.ListNodesAsync(context.Cancellation)).Single(n => n.Id == id);
Assert.SequenceEqual(["apng", "gif", "mjpeg"], registered.Encoders.Select(e => e.Codec).Order(StringComparer.Ordinal));
// Each encoder announces its own largest output, so the server matches job sizes per codec.
Assert.True(registered.Encoders.All(e => (e.MaxWidth, e.MaxHeight) == (65535, 65535)), "per-encoder limits");
}
[Test]
@@ -70,6 +70,26 @@ public sealed class RenderNodeTests(TestContext context)
}
}
[Test]
public async Task EachEncoderTakesOnlyJobsWithinItsOwnSizeLimit()
{
await using var server = await TestServer.StartAsync(context);
var (editor, _, _) = await server.UserAsync("alberto", "editor", renderNode: true);
var sequence = await JobApiTests.CreateSequenceAsync(editor);
// The software H.264 encoder stops at 4096 px although the node's MJPEG encoder writes far larger frames.
using var registered = await editor.PostAsJsonAsync("/api/v1/nodes/register", new RegisterNodeRequest("studio-pc",
[new NodeEncoder("h264", "H.264 Encoder MFT", false, false, 4096, 2304), new NodeEncoder("mjpeg", "Managed MJPEG", false, false, 65535, 65535)],
65535, 65535), ProtocolJson.Default.RegisterNodeRequest);
var node = await registered.ReadAsync(ProtocolJson.Default.RenderNodeDto);
Assert.Equal((4096, 2304), (node.Encoders[0].MaxWidth, node.Encoders[0].MaxHeight));
await JobApiTests.CreateAsync(editor, "render", sequence, H264Job(6144, 3456));
using (var none = await editor.PostAsync($"/api/v1/nodes/{node.Id}/claim", null)) await none.ExpectAsync(HttpStatusCode.NoContent);
var uhd = await JobApiTests.CreateAsync(editor, "render", sequence, H264Job(3840, 2160));
using var claim = await editor.PostAsync($"/api/v1/nodes/{node.Id}/claim", null);
Assert.Equal(uhd.Id, (await claim.ReadAsync(ProtocolJson.Default.ClaimedJob)).Job.Id);
}
[Test]
public async Task TheOutputUploadBecomesARenderAndFinishesTheJob()
{
@@ -123,6 +143,10 @@ public sealed class RenderNodeTests(TestContext context)
await foreign.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden");
}
private static string H264Job(int width, int height) => JsonSerializer.Serialize(
new RenderJobParameters("H.264", """{"preset":{"isAuto":false,"manual":"4k-h264"}}""", "h264", width, height, UseProxies: false, null),
ProtocolJson.Default.RenderJobParameters);
private static async Task<RenderNodeDto> RegisterAsync(HttpClient client, string name, string codec, int maxWidth)
{
using var response = await client.PostAsJsonAsync("/api/v1/nodes/register",