Practical technical guides / Recent development / Claude Code v2.1.326

A Reused Process ID Must Not Authorize Worker Cleanup

Separate a numeric process locator from an owned process incarnation and demonstrate a safe refusal after reuse.

By Sandeep Belgavi · Published 2026-11-25 · Prepared 2026-11-17

A locator is not an incarnation: Remembered PID, then Owned process identity, then Bound cleanup action
Original explanatory diagram by Sandeep Belgavi. Conceptual sequence; no measured performance is represented.

Separate a numeric process locator from an owned process incarnation and demonstrate a safe refusal after reuse.

A remembered process number can point somewhere else

A background worker records the numeric identifier of a child process. The child exits, the operating system later reuses that number, and cleanup runs against the old record. If the supervisor treats the number as permanent identity, it can target a different process. The failure is especially plausible after a restart, when a persisted list of worker identifiers outlives the processes that originally created it.

Claude Code v2.1.326, released on 16 November 2026 UTC, includes a fix concerning background-service cleanup after process-number reuse. The release notes were read on 17 November in Asia/Kolkata. They establish the reported behavior change, not its internal implementation or a benchmark. This guide develops an original synthetic identity model to explain the general supervisor design issue without terminating any process.

The underlying distinction is between a locator and an incarnation. A PID locates a current operating-system process. It does not, by itself, prove that this is the process a supervisor started earlier. Cleanup authority should refer to an owned incarnation with a defined lifecycle, and the actual termination mechanism should preserve that identity across the check-to-action boundary.

Model ownership independently of liveness

A live process is not necessarily your process. A matching numeric identifier is not sufficient, and a familiar command name is not sufficient either: several unrelated processes can run the same executable. A supervisor needs an ownership record established when it launches the child, plus a way to determine whether a later observation still refers to that incarnation.

An ownership record may include the PID, a start identity, the supervisor's generation and a platform-supported process handle. The exact fields and guarantees depend on the operating system and runtime. A timestamp with low resolution may be insufficient for a strong identity claim, and process metadata may be unavailable. Missing evidence should produce an explicit refusal or reconciliation state rather than an optimistic assumption that the old process is still present.

Java's ProcessHandle documentation warns that process state changes asynchronously and that PID reuse creates race conditions. It also documents implementation-dependent identity details. Those cautions matter when designing a portable abstraction: wrapping a number in an object does not automatically give every platform the same durable, race-free process identity guarantee. Verify the native semantics used by the actual supervisor.

Reproduce the reuse error without controlling processes

The following original fixture uses records only. The incarnation string is a synthetic identity assigned by the test, not a real operating-system field. The function returns an advisory decision and never sends a signal or invokes a process-control API. This makes the dangerous mismatch easy to test while keeping the demonstration independent of the reader's running applications.

# Author: Sandeep Belgavi. Synthetic process ownership decision only.
from dataclasses import dataclass

@dataclass(frozen=True)
class ProcessRecord:
    pid: int
    incarnation: str | None
    owner_generation: str

def cleanup_decision(owned, observed, generation):
    if owned.owner_generation != generation:
        return "reconcile-supervisor-generation"
    if observed is None:
        return "already-gone"
    if owned.incarnation is None or observed.incarnation is None:
        return "refuse-unknown-identity"
    if (owned.pid, owned.incarnation) != (observed.pid, observed.incarnation):
        return "refuse-different-process"
    if observed.owner_generation != generation:
        return "refuse-unowned-process"
    return "eligible-for-bound-handle-cleanup"

owned = ProcessRecord(42, "birth-a", "supervisor-7")
replacement = ProcessRecord(42, "birth-b", "unrelated")
assert cleanup_decision(owned, replacement, "supervisor-7") == "refuse-different-process"
assert cleanup_decision(owned, None, "supervisor-7") == "already-gone"

The key expected outcome is refusal when the PID matches but the incarnation differs. A PID-only implementation would treat the replacement as eligible. The model also distinguishes a process that is already absent from a process whose identity cannot be established. Those outcomes need different operational handling; absence can complete cleanup, while unknown identity requires a safe unresolved state.

