fix(scripting): #1064 the ScriptWorker applies the in-process result rule — a returned lazy sequence is materialised inside the run and held to Scripting:MaxResultElements (Hello.max_result_elements), same value and same failure text in both runners

This commit is contained in:
Joseph Doherty
2026-12-03 16:35:01 -05:00
parent fe4bbbe256
commit a06dc8dd9f
8 changed files with 85 additions and 5 deletions
@@ -77,6 +77,7 @@ internal sealed class WorkerHost
private int _maxFrameBytes = ScriptWorkerFrameCodec.DefaultMaxFrameBytes;
private int _queueCapacity = 4096;
private TimeSpan _hardGrace = TimeSpan.FromSeconds(1);
private int _maxResultElements = ScriptingOptions.DefaultMaxResultElements;
private TimeSpan _heartbeatInterval = TimeSpan.FromSeconds(1);
/// <summary>
@@ -160,6 +161,7 @@ internal sealed class WorkerHost
if (hello.HardGraceMs > 0) _hardGrace = TimeSpan.FromMilliseconds(hello.HardGraceMs);
if (hello.HeartbeatIntervalMs > 0) _heartbeatInterval = TimeSpan.FromMilliseconds(hello.HeartbeatIntervalMs);
if (hello.CompileThreads > 0) _compileThreads = (int)Math.Min(hello.CompileThreads, 64);
if (hello.MaxResultElements > 0) _maxResultElements = (int)Math.Min(hello.MaxResultElements, int.MaxValue);
_workerSoftClock = hello.WorkerSoftClock;
_testStallReaderOnDiag = hello.TestStallReaderOnDiag;
// lmxopcua#1014: no PE-cache key or directory any more — the host verifies, compiles and signs, and sends a
@@ -458,6 +460,11 @@ internal sealed class WorkerHost
try
{
object? value = script.Run(inputs, logger, clock, cts.Token, out var isPredicate);
// lmxopcua#1064: the in-process guard's result rule (#1059), applied here too and still inside the run —
// this eval is registered with the watchdog and its allocation sample is still open — so a returned lazy
// sequence is enumerated under the run's deadlines and held to Scripting:MaxResultElements, and an
// over-cap or open-slot sequence fails the script with the same message in both runners.
if (!isPredicate) value = ScriptResultMaterializer.Materialize(value, _maxResultElements);
if (isPredicate)
{
result.Predicate = (bool)value!;