fix(file): eliminate duplicate reads under task_concurrency - #117
Open
Mahesh Kamble (ma-gk) wants to merge 3 commits into
Open
fix(file): eliminate duplicate reads under task_concurrency#117Mahesh Kamble (ma-gk) wants to merge 3 commits into
Mahesh Kamble (ma-gk) wants to merge 3 commits into
Conversation
Previously, when task_concurrency > 1 in read mode, each worker independently expanded the glob and read every matched file, so every file was emitted once per worker (Nx duplication). The glob is now expanded exactly once (guarded by sync.Once), and workers claim disjoint files off the shared matched-path list via an atomic index, so each matched file is read exactly once regardless of worker count. Also fixes writeFile to build the per-worker file struct explicitly instead of struct-copying f, since f now carries a sync.Once/atomic read-concurrency state (and the embedded task.Base mutex) that must never be copied. Adds test/pipelines/file_concurrency_test.yaml, which exercises both directions: 4 concurrent read workers against a 2-file glob (expect exactly 2 read records, not 8), and 8 concurrent write workers writing one file per input line (expect the output file count to exactly match the input line count). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The write task's path had drifted to a repo-relative test/{{ macro
"uuid" }}.txt, contradicting the file's own header comment and
dumping generated files straight into the git checkout instead of
/tmp. Restored to /tmp/caterpillar/file_concurrency_test/{{ macro
"uuid" }}.txt as documented.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
filetask's read mode: whentask_concurrency > 1, every worker independently expanded the glob and read every matched file, so each file was emitted once per worker instead of once total.sync.Once), and workers claim disjoint files off the shared matched-path list via an atomic index (readIdx), so N workers split the file list N ways instead of each reading every file.writeFilenow builds the per-workerfilestruct explicitly (only the fields the writer needs) instead of struct-copyingf, sincefnow carriessync.Once/atomic read-concurrency state (and the embeddedtask.Basemutex) that must never be struct-copied.task_concurrencydoc row in the task README to describe the read/write semantics precisely.Test plan
Added
test/pipelines/file_concurrency_test.yaml, which exercises both directions in one pipeline:task_concurrency: 4against a glob matching 2 fixture files (names.txt,birds.txt) — before the fix, 4 workers × 2 files = 8 read records; after the fix, exactly 2.task_concurrency: 8writing one file per line after asplit— output file count must exactly equal input line count (no drops, no duplicates).Ran locally:
Output count matches expected exactly.
🤖 Generated with Claude Code