Do not turn a metadata check into a race-free claim

Even a correct comparison can be followed by an unsafe action. Suppose the supervisor reads metadata, confirms the expected incarnation, then issues termination using only the numeric PID. The process can exit and the PID can be reused between those operations. The comparison reduced one risk but did not bind the action to the checked object. This is the classic check-to-use gap in a process-control setting.

A real implementation should retain and use an appropriate native handle or another platform mechanism whose semantics bind the operation to the intended process. Where that guarantee is unavailable, document the limitation and choose a conservative policy. Do not present the synthetic comparison above as a complete process-killing routine. Its final status deliberately says eligible for bound-handle cleanup rather than claiming cleanup happened.

The same caution applies to process trees. Enumerating descendants produces a snapshot, while children can exit or spawn new children. Ownership may also cross supervisor boundaries if a child detaches. Define which processes the supervisor owns and how that ownership ends. A recursive list of numeric PIDs is not a durable authorization to terminate every future process that happens to reuse those numbers.

Make restart recovery explicit

On restart, give the supervisor a new generation and reconcile persisted child records before acting. Some records will refer to exited processes; others may refer to surviving children whose ownership can be re-established through the runtime's supported mechanism. Do not silently treat an old generation's registry as a current in-memory handle table. Persistence preserves bytes, not necessarily the validity of the resource identities those bytes describe.

Keep cleanup idempotent at the level of the owned process lifecycle. Repeating a cleanup request for an already-terminated incarnation should converge on an already-gone result. It should not search for a new process with the same PID and begin a new termination attempt. The completion record should identify the incarnation that was reconciled so a subsequent retry cannot reinterpret the outcome.

Separate graceful shutdown, forced shutdown and observation. A successful request to terminate is not always proof that the process has exited. Wait for the appropriate completion signal or report a pending state. If escalation is allowed, apply it to the same bound process identity under a bounded policy. Avoid escalating merely because a numeric locator still returns some live process.

Test ownership failures before adding real signals

Offline tests should cover same PID with a different incarnation, missing incarnation metadata, a different supervisor generation, a process that is already gone and an exact owned match. Assert that only the exact owned match reaches the adapter eligibility state. Add a test that the advisory function has no side effects, so a model-level test cannot accidentally control the host's processes.

Integration tests belong in an isolated environment with child processes created specifically by the test. They should retain the real launch handles, request cleanup, observe exit and verify that unrelated test processes survive. Do not rely on forcing actual PID reuse on a shared workstation. A fake platform adapter can deterministically inject reuse between observation and action to test whether the supervisor incorrectly falls back to a number.

Record the native platform and runtime in integration evidence. A passing test on one operating system does not prove the same handle guarantees elsewhere. The release note that motivated this guide is not evidence that the original fixture reproduces the exact vendor bug. It is a timely reason to examine a well-defined class of ownership error in one's own supervisor.

Migrate from a PID list to an ownership registry

Start by locating persisted PID lists and cleanup code that reacquires processes from those numbers. Add lifecycle records at launch, preserve the platform's stronger identity where available, and make restart reconciliation a first-class operation. Audit every fallback path; a careful handle-based design can still fail if an error handler reverts to a numeric kill command without the same ownership checks.

Expose unresolved cleanup separately from task failure. Operators need to know whether work failed, whether its process exited and whether the supervisor could establish ownership. Those are different facts. An agent may summarize the registry, but it should not infer permission to terminate a process from its command name or from an old conversation about a worker. Deterministic ownership and platform-bound actions should control cleanup.

The practical result is a narrower promise: the supervisor cleans up processes it can still identify as its own. Refusing an ambiguous cleanup may leave work to reconcile, but it preserves the boundary between a remembered locator and actual control over a live resource. That boundary is what a PID-only registry lacks.

Run the example yourself

The synthetic fixtures, expected output and tests behind this guide are in the companion code on GitHub; its README lists the prerequisites, exact commands, expected output and limits.

Primary references and authorship

Sources read 17 November 2026. Original explanation and synthetic examples by Sandeep Belgavi. Views are my own and do not represent any employer, past or present.