Skip to content

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

Merged
N0zoM1z0 merged 71 commits into
morluto:mainfrom
nikolay-dementiev:feat/1253-capture-finalization-interval
Oct 11, 2026
Merged

N0zoM1z0 merged 71 commits into
morluto:mainfrom
nikolay-dementiev:feat/1253-capture-finalization-interval

Conversation

@nikolay-dementiev

@nikolay-dementiev nikolay-dementiev commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

A capture deadline previously killed the target before its SIGTERM handler could write a final report. This extends the existing CLI/MCP process-capture scenario with optional finalization_ms (default 0): send SIGTERM to the captured root, continue collecting observations, then attempt SIGKILL once if the requested interval expires.

Fixes #1253. Supports the usability work in #1065.

The initiating timeout or idle timeout remains exit.reason, and deadline exits retain exit.code: null. Optional exit.finalization records the requested and observed interval, the actual finalizer exit code (or null), and each signal attempt with its delivery result and any unavailable reason. Incomplete captures retain the same finalization facts. A zero interval preserves existing scenario commitments; the combined timeout, finalization and settlement budget must be a safe integer.

For example, add "finalization_ms": 1500 to an existing capture scenario. A cooperative target can then return:

{
  "code": null,
  "signal": 0,
  "reason": "timeout",
  "finalization": {
    "requested_ms": 1500,
    "elapsed_ms": 12,
    "exit_code": 0,
    "signals": [
      { "signal": "SIGTERM", "sent_at_ms": 0, "delivery": "signaled" }
    ]
  }
}

The first retained root identity is bound to the captured run token between two OS identity observations. Finalization signals recheck that identity; unavailable ownership or identity is reported without a bare-PID fallback. Identity inspection and signaling remain separate OS operations. Cancellation during finalization stops it immediately. Only the root receives finalization signals; owned descendant cleanup follows, and cleanup uncertainty preserves collected facts.

The contributor's implementation and commits are preserved. Maintenance follow-ups bind the initial identity to captured ownership, validate complete observations inside cleanup-partial envelopes, and cover a detached descendant that survives root finalization before owned cleanup. The shared acceptance client still validates the full advertised schema dialect and uses the normal SDK call path, while compiling its additional validators only for tools it calls. This removes duplicated cold test-client work; it does not resolve upstream SDK #2997.

Integrated frozen main 29cc1b87 after #1664 fixed the source-qualified Electron API fixtures and the resulting merge conflicts. The three fixtures use main's implementation, preserving the contributor history and keeping them out of this PR's final diff.

Validation:

  • Contributor-reported macOS coverage and independent Linux baseline results are recorded in the review comments.
  • Independent integrated Linux checks: npm run check:fast, npm run build:cached, and npm run docs:check passed. Final head e980e6b0 passed all 250 cases in 13 focused files, covering the process/schema cases, real compiled finalization workflows, and adjacent Electron CLI/MCP workflows. npm run verify:test-discovery previously found all 796 test files exactly once; no test files were added or removed afterward.
  • Real compiled CLI/MCP workflows exercise cooperative and nonzero finalizer exits, forced escalation, cancellation, default commitments, invalid budgets, file-hash omissions, and detached owned cleanup.
  • Three representative OS-observation regressions demonstrate the initial binding gap and pass with the follow-up. They do not manufacture real OS PID reuse or signal foreign processes.

Windows capture remains unsupported and is rejected before PTY launch. No Hopper/Ghidra verification applies. Signal-attempt evidence does not establish which concurrent action caused an exit, and PTY exit notification can arrive after the OS exit. The requested interval is not an end-to-end wall-clock bound over snapshots and cleanup. No package release was performed.

@nikolay-dementiev

Copy link
Copy Markdown
Contributor Author

Thanks for the Linux run. The finalizer's exit code is now recorded (45caf68): exit.finalization.exit_code holds the code the PTY reported when the target exited on its own during finalization, so a finalizer that exits 3 shows 3. It is null when a signal ended the target or no exit was observed. exit.code stays null for deadline exits, as before.

The batch-3 exited is most likely the ENOSPC from the same batch. The fixture writes pid.txt and periodic.json at startup, so a full /tmp makes it exit before any deadline.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: This is a real-Linux runtime check of #1583 for #1253, at the new head 1cb4525. Fixed: a finalizer's exit code now shows in the record, and separately, all 21 repeat batches pass on a roomy /tmp. Still not run: Windows, macOS, the full test lanes and the merge with current main.

Everything below ran on one Linux box. I changed nothing on GitHub.

Check on Linux, head 1cb4525 Node 22.23.1 Node 24.18.0 Node 26.11.1
Finalizer exits 0: exit.finalization.exit_code 0 0 0
Finalizer exits 3: exit.finalization.exit_code 3 3 3
Killed by SIGTERM, no handler: exit_code, exit.signal null, 15 null, 15 null, 15
Deadline, child ignores SIGTERM: exit_code, exit.signal null, 9 null, 9 null, 9
exit.code in all four rows above null null null
Real-child repeat batches, 32 tests each 7 of 7 pass 7 of 7 pass 7 of 7 pass
The 7 test files this PR changes 124 pass 124 pass 124 pass
npm run check:fast pass pass pass

Each exit-code row is 3 runs per Node, and all 3 agreed.

  • Exit code. A finalizer that exits 3 now shows 3, and one that exits 0 shows 0. With an idle deadline the result was the same. With no finalization_ms, the record has no finalization object and exit.signal is 9. On the old head 8a1600e, the same programs left exit_code out of the record (2 of 2 runs per program per Node).
  • Batch 3. Before every batch, /tmp had 7.8 to 9.5 GB free (40 to 51 percent used). My notes from the first run say /tmp was 94 to 97 percent full then. All 21 batches passed, so this fits your reading, but it does not prove it for that old batch.
  • Same error, forced. I ran the PR's fixture through the CLI with pid.txt linked to /dev/full, where every write fails with ENOSPC. The record says exited, exit.code 1, before any deadline, as you described. This is a write error, not a full /tmp.
  • Leftovers. I made 93 CLI runs (63 on the new head, 30 on the old head). After each, no process of mine was alive 300 ms later.
  • Main. At the start GitHub showed the PR as mergeable. At 19:54 UTC it showed conflicting again. Main gained f9ea9a9, which changes four files this PR also changes. I did not test that merge.
  • Merged with main. Another agent applied the PR as a patch onto main at 16d9c5a (fix(ci): preserve cleanup boundaries and bounded failure assertions #1618). The patch applied clean, and the 7 test files gave 124 of 124 passes on Node 24.18.0. I did not repeat that run (details in a fold).

Still not run

  • Windows (the PR rejects capture there) and macOS.
  • The full test:boundary, test:acceptance and test:fast lanes, plus npm run check and docs:check.
  • The PR merged into current main. Main was 39da0b1 at 19:54 UTC, and it keeps moving.
  • A truly full /tmp. I would need root to make a small filesystem, so I did not.
  • Four programs from my first comment. They test a grandchild, the output tail, the start identity and an exit near the deadline. On the new head I reran only the exit-code programs.
  • A real pid reuse.

Thanks, nikolay-dementiev, for recording the exit code and for the quick answer on batch 3.

Commands

Every run used env -i with a fake HOME, its own TMPDIR under /tmp/p1583, nice -n 10 and ulimit -c 0. The PATH held one Node directory at a time. All npm calls used a fake HOME, their own cache and log folder, and HUSKY=0.

  • Trees: I ran git archive on 1cb4525 and on 8a1600e, from a local mirror, into two folders. In the new tree, npm ci and npm run build ran once, on Node 24.18.0. The old tree shared those node_modules through hard links (the lockfile is identical) and had its own build. All three Nodes ran that same dist, built on Node 24.18.0.
  • Native PTY probe: probeProcessCaptureCapability() from the new build returned available: true (backend node-pty) on all three Nodes first.
  • Exit-code programs: node scripts/rea.mjs capture-process scenario.json --json, once per run, from a runner that scanned /proc for a unique marker 300 ms after each exit.
  • Repeat batches: npm run test:focused -- tests/boundary/process/processCaptureLifecycle.test.ts tests/acceptance/process/processFinalization.test.ts, 7 times per Node, each with its own TMPDIR.
  • Changed test files: npm run test:focused -- with src/domain/process/processScenario.test.ts, src/domain/process/processCapture.validation.test.ts, src/process/capture/ProcessCaptureLifecycle.test.ts, src/process/capture/ProcessHarness.test.ts, tests/boundary/process/processCaptureLifecycle.test.ts, tests/boundary/process/processFilesystemCoverageAdapters.test.ts and tests/acceptance/process/processFinalization.test.ts. None were skipped.
  • Lint and types: npm run check:fast in a git clone --no-checkout of the mirror, then git checkout --detach 1cb45255c. The lint step needs a git checkout. My first Node 22 and Node 26 runs were turbo cache hits, so I reran both with -- --force, and those reruns passed with 0 cached.
  • Forced ENOSPC: the scenario starts tests/fixtures/processFinalization.mjs cooperative <dir> with timeout_ms 1000 and finalization_ms 1500. <dir>/pid.txt is a symlink to /dev/full.
Raw output: exit codes

I wrote four small Node scripts and ran each from the CLI. clean writes periodic.json. On SIGTERM it waits 200 ms. Then it writes final.json. It prints a line. It exits with a chosen code. plain has no signal handler. ignore swallows SIGTERM and SIGINT. And selfexit exits with code 7 after 300 ms. Scenarios used timeout_ms 1000 and finalization_ms 1500, unless the row says otherwise. The ranges cover 3 runs on the new head and 2 on the old head.

Tree Program exit.code, exit.signal, exit.reason finalization.exit_code Exit seen (elapsed_ms) SIGKILL sent at
new clean, exits 0 null, 0, timeout 0 233 to 242 ms none
new clean, exits 3 null, 0, timeout 3 236 to 257 ms none
new clean, exits 3, idle deadline only null, 0, idle_timeout 3 232 to 243 ms none
new plain null, 15, timeout null 27 to 31 ms none
new ignore null, 9, timeout null 1,533 to 1,540 ms 1,506 to 1,511 ms
new clean, exits 3, no finalization_ms null, 9, timeout no finalization object none none
new selfexit 7, 0, exited no finalization object none none
old clean, exits 0 or 3 null, 0, timeout key absent 233 to 241 ms none
old plain null, 15, timeout key absent 26 to 29 ms none
old ignore null, 9, timeout key absent 1,530 to 1,541 ms 1,504 to 1,510 ms
old clean, exits 3, no finalization_ms null, 9, timeout no finalization object none none

In every row, SIGTERM went out at 0 ms and was recorded as signaled. For one Node 24 run of clean, the child's own log says it exited with 3 at 210 ms after SIGTERM. REA saw the exit at 257 ms.

Raw output: repeat batches

Each batch ran the two real-child files (32 tests in all). Load is the 1-minute average before the batch. It counts tasks that run or wait, out of 24 threads. /tmp is a 16 GB memory-backed filesystem. Other jobs on the box used it too.

Batch Result /tmp free before /tmp used before Load before
Node 24, 1 to 7 32 pass each 9.5 GB each 40 percent each 1.19, 1.42, 1.29, 1.03, 1.50, 1.34, 1.35
Node 22, 1 to 7 32 pass each 9.5, 9.5, 8.9, 8.3, 8.1, 7.9, 7.8 GB 40, 40, 44, 47, 49, 51, 51 percent 0.94, 1.27, 1.66, 3.00, 2.34, 5.17, 3.29
Node 26, 1 to 7 32 pass each 7.8, 8.7, 9.5, 9.5, 9.5, 9.5, 9.5 GB 51, 45, 40, 40, 40, 40, 40 percent 2.11, 1.23, 1.06, 2.50, 1.40, 1.37, 2.06

The 7 changed files started at load 1.78 (Node 24), 2.22 (Node 22) and 3.22 (Node 26). The first run counted 30 tests in these two files at 8a1600e. I did not check which tests were added since.

Raw output: forced write error
cli exit 0
{"code":1,"signal":0,"reason":"exited"}
Error: ENOSPC: no space left on device, write
    at writeFileSync (node:fs:2430:20)
    at file:///tmp/p1583/head/tests/fixtures/processFinalization.mjs:13:1

The error text is from the CLI's stderr. The failing line is the fixture's first write, pid.txt. The run used Node 22.23.1.

Raw output: merge with main (another agent's run, not repeated by me)

Read from that agent's notes file, so secondhand.

  • Main was 16d9c5a (fix(ci): preserve cleanup boundaries and bounded failure assertions #1618). The PR base is dce81ca, and main had 5 commits past it. None touched a file the PR changes.
  • git diff dce81ca40 1cb45255c | patch -p1 onto main applied clean: 20 files, no fuzz, no offset, no rejects, all byte-identical to the PR head.
  • npm ci, npm run build and npm run typecheck passed on Node 24.18.0. The 7 changed test files: 124 of 124 pass.
  • Control: the PR's test files went onto main's own source, with two support files. That gave 70 failures out of 124, and every file had failures. So the tests do exercise the change.
  • Since then main has moved. It was 39da0b1 at 19:54 UTC. Its commit f9ea9a9 changes four files that the PR also changes. I listed them with git diff --name-only. One is the process-capture guide. One is the tool contracts file. Two are the scenario source and its test.
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: 1cb4525 / dce81ca (old head from my first comment: 8a1600e)
  • Other: npm 11.16.0 (with Node 24.18.0), turbo 2.11.7, and other test runs shared the box and its /tmp

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: I ran the full test lanes on 1cb4525 on Linux. The PR causes no failures. Five tests in other areas fail on this box, and they fail the same way on the base dce81ca.

Lane, Node 24.18.0 Result
test:fast 3,994 pass, 0 fail, 4 skipped (after a build; see below)
test:boundary 2,848 pass, 7 fail, 82 skipped
test:acceptance 142 pass, 0 fail, 3 skipped
docs:check pass
npm run check pass (0 lint errors)

All the tests this PR touches pass, including processFinalization.test.ts (11 tests).

The 7 boundary failures are 5 test cases in 5 files. None of these files is in the PR. I reran each file alone on the head and on a fresh base tree, and each gave the same result on both:

  • cdpCleanupCancellation.test.ts (2 tests)
  • evmoleInterfaceProvider.test.ts (1)
  • firmwareIntegration.test.ts (1)
  • qwenClientConfiguration.test.ts (2)
  • referenceSourceReader.test.ts (1)

I did not look into why they fail here. It may be this box.

The first test:fast run had one failure: realHopperSemantic.test.ts could not load before dist/ existed. After a build it passes 4 of 4, on the head and on the base.

Still not run

  • Windows and macOS.
  • The PR merged into current main, which now conflicts. Ran on 0aea0d1, see below.
  • Repeat runs of the failing files, so flakiness is not ruled out. Each failing file ran twice more. Head and main matched.

Edit: The lanes on the merged head 0aea0d1 are in my new comment. The PR causes no failures there.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 24.18.0
  • Head: 1cb4525
  • Base: dce81ca
  • Other: no Ghidra, JDK or Chromium paths were set. The skips in these lanes are for macOS, Windows and other host checks, not those tools. Other jobs shared the box (load 1.3 to 8.5 out of 24 threads).

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I ran the full test lanes on the merged head 0aea0d1 on Linux. The PR causes no failures. Two boundary tests fail, and both fail the same way on main 0fa0b04.

The merge brought main 0fa0b04 into the PR branch. GitHub now reports the PR as mergeable. I compared the PR's own changes before and after the merge. Two files differ, and both are conflict fixes.

  • The tool description keeps both texts. One is main's terminal-cell text. One is the PR's finalization text.
  • processScenario.test.ts has merged imports.
Lane, Node 24.18.0 Result
test:fast 4,018 pass, 0 fail, 3 skipped
test:boundary 2,901 pass, 2 fail, 83 skipped
test:acceptance 142 pass, 0 fail, 3 skipped
docs:check pass
npm run check pass (0 lint errors, 640 warnings)

The counts are higher than in my earlier comment because the tree now includes main 0fa0b04. This time I built first, so realHopperSemantic.test.ts loaded.

All the tests this PR touches pass, including processFinalization.test.ts (11 tests). I also ran them alone: 85 in test:fast, 31 in test:boundary and 11 in test:acceptance.

The 2 boundary failures are in 2 files. None of these files is in the PR. I ran each file alone twice on the head and twice on a fresh build of main 0fa0b04. Each run gave the same result on both:

Of the five files that failed last time, four now pass, on the head and on main alone: cdpCleanupCancellation.test.ts, evmoleInterfaceProvider.test.ts, firmwareIntegration.test.ts and qwenClientConfiguration.test.ts. Main changed all four test files after dce81ca. I did not check whether that is why they pass now.

Still not run

  • Windows and macOS.
  • Why referenceSourceReader.test.ts fails on main. I only read the error text.
  • Main has moved on since 0fa0b04 (it is now 926c2d6). I did not test that.
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 24.18.0 (npm 11.16.0)
  • Head: 0aea0d1
  • Main: 0fa0b04
  • Other: I set no Ghidra, JDK or Chromium paths. The unpacked tree had no .git folder, so the first npm run check stopped in the module-boundary script. It passed after git init in that folder. Load average (threads running or waiting, out of 24) ran from 1.3 to 5.1 across the lanes.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thanks for the finalization work. Independent Linux verification of 0aea0d17 passed all 127 focused cases, including the compiled CLI/MCP cooperative, non-zero exit, forced escalation and cancellation workflows. I approved the waiting workflows; CI currently has a failed source shard that I am investigating.

One ownership gap remains before retaining the first start identity: observeProcessStartIdentity can adopt a replacement PID's identity without checking the captured run token. Three representative OS-observation regressions fail on this head (foreign run token, unreadable token and identity change during the token read). They do not manufacture real OS PID reuse or signal a foreign process. I am adding a narrow follow-up that binds this initial identity to the run token, preserves the unavailable reason, and keeps ordinary attached-PID readers unchanged. I will preserve your commits, integrate current main and rerun the actual capture workflows before final CI/merge.

@N0zoM1z0 N0zoM1z0 added area: cli CLI adapter and one-shot commands area: domain Domain logic, errors, and pure functions area: mcp MCP server, transport, and tool registration area: tests Test suite and verification enhancement New feature or request labels Oct 11, 2026
@N0zoM1z0

N0zoM1z0 commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Final reviewed head is e980e6b0, with frozen main 29cc1b87 integrated and the contributor history preserved. Main's #1664 also fixes the three Electron fixture conflicts; those files are outside this PR's final diff.

Linux validation passed all 250 cases in 13 focused files, including real compiled CLI/MCP finalization, cancellation, file-hash omissions, detached owned cleanup, and adjacent Electron workflows. Static checks, build and docs passed. Test discovery previously found all 796 files exactly once; no test files were subsequently added or removed. Initial ownership-binding regressions use representative OS observations, without manufacturing PID reuse or signaling foreign processes.

Additional acceptance validators compile when a tool is used; the complete advertised schemas and normal SDK call path remain validated. One identical-runtime before/after pair reduced connection plus first call from 13.65 s to 6.44 s. This is a test-client measurement; upstream SDK #2997 remains open. All 12 finalization acceptance cases passed the earlier integrated CI with existing deadlines.

Merged as c1efa646 after all 31 final-head CI checks succeeded. Windows capture remains unsupported; no new Windows capture claim is made.

# Conflicts:
#	src/application/javascript/JavaScriptArtifactPathResolution.test.ts
#	tests/acceptance/applications/electronPreloadOverridesCli.test.ts
#	tests/composition/javascript-applications/electronOptionKeys.test.ts
@N0zoM1z0
N0zoM1z0 merged commit c1efa64 into morluto:main Oct 11, 2026
31 checks passed
@morluto morluto added the area: runtime Process capture and runtime observation label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands area: domain Domain logic, errors, and pure functions area: mcp MCP server, transport, and tool registration area: runtime Process capture and runtime observation area: tests Test suite and verification enhancement New feature or request

Projects

None yet

4 participants