Skip to content

Clean up interrupted JavaScript dependency downloads - #387

Merged
BenCodez merged 4 commits into
masterfrom
fix/javascript-download-cleanup
Nov 24, 2026
Merged

BenCodez merged 4 commits into
masterfrom
fix/javascript-download-cleanup

Conversation

@BenCodez

@BenCodez BenCodez commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

An interrupted optional JavaScript dependency download could leave its temporary file behind. Give each attempt a unique sibling candidate, clean up only that attempt's candidate, close streams and disconnect on failure, and preserve the original failure with cleanup failures suppressed.

The follow-up closes an unpublished class loader if engine factory creation fails, while retaining the previous published loader until a replacement is ready. A managed cached dependency whose archive structure cannot be read can be repaired through a validated candidate. Before publication, recheck the destination and preserve a competing readable archive; replacement of an existing unreadable archive requires atomic filesystem replacement, and unsupported atomic publication retains the prior bytes.

Readable manually supplied archives remain supported. No version or trust policy, unowned temporary-file purge, async readiness contract, cross-handler single-flight or privileged script capability is changed. The final destination check does not serialize unrelated filesystem writers acting after that check.

Validation at exact source a1e45afff016d86782ada14e6d97a6f1dda37a5c: 69 focused JavaScript tests passed; a clean JDK 21 package passed 1,747 ordinary tests and two artifact checks, with zero failures, errors or skips. Independent read-only source review approved this exact snapshot and independently passed 69 focused tests. Earlier loader-failure and publication-race regressions failed on their respective baselines and passed on the corrected source. Build receipts bind the source, dependencies, tools and packaged classes. These are local component/package results; hosted current-head checks and affected downstream/native acceptance are recorded separately.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of JavaScript dependency downloads. Interrupted, cancelled, failed, or empty transfers no longer leave partial artifacts in place or overwrite a previously available file.
    • Temporary download files are cleaned up after failures, and existing artifacts remain intact when a replacement cannot be completed. Connections are also closed when downloads finish or fail.
    • Invalid cached JavaScript archives can be recovered when downloads are enabled, while valid cached archives are preserved.
    • Failed JavaScript engine loads now clean up resources without replacing the previously available loader.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The handler validates cached and downloaded JAR archives, stages downloads before atomic publication, and cleans up failed candidates. It also closes candidate class loaders when engine creation fails. New tests cover archive recovery, transfer handling, and loader ownership.

Changes: JavaScript dependency handling

Layer / File(s) Summary
Cached archive validation and recovery
AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java, AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/javascript/JavascriptCacheArchiveRecoveryTest.java
The handler reuses readable regular JAR files and sends unreadable regular files to the download path. Tests cover recovery, preservation of valid caches, concurrent publication, and unsupported atomic replacement.
Staged download and publication
AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java, AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/javascript/JavascriptDependencyDownloadTest.java
downloadArtifact writes to a temporary file, rejects empty or unreadable archives and interrupted transfers, and requires an atomic move. Tests cover transfer and write failures, cleanup, target preservation, and connection closure.
Engine loader ownership
AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java, AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/javascript/JavascriptLoaderOwnershipTest.java
The handler retains a candidate class loader after successful engine creation and closes it after failed loading. Tests cover constructor and factory failures, a missing factory method, and successful loading.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Merge Risk: Minimal · up to a1e45

The change cleans up interrupted JavaScript dependency downloads and closes unpublished loaders. No actionable merge-blocking risk remains. A narrow, low-impact cache-publication race remains theoretical.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Clean up interrupted JavaScript dependency downloads" matches the main change. The PR adds cleanup of temporary candidate files when Nashorn JAR downloads are interrupted or fail, and the o…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "Clean up interrupted JavaScript dependency downloads" matches the main change. The PR adds cleanup of temporary candidate files when Nashorn JAR downloads are interrupted or fail, and the objectives state this as the primary goal. The title is concise, specific, and names the affected area. The changeset also covers cache archive validation and loader ownership, which the title does not mention, but the title does not need to cover every detail.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@BenCodez
BenCodez marked this pull request as ready for review November 22, 2026 21:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T21:41:35.576471Z a1e45af Draft marked ready
🔒 Security Review ✅ Completed 2026-11-22T21:43:26.582952Z a1e45af Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BenCodez
BenCodez merged commit 04a0eb9 into master Nov 24, 2026
6 checks passed
@BenCodez
BenCodez deleted the fix/javascript-download-cleanup branch November 24, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants