Skip to content

fix(task): prevent broken pipe panic and race condition in remote git task cache#8375

Merged
jdx merged 4 commits intojdx:mainfrom
vmaleze:fix/task-remote-git-cache-race-and-epipe
Feb 28, 2026
Merged

fix(task): prevent broken pipe panic and race condition in remote git task cache#8375
jdx merged 4 commits intojdx:mainfrom
vmaleze:fix/task-remote-git-cache-race-and-epipe

Conversation

@vmaleze
Copy link
Contributor

@vmaleze vmaleze commented Feb 27, 2026

Fixes intermittent panics when fetching remote git tasks by replacing println!/eprintln! with non-panicking writeln! for EPIPE handling, and adding file locking + clone-to-temp-then-rename to prevent concurrent cache corruption.

… task cache

Remote git task fetching could panic on EPIPE when stdout/stderr was
piped, and concurrent fetches of the same repo could corrupt the cache.

Use writeln! instead of println!/eprintln! to gracefully handle broken
pipes, add file locking per cache key to serialize concurrent access,
and clone to a temp directory before renaming into place to avoid
partial cache state.

Made-with: Cursor
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses two critical issues in the remote git task cache: potential panics due to broken pipes and race conditions leading to cache corruption. It enhances the robustness and reliability of the task fetching process by implementing safer output writing and ensuring atomic cache updates.

Highlights

  • Broken Pipe Handling: Replaced println! and eprintln! with writeln! to prevent panics caused by broken pipes (EPIPE) when fetching remote git tasks.
  • Race Condition Prevention: Implemented file locking and a clone-to-temp-then-rename strategy to prevent concurrent cache corruption when fetching remote git tasks.
Changelog
  • src/cmd.rs
    • Replaced println! and eprintln! with writeln! to handle potential EPIPE errors gracefully.
  • src/task/task_file_providers/remote_task_git.rs
    • Added file locking to prevent concurrent access to the remote git task cache.
    • Implemented a clone-to-temporary-directory-then-rename strategy to ensure atomic updates of the cache.
Activity
  • The pull request introduces changes to handle broken pipe errors and prevent race conditions in the remote git task cache.
  • It replaces println! and eprintln! with writeln! for safer output writing.
  • File locking and a clone-to-temp-then-rename strategy are implemented to prevent cache corruption.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses two separate issues: preventing panics from broken pipes and fixing a race condition in the remote git task cache. The use of writeln! instead of println! is a good, standard way to handle EPIPE errors gracefully. The implementation of file locking combined with a clone-to-temp-then-rename strategy for the git cache is a robust solution to prevent concurrent access issues. I have one suggestion to improve the error handling and ensure temporary files are always cleaned up.

@greptile-apps
Copy link

greptile-apps bot commented Feb 27, 2026

Greptile Summary

This PR fixes two related issues in task execution: EPIPE panics and race conditions in remote git task caching. The changes prevent crashes when stdout/stderr is closed unexpectedly by replacing panicking I/O macros with error-returning alternatives, and eliminate cache corruption from concurrent access by implementing proper file locking with atomic clone-to-temp-then-rename operations.

  • src/cmd.rs: Replaced println! and eprintln! with writeln! on locked stdout/stderr handles, ignoring errors to gracefully handle EPIPE conditions
  • src/task/task_file_providers/remote_task_git.rs: Added LockFile to serialize concurrent cache access, implemented atomic updates via temporary directory cloning followed by rename operation

The implementation follows best practices for concurrent file operations and error handling. No issues found.

Confidence Score: 5/5

  • This PR is safe to merge with no identified risks
  • Both changes follow well-established patterns for handling EPIPE errors and preventing concurrent file corruption. The EPIPE fix uses the standard approach of replacing panicking macros with Result-returning alternatives. The cache protection implements proper locking with atomic rename operations, preventing race conditions while maintaining correct cleanup on all code paths.
  • No files require special attention

Important Files Changed

Filename Overview
src/cmd.rs Replaced println!/eprintln! with writeln! to prevent broken pipe panics
src/task/task_file_providers/remote_task_git.rs Added file locking and atomic clone-to-temp-then-rename pattern to prevent concurrent cache corruption

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Start: get_local_path] --> B[Acquire Lock on destination]
    B --> C{is_cached == true?}
    C -->|Yes| D{full_path exists?}
    D -->|Yes| E[Return cached file]
    D -->|No| F[Continue to clone]
    C -->|No| F
    F --> G[Clean up tmp_destination if exists]
    G --> H[Clone repo to tmp_destination]
    H --> I{Clone successful?}
    I -->|No| J[Clean up tmp_destination]
    J --> K[Return error]
    I -->|Yes| L[Remove destination if exists]
    L --> M[Rename tmp_destination to destination]
    M --> N{Rename successful?}
    N -->|No| O[Clean up tmp_destination]
    O --> P[Return error]
    N -->|Yes| Q[Return full_path]
    E --> R[Release lock]
    K --> R
    P --> R
    Q --> R
Loading

Last reviewed commit: b718a6d

@jdx jdx merged commit 822d42c into jdx:main Feb 28, 2026
33 checks passed
mise-en-dev added a commit that referenced this pull request Feb 28, 2026
### 🚀 Features

- **(backend-plugin)** pass options to vfox backend plugins by
@Attempt3035 in [#8369](#8369)

### 🐛 Bug Fixes

- **(install)** prevent --locked mode from modifying or bypassing
lockfile by @jdx in [#8362](#8362)
- **(install)** clear aqua bin_paths cache after install to prevent
stale PATH by @jdx in [#8374](#8374)
- **(task)** prevent broken pipe panic and race condition in remote git
task cache by @vmaleze in [#8375](#8375)

### 📦️ Dependency Updates

- update docker/build-push-action digest to 10e90e3 by @renovate[bot] in
[#8367](#8367)
- update fedora:43 docker digest to 781b764 by @renovate[bot] in
[#8368](#8368)

### 📦 Registry

- add porter
([github:getporter/porter](https://github.com/getporter/porter)) by
@lbergnehr in [#8380](#8380)
- add entire ([aqua:entireio/cli](https://github.com/entireio/cli)) by
@TyceHerrman in [#8378](#8378)
- add topgrade
([aqua:topgrade-rs/topgrade](https://github.com/topgrade-rs/topgrade))
by @TyceHerrman in [#8377](#8377)

### Chore

- remove pre-commit config and tool dependency by @jdx in
[#8373](#8373)

### New Contributors

- @Attempt3035 made their first contribution in
[#8369](#8369)
- @lbergnehr made their first contribution in
[#8380](#8380)
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.

3 participants