Fix orphaned temp runtime cleanup - #2089
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
doctorandcleanupFixes #2086
Root cause
wp-codebox doctorandwp-codebox cleanuponly inspected recipe-run process names and ZIP archive roots. Runtime producers usemkdtemp()under the effectiveTMPDIR, so abandoned Playground sites, release/package staging, overlays, read-only mounts, and other runtime directories were outside the cleanup lifecycle.Ownership and liveness evidence
Ownership is restricted to direct, non-symlink directory children of the canonical effective temp root on the same filesystem. WP Codebox producers use an explicit registry of exact prefixes found in the runtime creation code; upstream
node-playground-cli-site-*directories additionally require a WordPress filesystem layout. ArbitraryTMPDIRcontent and unknownwp-codebox-*names are not selected.Candidates are retained when their newest filesystem activity is younger than the stale threshold, a live process command/cwd/file descriptor references them, any WP Codebox recipe/agent/held-preview process is active, an active preview lease exists in a checked registry, or a run registry heartbeat is recent. Removal rechecks canonical containment and the original device/inode immediately before recursive deletion.
Structured contract
Before,
wp-codebox/doctor/v1contained process and archive checks but no temp-runtime accounting. After, thewp-codebox.temp-runtimecheck includes:tempRoot,scannedCount, andownedCountcandidateCount,retainedCount, andretainedReasonsestimatedAllocatedBytesandreclaimedAllocatedBytes--run-registryis repeatable for doctor/cleanup,WP_CODEBOX_RUN_REGISTRY_ROOTScan provide additional registries, and./artifacts/runsremains the default registry evidence root.Safety boundaries
wp-codebox-*globTests
npm run test:temp-runtime-cleanup- passednpm run build- passednpx tsx scripts/doctor-command-smoke.ts- passed with isolated customTMPDIRFocused coverage includes live process protection, age protection, active lease and recent-run protection, stale orphan removal, idempotency, custom
TMPDIR, structured allocated/reclaimed byte reporting, and unrelated-directory preservation.Residual risks
The producer registry must be updated when WP Codebox introduces a new temp-directory prefix. Externally owned wrappers and test harness directories are intentionally not inferred from names or removed; they need their owning layer's lifecycle contract. Non-Linux hosts do not expose
/procprocess path references, so cleanup relies on age and registry evidence there and remains conservative for recognized active runtime command lines where available.