Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Only stop when more than x files change in the project compared to more than x files exist#121

Merged
joeldierkes merged 2 commits intomainfrom
vk/b7da-only-stop-when-m
Jan 20, 2026
Merged

Only stop when more than x files change in the project compared to more than x files exist#121
joeldierkes merged 2 commits intomainfrom
vk/b7da-only-stop-when-m

Conversation

@joeldierkes
Copy link
Contributor

@joeldierkes joeldierkes commented Jan 16, 2026

Rn mgrep watch stops when more than x files exist in the folder. Let's change that so that mgrep stops when more than x files need to be uploaded/deleted.

Also check if that is really the current behavior.


Note

Implements file count limiting based on actual sync workload rather than total repo files.

  • initialSync now precomputes filesToPotentiallyUpload (size-filtered, mtime-checked) and filesToDelete, sums them as filesToSync, and throws MaxFileCountExceededError when exceeding config.maxFileCount
  • Refines error to: Files to sync (X) exceeds the maximum allowed (Y). No files were synced. and updates all tests accordingly
  • Updates README.md and config JSDoc to clarify maxFileCount applies to files to sync per operation (upload/delete), and example CLI/env var descriptions

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

@aamir-s18
Copy link
Contributor

strange naming but looks good

**You were correct!** The previous behavior checked `repoFiles.length` (total files in the folder) instead of files that actually need to be synced.

### Changes Made

1. **`src/lib/utils.ts:27-35`** - Updated `MaxFileCountExceededError` message to say "Files to sync" instead of "File count"

2. **`src/lib/utils.ts:300-326`** - Added logic to calculate `filesToPotentiallyUpload` which counts only files that:
   - Are new (not in store)
   - Have changed (mtime is newer than stored mtime)
   - Don't exceed max file size

   Then the check is:
   ```typescript
   const filesToSync = filesToPotentiallyUpload.length + filesToDelete.length;
   if (config && filesToSync > config.maxFileCount) {
     throw new MaxFileCountExceededError(filesToSync, config.maxFileCount);
   }
   ```

### Behavior Change

| Scenario | Before | After |
|----------|--------|-------|
| 2000 files total, 10 need syncing, limit=1000 | ❌ Error (2000 > 1000) | ✅ Passes (10 < 1000) |
| 500 files total, 1500 deleted in store, limit=1000 | ✅ Passes (500 < 1000) | ❌ Error (1500 > 1000) |
| 100 new files + 50 deleted, limit=1000 | ✅ Passes | ✅ Passes (150 < 1000) |

The new behavior is more practical - it protects against accidentally syncing too many changes in one operation while allowing large codebases that are already synced to continue working.
1. **Line 208**: Changed description from "limit uploads to directories with 5000 files or fewer" to "limit sync to 5000 changed files or fewer"
2. **Line 232**: Changed comment from "Maximum number of files to upload" to "Maximum number of files to sync (upload/delete) per operation"
3. **Line 274**: Changed description from "Maximum number of files to upload" to "Maximum number of files to sync per operation"

- Updated JSDoc comment to reflect that the limit applies to files that need syncing, not total files in the folder

Updated 4 test assertions to match the new error message format:
- Line 404: `File count (5)` → `Files to sync (5)`
- Line 436: `File count (4)` → `Files to sync (4)`
- Line 453: `File count (4)` → `Files to sync (4)`
- Line 470: `File count (4)` → `Files to sync (4)`
- All instances of `No files were uploaded` → `No files were synced`
@joeldierkes joeldierkes force-pushed the vk/b7da-only-stop-when-m branch from e27cc12 to 0a1f95c Compare January 20, 2026 16:18
@joeldierkes joeldierkes merged commit e2eeefa into main Jan 20, 2026
2 checks passed
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.

2 participants