feat(process): bound a finalization interval before forced capture timeout

Add optional finalization_ms to keep observing a captured root after SIGTERM, record the actual finalizer exit and each signal attempt, and escalate once when needed. Bind the initial root identity to captured ownership and preserve observations through cleanup uncertainty.

Fixes #1253.

Co-authored-by: Mykola Dementiev <16836724+nikolay-dementiev@users.noreply.github.com>
Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com>
This commit is contained in:
Mykola Dementiev
2026-10-11 09:55:43 +08:00
committed by GitHub
co-authored by Mykola Dementiev N0zoM1z0
parent 1e51c732bb
commit c1efa6467d
23 changed files with 3569 additions and 74 deletions
+35 -5
View File
@@ -95,11 +95,17 @@ const committedScenarioEvents = (
export const processScenarioCommitment = (
scenario: ProcessScenario,
executableSha256?: string,
): Readonly<Record<string, unknown>> => ({
...scenario,
events: committedScenarioEvents(scenario.events, true),
executable_sha256: executableSha256 ?? null,
});
): Readonly<Record<string, unknown>> => {
// A zero interval is today's immediate kill; leaving it out keeps the
// committed identity of every scenario that predates the field unchanged.
const { finalization_ms: finalizationMs, ...committed } = scenario;
return {
...committed,
...(finalizationMs > 0 ? { finalization_ms: finalizationMs } : {}),
events: committedScenarioEvents(scenario.events, true),
executable_sha256: executableSha256 ?? null,
};
};
/** Project observation settings shared by capture and reconstruction. */
export const processComparisonContract = (
@@ -117,6 +123,9 @@ export const processComparisonContract = (
timeout_ms: scenario.timeout_ms,
idle_timeout_ms: scenario.idle_timeout_ms,
settle_ms: scenario.settle_ms,
...(scenario.finalization_ms > 0
? { finalization_ms: scenario.finalization_ms }
: {}),
limits: scenario.limits,
normalization: scenario.normalization,
...(scenario.normalization.ports
@@ -177,6 +186,15 @@ export const processScenarioSchema = z
timeout_ms: positiveBudget.default(30_000),
idle_timeout_ms: positiveBudget.default(30_000),
settle_ms: z.number().int().safe().nonnegative().default(100),
finalization_ms: z
.number()
.int()
.safe()
.nonnegative()
.default(0)
.describe(
"Milliseconds a target may keep running after SIGTERM when timeout_ms or idle_timeout_ms fires, before SIGKILL; 0 sends SIGKILL immediately. Both signals reach the captured root only while its launch-time start identity still matches; cancellation ends the run at once.",
),
limits: z
.strictObject({
output_bytes: positiveBudget.default(1_000_000),
@@ -221,6 +239,18 @@ export const processScenarioSchema = z
}),
})
.superRefine((scenario, context) => {
// Each budget is a safe integer, but their sum is not checked anywhere
// else. BigInt keeps the comparison exact beyond the representable range.
const lifecycleBudget =
BigInt(scenario.timeout_ms) +
BigInt(scenario.finalization_ms) +
BigInt(scenario.settle_ms);
if (lifecycleBudget > BigInt(Number.MAX_SAFE_INTEGER))
context.addIssue({
code: "custom",
message: `timeout_ms + finalization_ms + settle_ms must stay at or below ${String(Number.MAX_SAFE_INTEGER)} ms, the largest total exactly representable as a JavaScript number`,
path: ["timeout_ms"],
});
if (
!fitsProcessTerminalCellBudget(
scenario.terminal.columns,