Skip to content

fix(install-tool): remove read-only user caches - #8423

Queued
viceice wants to merge 2 commits into
mainfrom
viceice/fix/virtualenv-readonly-cache
Queued

viceice wants to merge 2 commits into
mainfrom
viceice/fix/virtualenv-readonly-cache

Conversation

@viceice

@viceice viceice commented Nov 23, 2026

Copy link
Copy Markdown
Member

Changes

  • virtualenv 21.15.12 makes its seed package cache read-only (🐛 fix(seed): make seed images read-only pypa/virtualenv#3757), so the user cache cleanup after install-tool pipenv in a non-root image build fails with EACCES.
  • The cleanup now removes .cache entries and the virtualenv cache with removePath, which makes read-only folders writable and retries, like cleanup-cache already did.
  • removePath moves from cleanup-cache to the shared utils and walks the folders with fs.chmod instead of spawning chmod -R.

Context

Please select one of the following:

  • This closes an existing Issue, Closes: #
  • This doesn't close an Issue, but I accept the risk that this PR may be closed if maintainers disagree with its opening or implementation

AI assistance disclosure

Did you use AI tools to create any part of this pull request?

Please select one option and, if yes, briefly describe how AI was used (e.g., code, tests, docs) and which tool(s) you used.

  • No — I did not use AI for this contribution.
  • Yes — minimal assistance (e.g., IDE autocomplete, small code completions, grammar fixes).
  • Yes — substantive assistance (AI-generated non‑trivial portions of code, tests, or documentation).
  • Yes — other (please describe):

Use of AI in replying to PR comments

Who answers review comments:

  • @viceice will read and reply directly. Name the account.
  • An agent will draft replies and @username will read them before they are posted. Name the account.
  • An agent will draft replies and reply autonomously. This is heavily discouraged, and we prefer that there are humans in the loop
  • Nobody has explicitly committed to replying.

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified tests

Drafted by Claude Code (Claude Opus 5.5, low effort) on behalf of @viceice.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
@viceice
viceice enabled auto-merge November 23, 2026 11:20
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@qodo-code-review

qodo-code-review Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Fix read-only user cache cleanup during tool installation

🐞 Bug fix 🕐 20-40 Minutes

Grey Divider

AI Description

• Remove read-only virtualenv caches without failing non-root Docker builds.
• Share permission-aware removal between install-tool and cleanup-cache, without invoking chmod.
• Verify cache removal and dry-run preservation.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: cache_cleanup_integration.
  • This is the cache-removal behavior attached to the tool-install lifecycle.
  • The install cleanup enumerates user .cache entries and the virtualenv cache, then directly invokes the shared removal helper; it is a separate user-visible operation from the explicit cleanup command but belongs to the same bounded cache-management integration.
  • This is the separately triggered cleanup-cache command.
  • It has the independent user-visible outcome of removing requested caches, including preserving linked roots while removing their contents, but remains within the same bounded cache-management integration as post-install cleanup.
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before, each caller had local removal behavior, while the install path used a deletion library with dry-run handling.
  • After, removal is centralized and adds a first-attempt/errno classification/lstat directory check, recursive descendant traversal, symlink exclusion through Dirent checks, and a retry; the incremental extraction of listEntries and explicit !dryRun guard does not add a new external protocol or persistence transition.
  • The new correctness condition is that permission recovery must apply only to intended directory failures while preserving symlink targets and still removing all selected cache entries.
  • Before: a failed removal either used the caller's local fallback or propagated according to that caller.
  • After: directory EACCES can mutate permissions throughout the directory tree before retry, while other errors propagate.
  • New correctness condition: the fallback, recursive traversal, and retry must agree on directory identity, descendant layout, and the selected cache scope.
  • No new concurrency, migration, or coordinated invariant is introduced.
Potential damage 🟡 Medium 🩹 Recoverable

  • A failed deletion can retain build-time user caches and can cause the install operation to report an error during cleanup after tool writes have completed.
  • Reverting the code restores the prior removal implementation, but does not repair already-created image layers or retained cache contents.
  • No persistent application-state corruption or irreversible external effect is shown.
  • Usually recoverable by correcting filesystem permissions or conditions and rerunning cleanup or rebuilding the image.
  • If the install reports failure after tool installation, the caller may need to verify installed state before retrying.
  • Code rollback alone does not delete retained contents.
Assessed commit 5ebf089
Diagram

graph TD
  I["Install Tool"] --> D{"Non-root Docker build?"} -->|"yes, not dry run"| U["User caches"] --> R["removePath"] --> F["fs.rm"]
  C["Cleanup Cache"] --> R
  F -->|EACCES| W["Writable directories"] -->|retry| F
Loading
High-Level Assessment

Sharing a permission-aware helper is appropriate because both cleanup paths need the same behavior. Keeping filesystem traversal in Node avoids an external chmod subprocess and allows symlinks to be skipped.

Files changed (4) +94 / -36

Bug fix (2) +61 / -12
install-tool.service.tsRemove non-root user caches with the shared helper +21/-11

Remove non-root user caches with the shared helper

• Replaces glob-based deletion with removal of each .cache entry and the virtualenv cache through removePath. Skips that removal on dry runs and leaves the .cache directory itself intact.

src/cli/install-tool/install-tool.service.ts

common.tsAdd shared removal with a writable-directory retry +40/-1

Add shared removal with a writable-directory retry

• Adds removePath, which retries recursive removal after an EACCES error on a directory. The retry adds owner write permission to directories using filesystem APIs and does not chmod symlink targets.

src/cli/utils/common.ts

Refactor (1) +4 / -24
cleanup-cache.service.tsReuse shared permission-aware cache removal +4/-24

Reuse shared permission-aware cache removal

• Replaces the local removal function with removePath for cache roots, entries, and symlink-target contents. Existing cache selection and error reporting remain in place.

src/cli/cleanup/cleanup-cache.service.ts

Tests (1) +29 / -0
install-tool.service.spec.tsTest read-only cleanup and dry-run preservation +29/-0

Test read-only cleanup and dry-run preservation

• Adds a Docker-build test with a read-only virtualenv directory and checks that user cache contents and the virtualenv cache are removed. A second test checks that dry runs preserve user caches.

src/cli/install-tool/install-tool.service.spec.ts

@qodo-code-review

qodo-code-review Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@mend.io>
@viceice
viceice added this pull request to the merge queue Nov 23, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 23, 2026
@viceice
viceice added this pull request to the merge queue Nov 23, 2026
Any commits made after this event will not be merged.
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.

1 participant