CODE EXECUTION · DEADLINES

Agent code execution: terminate a runaway script

Run a modeled loop against a deadline and compare a supervisor kill, cooperative cancellation, an iteration budget and no limit at all.

Computed experiment · sixty inspection seconds

Event trace

    Computed data

    Final metrics

    Modeled time only: each iteration adds the configured milliseconds and no code runs. The blocking call happens once, at x = 150, in the blocking script. A hard kill models an out-of-process supervisor; cooperative cancellation runs only between iterations. The run is cut off at ten times the deadline when nothing stops it.

    A deadline needs an enforcer

    The modeled script is a loop: while x is below a limit, add a step to x. Each iteration costs Work per iteration milliseconds. With the opening settings the script is the stalled loop, whose step is zero, so it can never finish on its own. The deadline is 5,000 ms and Enforcement is a supervisor that kills the process at the deadline. At ten milliseconds per iteration the kill happens at exactly 5,000 ms after 500 iterations, and no result is returned. The Elapsed-time samples table records x and elapsed time every fifty iterations, plus the stopping point.

    Compare the four enforcement modes

    Choose Script checks for cancellation every N iterations with a check every 100 iterations: the check at iteration 500 sees the expired deadline and stops at 5,000 ms. Raise the interval to 300: the first check after the deadline is at iteration 600, so the stop comes at 6,000 ms, 1,000 ms late. Iteration budget only stops the stalled loop after 600 iterations, also 6,000 ms; lower the budget to 450 and it stops at 4,500 ms, before the deadline. With No limit nothing stops it: the model gives up at 50,000 ms, ten times the deadline, and reports a runaway.

    Blocking calls defeat cooperative checks

    Choose the blocking script and set Blocking call duration to 5,000 ms. At x = 150, after 1,500 ms, the thread blocks until 6,500 ms. The supervisor kill still stops it at 5,000 ms after 150 iterations. Cooperative cancellation cannot run while the call blocks; its next check is at iteration 200, at 7,000 ms, 2,000 ms past the deadline. Code that only checks between iterations cannot interrupt a call that never returns control.

    Find the exact boundary

    Choose the finite loop of 400 iterations. At 10 ms per iteration it completes in 4,000 ms with total 80,200. At 12 ms it still completes, at 4,800 ms. At 13 ms it would need 5,200 ms, so the supervisor kills it at 5,000 ms after 385 iterations. The finite but slow script needs 4,000 iterations; under No limit it completes at 40,000 ms, which the lab reports as 35,000 ms late because the caller waited for all of it. The Deadline slider moves every one of these boundaries.

    Scope of the model

    Time is modeled, not measured: no code runs and each iteration adds the configured cost. A real supervisor kill is a process or container stop, which also discards partial results and may leave external side effects half done. Java threads cannot be safely force-stopped inside the JVM, which is why agent code executors use a separate process with its own timeout. Play, Next event, Restart, Speed and Inspection time replay the run over sixty seconds.