Post-spawn cleanup
Use this knowledge-style utility in the existing creator or orchestrating caller context. It adds operating knowledge to the existing resource-lifecycle policy; it does not transfer ownership, authorize a new process sweep, or require a cleanup agent. Keep the main task moving wherever a particular resource hold does not affect it.
Select the existing owner and supported control
Bind the launch/run or child context to the selected resources and the caller's existing authority. Prefer creator-retained process/Job handles and a supported exact-context release API. Discover current capabilities and inspect the selected API's actual teardown semantics. Completion, interruption or unsubscribing can end work or notifications without releasing a process; a name or successful return alone proves no physical teardown.
Reuse the working owner/helper and its results. A defective assistant permits declared same-owner execution only with the same selection, identity, evidence, rollback where applicable, bounded cancellation and resource guarantees. A genuine host-policy refusal stops that operation: do not retry through another shell, provider or command shape. Missing ownership or teardown evidence holds that resource action, not unrelated delivery. Name the missing datum and its owner/next action; preserve shared, borrowed and unknown resources.
An existing process supervisor owns only resources it actually created. Reuse its Job/process lifecycle and receipt for those resources; its success does not establish ownership of provider-native Model Context Protocol (MCP) servers.
Settle without enlarging the selection
- Preserve actual substantive results and terminal outcomes before formatting or analysis can fail. Retain acquired failed/partial outcomes incrementally through the existing supported result or task artifact. Complete required settlement even if interpretation or persistence later fails; disclose unavailable evidence.
- Establish the selected child's terminal state, including any active follow-up, before releasing its context resources. For live cancellation, use its supported creator-owned cancellation path and retain the actual pending identity until it settles. Do not terminate a still-running child merely because a prior turn completed.
- Use sufficient existing creator/public ownership evidence directly. Do not start an unused tool to manufacture a cleanup target. If an authorized self-probe is necessary for an existing selected endpoint, it may itself start resources: retain available pre-probe evidence and distinguish probe-created resources from proven pre-existing ones. Unknown prior existence is not a cleanup saving.
- Revalidate the current object and hold its supported stable handle before a destructive action. Bind it to the exact selected context and creation identity where exposed. Process identifier (PID), parent PID, name, age, time window or ancestry alone is insufficient. A stale/exited selection needs no kill; a reused PID identifies a different object and must be preserved. Protect the active orchestrator, editor and shared/unselected services; never use parent, process-group or name-wide termination as a substitute.
- Prefer an effective supported graceful release. Where existing authority permits identity-bound termination, act only through the retained selected object and the caller's accepted budget/cancellation contract. A missing budget is not permission to invent an arbitrary timeout or retry loop. Record refusal, timeout, cancellation and partial settlement truthfully.
- Independently verify the original selected object exited or its identity is absent, then verify required protected identities remain intact. A termination request's return is not that oracle. Dispose every retained handle, including protection handles, on success and every failure exit. Do not claim selected resources clean while their teardown or handles remain live or unknown.
On Windows, load the conditional native-MCP method only when the selected endpoint, available public self-observation and native process capabilities fit. Other platforms and sufficient creator-bound release APIs do not require that method, Node, Python or an added dependency.
Return a scoped outcome through the current sink
Record the actual context/resource binding, selection, action and result; independent identity/protection readback; handle settlement; remaining unknowns; and any probe-created resource caveat in the current tool result, existing task artifact or Root's existing ledger/status flow. Do not introduce a registry or mandatory duplicate report. Distinguish selected-resource settlement from whole-host or all-MCP cleanliness, and actual observations from requested model/provider settings.
For file/evidence/trash disposition, follow the applicable shared artifact-disposition and repository-cleanup owner. File cleanup does not prove a live process settled; this skill does not duplicate or reopen that separate policy.
Terms and Abbreviations
MCP: Model Context Protocol. PID: process identifier. Job: operating-system resource group owned by its creator. Root: the current orchestrating caller. Stable handle: retained reference to the selected native object, not a later lookup by PID.