Skip to content

Comments

fix: prevent race condition when files are deleted between collection and execution#353

Merged
jdx merged 2 commits intomainfrom
fix-batch-false-empty-files
Oct 5, 2025
Merged

fix: prevent race condition when files are deleted between collection and execution#353
jdx merged 2 commits intomainfrom
fix-batch-false-empty-files

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Oct 5, 2025

Problem

When running mise run render ::: lint-fix in CI (which runs render and lint-fix in parallel), prettier would fail with:

prettier – 0 files – *.js *.jsx *.mjs...
prettier – [error] No parser and no file path given, couldn't infer a parser.

Root Cause

This was a race condition between parallel tasks:

  1. mise run render builds docs and temporarily creates .timestamp-*.mjs files (VitePress cache files)
  2. hk fix --all starts and calls git status, which includes these temporary files
  3. hk filters files through prettier's glob pattern - .mjs files match!
  4. VitePress deletes the timestamp files as part of its cleanup
  5. hk still has these files in its job list, but they no longer exist
  6. When prettier runs, the file list is empty, causing the "No parser" error

The warning in the logs confirms this:

hk WARN  failed to canonicalize file: docs/registry.data.ts.timestamp-1759693024496-12ef47f15bd9b.mjs No such file or directory (os error 2)

Solution

Added a check right before command execution to filter out files that no longer exist and skip the job if all files were deleted. This prevents tools from being called with empty file lists due to race conditions.

The fix happens in step.rs at the execution stage:

// Filter out files that no longer exist (e.g., deleted by parallel tasks)
job.files.retain(|f| f.exists());
// Skip this job if all files were deleted
if job.files.is_empty() && (self.glob.is_some() || self.dir.is_some() || self.exclude.is_some()) {
    debug!("{self}: all files deleted before execution");
    self.mark_skipped(ctx, &SkipReason::NoFilesToProcess)?;
    return Ok(());
}

Test Coverage

  • Added test/batch_false_empty_files.bats verifying steps skip when no files match filters
  • Fixed test/fail_fast_config.bats to properly test fail_fast behavior with actual files
  • All existing tests pass

Impact

Fixes the issue reported in https://github.com/jdx/mise/actions/runs/18262606323/job/51992569650

🤖 Generated with Claude Code


Note

Skip step execution when file filters yield no files or when files are deleted before run, and add tests to verify batch=false and race-condition behavior.

  • Step execution
    • Skip when filter_files yields empty and step has file filters (glob/dir/exclude).
    • Before running, drop files that no longer exist (symlink_metadata) and skip with no-files-to-process if none remain.
    • Template context: for regex glob patterns, set globs to the regex string for command templates.
  • Tests
    • Add test/batch_false_empty_files.bats covering: no matches, all excluded, and deletion between collection and execution (race) with graceful skip.
    • Update test/fail_fast_config.bats to ensure execution context is valid while preserving fail-fast behavior checks.

Written by Cursor Bugbot for commit 8aaa202. This will update automatically on new commits. Configure here.

…ence

## Problem
When `batch = false` is set for a step, and the file list becomes empty
(e.g., when no files match the glob pattern or all files are excluded),
the step would still create a job with an empty file list. This caused
tools like prettier to fail with "No parser and no file path given,
couldn't infer a parser" error.

## Root Cause
The empty file check in `build_step_jobs()` at line 456 only skipped
when filters (glob, dir, or exclude) were explicitly set:

```rust
if files.is_empty() && (self.glob.is_some() || self.dir.is_some() || self.exclude.is_some())
```

This meant that steps with `batch = false` but without explicit filters
would still create jobs with empty file lists.

## Solution
Remove the filter condition check and skip whenever the file list is
empty, regardless of whether filters are configured:

```rust
if files.is_empty()
```

This ensures that no step job will be created with an empty file list,
preventing tools from being called with no arguments.

## Test Coverage
Added `test/batch_false_empty_files.bats` with two test cases:
1. Step with glob that matches no files
2. Step with exclude that filters out all files

Both cases now correctly skip with "no files to process" reason.

Fixes the issue reported in https://github.com/jdx/mise/actions/runs/18262606323/job/51992569650

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@jdx jdx changed the title fix: skip step jobs when file list is empty regardless of filter presence fix: prevent race condition when files are deleted between collection and execution Oct 5, 2025
cursor[bot]

This comment was marked as outdated.

Add test that simulates the VitePress race condition where:
1. deleter step removes a .temp.mjs file (like VitePress cleanup)
2. prettier step tries to run on the now-deleted file

