Skip to content

[Improve] Strengthen managed binary installation - #1059

Open
navedmerchant wants to merge 6 commits into
mainfrom
feat/managed-binary-infrastructure
Open

[Improve] Strengthen managed binary installation#1059
navedmerchant wants to merge 6 commits into
mainfrom
feat/managed-binary-infrastructure

Conversation

@navedmerchant

@navedmerchant navedmerchant commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What changed

Adds tighter managed-binary safeguards: bounded Semble downloads, stricter archive layout validation, stream cleanup on download failures, and regression coverage for successful verification and installation cleanup.

Why this change was made

The shared installer underpins the DCG rollout and must reject malformed archives or unbounded downloads without leaving partial files or open connections. Closes #1055.

Impact

Binary-backed services install more safely and consistently without changing Semble's user-facing workflow.

Related PRs

@navedmerchant navedmerchant added the enhancement New feature or request label Jul 30, 2026
@navedmerchant navedmerchant self-assigned this Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Shared managed-binary utilities now handle secure downloads, checksum verification, archive extraction, versioned atomic installation, cleanup, and concurrent installation control. The Semble downloader delegates to these utilities, and related tests and ESLint configuration were updated.

Changes

Managed binary infrastructure

Layer / File(s) Summary
Secure download and checksum utilities
src/services/managed-binary/download.ts, src/services/managed-binary/__tests__/download.spec.ts
Adds trusted HTTPS downloads with redirect validation, size limits, timeouts, exclusive writes, and streaming SHA-256 verification.
Archive extraction and layout validation
src/services/managed-binary/archive.ts, src/services/managed-binary/__tests__/archive.spec.ts
Adds process execution and platform-specific archive extraction with hardened tar options and single-file archive validation.
Versioned atomic installation
src/services/managed-binary/install.ts, src/services/managed-binary/__tests__/install.spec.ts
Adds staged installation, version tracking, executable handling, stale-archive cleanup, atomic promotion, validation, filesystem locking, and concurrent-install de-duplication.
Semble integration and regression coverage
src/services/code-index/semble/semble-downloader.ts, src/services/code-index/semble/__tests__/semble-downloader.spec.ts, src/eslint-suppressions.json
Migrates Semble to managed-binary utilities and updates cleanup, staging, lock, and lint-suppression expectations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Semble as downloadSemble
  participant Installer as ensureManagedBinaryInstalled
  participant Downloader as downloadBinaryFile
  participant Checksum as verifySha256Checksum
  participant Extractor as extractTarGzArchive
  Semble->>Installer: provide version and lifecycle callbacks
  Installer->>Downloader: download trusted archive
  Installer->>Checksum: verify archive checksum
  Installer->>Extractor: extract into staging directory
  Installer-->>Semble: return installed binary path
Loading

Possibly related PRs

Suggested labels: awaiting-review

Suggested reviewers: taltas

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the purpose and scope and links issue #1055, but it omits the required test procedure and pre-submission checklist. Add the template sections for test procedure, checklist, documentation updates, and any relevant reviewer notes.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement reusable download, checksum, extraction, and atomic installation helpers, migrate Semble, and add focused regression tests for [#1055].
Out of Scope Changes check ✅ Passed The code changes remain within the linked issue scope and do not add DCG-specific metadata, execution, settings, or UI changes.
Title check ✅ Passed The title clearly summarizes the pull request's main change: strengthening managed binary installation.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/managed-binary-infrastructure

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

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
src/services/managed-binary/archive.ts (1)

55-87: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Avoid constructing PowerShell scripts with string interpolation.

These extraction paths still interpolate user-controlled paths and archive names into PowerShell commands before shell escaping. Use PowerShell parameterized execution instead: pass values via -ArgumentList with a -File script, or build the command as script text and run it via -EncodedCommand so the values are not quoted into the command literal.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/managed-binary/archive.ts` around lines 55 - 87, Update
extractZipArchive and extractSingleFileZipArchive to stop interpolating archive
paths, destinations, expectedFile, or archiveName into PowerShell script text.
Pass these values as PowerShell parameters via -ArgumentList with a -File script
or an equivalent EncodedCommand approach, while preserving the existing
extraction and archive-layout validation behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/code-index/semble/__tests__/semble-downloader.spec.ts`:
- Around line 707-723: Replace the stale fs.unlink assertion in the upgrade
cleanup test with an assertion against fs.rm, verifying the unrelated file path
is not removed while preserving the existing force-option expectations for
intended archives.

In `@src/services/managed-binary/__tests__/archive.spec.ts`:
- Around line 61-79: Update the test “validates a single-file tar.xz layout
before extraction” to assert that extraction passes the exact archive member
name returned by the listing, including the “./” prefix. Adjust the mocked
listing or expected tar arguments only as needed to verify the implementation
preserves the stored member name rather than stripping it.

