Skip to content

fix(clawhub): prevent failed archive staging from leaking temporary files - #127065

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-179-clawhub-cleanup
Aug 21, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-179-clawhub-cleanup

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #127057

AI-assisted: Codex; the implementation and evidence were independently reviewed.

What Problem This Solves

Fixes an issue where users installing ClawHub plugins or skills would retain a private temporary directory and partially written archive when staging failed with a filesystem error such as ENOSPC before the caller received a cleanup handle. ClawPack packages, legacy package archives, versioned skills, resolver-backed skills, and GitHub-backed skills were all affected. The defect is also present in stable v2026.7.1 under the earlier src/infra/clawhub.ts owner.

Why This Change Was Made

One private archive-staging owner now allocates the existing temporary target, writes and constructs the unchanged download result while it still owns cleanup, and performs best-effort identity-checked workspace cleanup before rethrowing the exact original failure. Successful downloads continue transferring the existing cleanup handle to their callers; their filenames, bytes, SHA-256 integrity values, and all ClawPack SHA-512/SHA-1/header metadata are unchanged. ClawPack reuses its already-validated SHA-256 digest, and ordinary archives hash their bytes once through the existing shared helper before deriving both integrity representations.

Rejected alternatives: caller-side cleanup cannot work because failed acquisition never returns a target; five independent try/catch blocks preserve the duplicate lifecycle bug surface; unlinking a pathname directly could delete a replacement path and would bypass the existing workspace identity contract.

User Impact

Failed ClawHub plugin and skill downloads release their own partially staged archive and temporary directory immediately, keep unrelated files and replacement paths intact, and still report the original filesystem error. Successful installs, preflight behavior, verification metadata, public result shapes, and caller-owned cleanup remain unchanged.

Evidence

  • Exact reviewed head: 4b48c0b2786b0a17d28bdebb156c192462a7fd60.
  • Before the fix, the actual acquisition-owner suite passed its 17 existing cases and failed all five new real-filesystem partial-write regressions because workspace cleanup was called zero times.
  • After the fix, the focused owner suite passes all 30 cases, including five exact-identity ENOSPC failures, five complete success/result/cleanup contracts, preservation of a renamed-workspace replacement, and cleanup/logger-failure error precedence.
  • Owner, existing temporary-download boundary, ClawHub client/package/skill siblings, plugin install, and skill install/preflight: seven files, five Vitest shards, 286 tests passed.
  • Direct inspection and disposable-files proof establish the locked and installed @openclaw/[email protected] cleanup outcomes: removed, missing, and identity-mismatch; a preexisting replacement marker and unrelated sibling survive. The identity check is not claimed to be atomic against a replacement during the cleanup call.
  • node scripts/check-changed.mjs -- src/infra/clawhub-artifacts.ts src/infra/clawhub-artifacts.test.ts, targeted oxfmt --check, and git diff --check pass.
  • Fresh uncommitted Codex autoreview: clean, no actionable findings; independent adversarial owner/dependency/caller review: clean.
  • Production: +47/-60 (net -13); tests: +202/-4 (net +198). No new file, dependency, exported helper, Plugin SDK change, config surface, persistence change, install-flow change, or CHANGELOG.md edit.
  • All requests use synthetic responses and real disposable files. No live ClawHub service, real install, external archive request, or operator state was accessed; live installation is intentionally out of scope.
OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/tmp/openclaw-autoqa-179-vitest-cache node scripts/run-vitest.mjs run --config test/vitest/vitest.infra.config.ts --configLoader runner src/infra/clawhub-artifacts.test.ts
OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/tmp/openclaw-autoqa-179-vitest-cache node scripts/run-vitest.mjs src/infra/clawhub-artifacts.test.ts src/infra/clawhub-client.test.ts src/infra/clawhub-packages.test.ts src/infra/clawhub-skills.test.ts src/plugin-sdk/temp-path.test.ts src/plugins/clawhub.test.ts src/skills/lifecycle/clawhub.test.ts --configLoader runner
node scripts/check-changed.mjs -- src/infra/clawhub-artifacts.ts src/infra/clawhub-artifacts.test.ts
node_modules/.bin/oxfmt --check src/infra/clawhub-artifacts.ts src/infra/clawhub-artifacts.test.ts
git diff --check

@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 21, 2026
@steipete
steipete marked this pull request as ready for review August 21, 2026 06:44
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head 4b48c0b2786b0a17d28bdebb156c192462a7fd60.

The actual acquisition owner reproduced all five pre-fix partial-write leaks: its 17 existing cases passed, while each new ClawPack/package/skill/resolver/GitHub ENOSPC case failed because workspace cleanup was never called. The repaired owner suite now passes 30 cases, including exact original-error identity, five success-result/cleanup contracts, replacement-path preservation, and cleanup/logger error precedence. Seven owner/sibling/caller suites pass 286 tests. The complete changed-file gate, formatter, dead-export analysis, core/core-test typechecks, changed-file type-aware lint, and git diff --check are green.

Direct docs, types, installed distribution, immutable lock, and disposable-filesystem proof verify @openclaw/[email protected]: owned cleanup returns removed, absent workspace returns missing, and a renamed workspace plus replacement returns identity-mismatch while preserving its replacement marker. The check is identity-bound but is not claimed atomic against a same-call replacement race. Cleanup or logger failures cannot replace the original acquisition failure.

Fresh mandatory Codex autoreview and the independent adversarial review of this exact committed head both report zero findings. Native exact-head review artifacts validate as READY FOR /prepare-pr with zero findings. Production is +47/-60 (net -13); tests are +202/-4 (net +198). No public API, installation flow, dependency, configuration, persistence, Plugin SDK, security surface, changelog, or archive integrity value changed.

Exact-head required CI is green: https://github.com/openclaw/openclaw/actions/runs/32455625580. CodeQL is green: https://github.com/openclaw/openclaw/actions/runs/32455625560. Dependency Guard is green: https://github.com/openclaw/openclaw/actions/runs/32455625614.

ClawSweeper's latest exact-head comment currently reports review started only; it contains no findings and no Rank-up moves:. Repository policy treats a queued or late review as non-blocking, so there are no actionable moves to apply or skip. All acquisition responses were synthetic and all filesystem paths disposable; no live ClawHub services, real installs, or operator state were accessed.

@steipete
steipete merged commit c021295 into main Aug 21, 2026
292 checks passed
@steipete
steipete deleted the codex/autoqa-179-clawhub-cleanup branch August 21, 2026 06:57
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClawHub downloads retain temporary archives when staging writes fail

1 participant