This test fails on origin/main with the prettier error and passes
with our fix that filters out deleted files before execution.
@jdx jdx force-pushed the fix-batch-false-empty-files branch from 9ec73fb to 8aaa202 Compare October 5, 2025 19:52
@jdx jdx merged commit 3c356b8 into main Oct 5, 2025
12 checks passed
@jdx jdx deleted the fix-batch-false-empty-files branch October 5, 2025 19:57
@jdx jdx mentioned this pull request Oct 5, 2025
jdx added a commit that referenced this pull request Oct 5, 2025
## [1.18.1](https://github.com/jdx/hk/compare/v1.18.0..v1.18.1) -
2025-10-05

### 🐛 Bug Fixes

- prevent race condition when files are deleted between collection and
execution by [@jdx](https://github.com/jdx) in
[#353](#353)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Release 1.18.1 with a fix for a file-deletion race condition and
synchronized version refs across code, docs, and CLI metadata.
> 
> - **Release 1.18.1**
> - **Bug Fix**: Prevent race when files are deleted between collection
and execution (`CHANGELOG.md`).
> - **Version Bump**: Update `1.18.0` → `1.18.1` in `Cargo.toml`,
`Cargo.lock`, CLI specs (`docs/cli/commands.json`, `docs/cli/index.md`,
`hk.usage.kdl`), docs and examples (`docs/*.md`, `docs/public/*.pkl`,
`docs/reference/**`), templates (`hk-example.pkl`, `src/cli/init.rs`),
project config (`hk.pkl` comment), and error/help text
(`src/config.rs`).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
90e8fcd. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: mise-en-dev <[email protected]>
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Oct 10, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [hk](https://github.com/jdx/hk) | minor | `1.15.7` -> `1.18.3` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jdx/hk (hk)</summary>

### [`v1.18.3`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1183---2025-10-07)

[Compare Source](jdx/hk@v1.18.2...v1.18.3)

##### 🐛 Bug Fixes

- stash untracked files during partial stashes when HK\_STASH\_UNTRACKED=true by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;357](jdx/hk#357)

### [`v1.18.2`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1182---2025-10-06)

[Compare Source](jdx/hk@v1.18.1...v1.18.2)

##### 🐛 Bug Fixes

- stage directive to include untracked files matching globs by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;355](jdx/hk#355)

### [`v1.18.1`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1181---2025-10-05)

[Compare Source](jdx/hk@v1.18.0...v1.18.1)

##### 🐛 Bug Fixes

- prevent race condition when files are deleted between collection and execution by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;353](jdx/hk#353)

### [`v1.18.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1180---2025-10-05)

[Compare Source](jdx/hk@v1.16.0...v1.18.0)

##### 🚀 Features

- add fix-smart-quotes util by [@&#8203;joonas](https://github.com/joonas) in [#&#8203;348](jdx/hk#348)

##### 🐛 Bug Fixes

- add Windows support by guarding Unix-specific file permission APIs by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;349](jdx/hk#349)
- handle missing files in update-version script by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;350](jdx/hk#350)
- rewrite update-version script to avoid pipefail issues by [@&#8203;jdx](https://github.com/jdx) in [211b1ac](jdx/hk@211b1ac)
- run render before update-version in release script by [@&#8203;jdx](https://github.com/jdx) in [35d2df3](jdx/hk@35d2df3)
- use \[0-9] instead of \d in ripgrep pattern for better compatibility by [@&#8203;jdx](https://github.com/jdx) in [cf8ebb0](jdx/hk@cf8ebb0)
- explicitly specify search path for ripgrep in update-version script by [@&#8203;jdx](https://github.com/jdx) in [5666f96](jdx/hk@5666f96)

##### 🔍 Other Changes

- add diagnostic output to update-version script by [@&#8203;jdx](https://github.com/jdx) in [aaeea63](jdx/hk@aaeea63)
- add more file existence checks by [@&#8203;jdx](https://github.com/jdx) in [cbace40](jdx/hk@cbace40)
- test rg pattern matching in CI environment by [@&#8203;jdx](https://github.com/jdx) in [a52ea46](jdx/hk@a52ea46)

##### New Contributors

- [@&#8203;joonas](https://github.com/joonas) made their first contribution in [#&#8203;348](jdx/hk#348)

### [`v1.16.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1160---2025-10-02)

[Compare Source](jdx/hk@v1.15.7...v1.16.0)

##### 🚀 Features

- add HK\_STAGE setting to control automatic staging of fixed files by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;313](jdx/hk#313)
- suppress check output\_summary when fixer runs with check\_first by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;315](jdx/hk#315)

##### 🐛 Bug Fixes

- \--slow flag now properly enables slow profile by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;317](jdx/hk#317)

##### 📚 Documentation

- Update getting\_started.md by [@&#8203;jdx](https://github.com/jdx) in [a8c1a35](jdx/hk@a8c1a35)

##### 🔍 Other Changes

- Update getting\_started.md by [@&#8203;jdx](https://github.com/jdx) in [58c0564](jdx/hk@58c0564)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMzIuNSIsInVwZGF0ZWRJblZlciI6IjQxLjEzOC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
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