In `@src/services/managed-binary/archive.ts`:
- Around line 89-105: Preserve the raw tar member name in
extractSingleFileTarXzArchive for the extraction command, while normalizing a
separate value by removing ./ for the single-entry layout comparison. Update the
archive.spec.ts test expectation so a ./binary listing results in extraction
targeting ./binary; apply the change in both specified files.

In `@src/services/managed-binary/download.ts`:
- Around line 120-144: Update the maxBytes error path in the response data
handler to explicitly destroy or close the output stream before rejecting,
alongside response.destroy() and request.destroy(). Preserve the existing
successful output.on("finish") flow and ensure the stream’s file descriptor is
released when assertSizeWithinLimit throws.

In `@src/services/managed-binary/install.ts`:
- Line 4: Add cross-process locking to ensureManagedBinaryInstalled in addition
to the in-memory installationPromises map, using an exclusive lock file under
storageDir to serialize attempts targeting the deterministic staging path.
Ensure lock acquisition, release, and stale/error cleanup are handled safely,
and keep each owner’s archive and staging writes isolated until successful
promotion.

---

Nitpick comments:
In `@src/services/managed-binary/archive.ts`:
- Around line 55-87: Update extractZipArchive and extractSingleFileZipArchive to
stop interpolating archive paths, destinations, expectedFile, or archiveName
into PowerShell script text. Pass these values as PowerShell parameters via
-ArgumentList with a -File script or an equivalent EncodedCommand approach,
while preserving the existing extraction and archive-layout validation behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1dfa2c7c-2e9f-416c-ba33-4eec94aae3ba

📥 Commits

Reviewing files that changed from the base of the PR and between c378193 and e93b1cc.

📒 Files selected for processing (9)
  • src/eslint-suppressions.json
  • src/services/code-index/semble/__tests__/semble-downloader.spec.ts
  • src/services/code-index/semble/semble-downloader.ts
  • src/services/managed-binary/__tests__/archive.spec.ts
  • src/services/managed-binary/__tests__/download.spec.ts
  • src/services/managed-binary/__tests__/install.spec.ts
  • src/services/managed-binary/archive.ts
  • src/services/managed-binary/download.ts
  • src/services/managed-binary/install.ts
💤 Files with no reviewable changes (1)
  • src/eslint-suppressions.json

Comment thread src/services/code-index/semble/__tests__/semble-downloader.spec.ts
Comment thread src/services/managed-binary/__tests__/archive.spec.ts
Comment thread src/services/managed-binary/archive.ts
Comment thread src/services/managed-binary/download.ts
Comment thread src/services/managed-binary/install.ts
@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 30, 2026

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Had a couple implementation comments.

Comment thread src/services/managed-binary/download.ts Outdated
Comment thread src/services/managed-binary/download.ts
Comment thread src/services/managed-binary/download.ts Outdated
Comment thread src/services/managed-binary/download.ts
Comment thread src/services/code-index/semble/semble-downloader.ts Outdated
Comment thread src/services/managed-binary/install.ts Outdated
Comment thread src/services/managed-binary/__tests__/install.spec.ts Outdated
Comment thread src/services/managed-binary/__tests__/install.spec.ts
Comment thread src/services/managed-binary/__tests__/archive.spec.ts
Comment thread src/services/managed-binary/__tests__/download.spec.ts
@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Jul 31, 2026
@github-actions github-actions Bot removed the awaiting-author PR is waiting for the author to address requested changes label Aug 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/managed-binary/__tests__/archive.spec.ts`:
- Around line 45-55: Wrap the fake-timer setup and test assertions in a
try/finally block within the “kills a process that exceeds its timeout” test,
and call vi.useRealTimers() in the finally block so timers are restored even
when an assertion fails.

In `@src/services/managed-binary/archive.ts`:
- Around line 109-116: Update the archive extraction flow around the TAR entry
validation and runProcess call to inspect entry types, accepting exactly one
regular file named expectedFile and rejecting symbolic links, hard links,
directories, and other non-regular entries. Apply the same ownership and
directory-overwrite protections already implemented by extractTarGzArchive
before extracting.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: dfecb8ff-1b98-44ef-af6f-4a38bc8f3e09

📥 Commits

Reviewing files that changed from the base of the PR and between e93b1cc and 24d527e.

📒 Files selected for processing (8)
  • src/services/code-index/semble/__tests__/semble-downloader.spec.ts
  • src/services/code-index/semble/semble-downloader.ts
  • src/services/managed-binary/__tests__/archive.spec.ts
  • src/services/managed-binary/__tests__/download.spec.ts
  • src/services/managed-binary/__tests__/install.spec.ts
  • src/services/managed-binary/archive.ts
  • src/services/managed-binary/download.ts
  • src/services/managed-binary/install.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/services/code-index/semble/tests/semble-downloader.spec.ts

Comment thread src/services/managed-binary/__tests__/archive.spec.ts Outdated
Comment thread src/services/managed-binary/archive.ts Outdated
@github-actions github-actions Bot added the awaiting-author PR is waiting for the author to address requested changes label Aug 1, 2026

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some questions about the implementation.

Comment thread src/services/managed-binary/download.ts
Comment thread src/services/managed-binary/download.ts
Comment thread src/services/managed-binary/__tests__/download.spec.ts
Comment thread src/services/managed-binary/__tests__/archive.spec.ts
Comment thread src/services/managed-binary/install.ts
Comment thread src/services/managed-binary/archive.ts
Comment thread src/services/managed-binary/__tests__/install.spec.ts
Comment thread src/services/code-index/semble/semble-downloader.ts
Comment thread src/services/code-index/semble/semble-downloader.ts
@github-actions github-actions Bot removed the awaiting-author PR is waiting for the author to address requested changes label Aug 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/services/managed-binary/archive.ts (2)

1-33: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Bound captured process output.

runProcess stores all stdout and stderr in memory. extractSingleFileTarXzArchive uses it to collect the complete tar -tvJf listing before checking the entry count. A highly compressed archive with many entries can exhaust memory before validation completes.

Add a byte limit and terminate the child when the limit is exceeded, or stream only enough output to detect more than one entry.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/managed-binary/archive.ts` around lines 1 - 33, Update
runProcess to bound captured stdout and stderr while preserving its
ProcessResult contract: track accumulated output bytes, terminate the child and
reject when the configured limit is exceeded, and clear the timeout during
cleanup. Ensure extractSingleFileTarXzArchive’s tar listing cannot accumulate
unbounded output before entry-count validation.

35-49: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Enforce one common archive-entry policy before generic extraction.

extractTarGzArchive and extractTarXzArchive pass TAR entries directly to tar, while extractZipArchive uses unzip/Expand-Archive. The current flags only affect ownership or directory replacement behavior; they do not validate member paths/types or prevent unsafe symlinks or traversal entries. Use a single safe-entry policy that validates every archive member before extraction for both generic extractors.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/managed-binary/archive.ts` around lines 35 - 49, Update
extractTarGzArchive and extractTarXzArchive to apply the same safe-entry
validation policy used by extractZipArchive before generic extraction. Validate
every member’s path and type, rejecting traversal entries and unsafe symlinks,
then extract only validated entries while preserving the existing TAR options
and platform-specific flags.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/managed-binary/archive.ts`:
- Around line 112-123: In the archive extraction logic around archiveEntry and
entryName, separate the entries.length validation from parsing and validate
archiveEntry and entryName before calling startsWith, replace, or appending
entryName to args. Ensure the checks narrow both values to strings before the
existing layout error and runProcess("tar", args) flow.

In `@src/services/managed-binary/download.ts`:
- Around line 147-150: Update the download completion handling around the output
stream’s finish/close listeners so the promise resolves only from the close
event after output.close() completes; adjust the success test to emit close
after finish and verify completion remains gated on close.

---

Outside diff comments:
In `@src/services/managed-binary/archive.ts`:
- Around line 1-33: Update runProcess to bound captured stdout and stderr while
preserving its ProcessResult contract: track accumulated output bytes, terminate
the child and reject when the configured limit is exceeded, and clear the
timeout during cleanup. Ensure extractSingleFileTarXzArchive’s tar listing
cannot accumulate unbounded output before entry-count validation.
- Around line 35-49: Update extractTarGzArchive and extractTarXzArchive to apply
the same safe-entry validation policy used by extractZipArchive before generic
extraction. Validate every member’s path and type, rejecting traversal entries
and unsafe symlinks, then extract only validated entries while preserving the
existing TAR options and platform-specific flags.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fba919fe-d390-4c80-8ef6-3b8d9ec50684

📥 Commits

Reviewing files that changed from the base of the PR and between 24d527e and 28d81f9.

📒 Files selected for processing (7)
  • src/services/code-index/semble/semble-downloader.ts
  • src/services/managed-binary/__tests__/archive.spec.ts
  • src/services/managed-binary/__tests__/download.spec.ts
  • src/services/managed-binary/__tests__/install.spec.ts
  • src/services/managed-binary/archive.ts
  • src/services/managed-binary/download.ts
  • src/services/managed-binary/install.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/services/managed-binary/tests/download.spec.ts
  • src/services/managed-binary/tests/archive.spec.ts
  • src/services/managed-binary/install.ts

Comment thread src/services/managed-binary/archive.ts
Comment thread src/services/managed-binary/download.ts Outdated
@zoomote zoomote Bot changed the title [Refactor] Extract managed-binary installation infrastructure [Improve] Strengthen managed binary installation Aug 2, 2026
@zoomote

zoomote Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Addressed all current unresolved review feedback in ae26434 and 1f1af77. Managed-binary archive validation, stream cleanup, install locking, and Semble coverage are updated.

@github-actions github-actions Bot added the awaiting-author PR is waiting for the author to address requested changes label Aug 2, 2026
@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review and removed awaiting-author PR is waiting for the author to address requested changes labels Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract reusable managed-binary installation infrastructure

2 participants