Skip to content

Conversation

@BasselBlal
Copy link

@BasselBlal BasselBlal commented Jan 28, 2026

Description:
This PR improves the reliability of parallel agent execution by strictly isolating infrastructure files, preventing merge conflicts, and handling all file changes robustly. It simplifies the commit logic to ensure clean working directories and data integrity.

Key Changes:

  1. src/execution/parallel.ts:

    • Fix: Refactored runtime file filtering to use the centralized DEFAULT_IGNORED list from sandbox.ts.
    • Reason: Replaces ad-hoc path checks with a robust, case-insensitive logic that correctly filters broad patterns like .ralphy (entire folder), matching sandbox creation logic.
  2. src/execution/sandbox-git.ts:

    • Fix: Replaced catch-all git staging with a two-phase staging process using a hardened safeGitAdd helper:
      1. Batching: Processes files in chunks of 20 to prevent ENAMETOOLONG errors on Windows.
      2. Ignore Filtering: Pre-checks files with git check-ignore to prevent errors from git adding ignored files (e.g. .env, .turbo).
      3. Retries: Automatically retries on index.lock contention to handle high-concurrency parallel execution.
      4. Two-Phase Strategy: First stages explicitly tracked files, then catches untracked files (e.g. composer installs) via git status, providing redundancy against missed files.
    • Reason: The previous git add . approach was fragile, and standard git add crashed on large file sets or locked repos. The new robust approach guarantees data integrity even under heavy parallel load.
  3. src/execution/sandbox.ts:

    • Fix: Updated DEFAULT_IGNORED to include the entire .ralphy directory and improved matchesPattern regex escaping.
    • Reason: Agents do not need access to the .ralphy folder (config is loaded by the runner), preventing infrastructure pollution. Added comprehensive unit tests (sandbox.test.ts).
  4. src/execution/prompt.ts:

    • Fix: Removed instructions to update progress.txt.
    • Reason: Eliminates race conditions where agents attempted to modify the runner's tracking file.

Result:
Parallel execution now runs cleanly without merge conflicts or "dirty checkout" errors. Infrastructure files are fully isolated, and the commit strategy ensures zero data loss for agent-generated files (including package manager artifacts) while respecting isolation boundaries.

- Add robust file filtering to exclude .ralphy, progress.txt, and nul from agent commits
- Remove contradictory prompt instruction for updating progress.txt
- Add DEFAULT_IGNORED list to sandbox creation to prevent infrastructure file copying
@vercel
Copy link

vercel bot commented Jan 28, 2026

@BasselBlal is attempting to deploy a commit to the Goshen Labs Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot
Copy link

dosubot bot commented Jan 28, 2026

Related Documentation

Checked 30 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 28, 2026

Greptile Overview

Greptile Summary

This PR successfully addresses parallel agent isolation by preventing infrastructure file conflicts through centralized ignore patterns and a robust two-phase git staging process.

Key Improvements

  • Centralized Filtering: Introduced DEFAULT_IGNORED list with pattern matching functions (matchesPattern, isIgnored) that properly handle directory boundaries, wildcards, and regex escaping
  • Infrastructure Isolation: .ralphy/ directory and other infrastructure files are now filtered from both sandbox creation and git commits, preventing merge conflicts
  • Robust Git Staging: Two-phase approach with safeGitAdd helper that batches files (prevents ENAMETOOLONG), filters ignored files via git check-ignore, and retries on lock contention
  • Race Condition Fix: Removed progress.txt update instruction from agent prompts to eliminate concurrent modification issues
  • Comprehensive Tests: Added test suite validating pattern matching edge cases including boundary checks and regex escaping

Architecture

The filtering logic is applied consistently across three critical points:

  1. Sandbox creation (sandbox.ts:189-199) - prevents infrastructure files from being copied into agent workspaces
  2. File commit filtering (parallel.ts:470-506) - prevents infrastructure files from being staged for commit
  3. Git staging (sandbox-git.ts:164-191) - secondary filter during two-phase staging catches any edge cases

The two-phase staging approach (Phase 1: explicit filtered files, Phase 2: untracked files from git status) ensures no agent-generated files are lost while maintaining isolation boundaries.

Confidence Score: 4/5

  • Safe to merge with minor considerations - the implementation is solid but has extensive previous review comments that have been addressed or explained by the developer
  • The code demonstrates thoughtful design with proper error handling, comprehensive testing, and addresses the core issue of parallel agent isolation. The extensive previous review thread shows the developer has been responsive to feedback and made deliberate architectural choices (e.g., symlinking nested dependencies for performance). The pattern matching logic is well-tested and the two-phase staging approach is robust. Score reflects solid implementation quality with no critical issues found.
  • No files require special attention - all changes are well-structured and properly tested

Important Files Changed

Filename Overview
cli/src/execution/sandbox.ts Added centralized pattern matching functions (matchesPattern, isIgnored) with proper regex escaping and introduced DEFAULT_IGNORED list to filter infrastructure files during sandbox creation
cli/src/execution/parallel.ts Refactored file filtering to use centralized DEFAULT_IGNORED patterns instead of hardcoded strings, with proper directory boundary checks and basename matching for recursive filtering
cli/src/execution/sandbox-git.ts Implemented two-phase staging with safeGitAdd helper that batches files, filters ignored files via git check-ignore, and retries on lock contention for robust parallel execution

Sequence Diagram

sequenceDiagram
    participant Runner as Main Runner
    participant Agent as Parallel Agent
    participant Sandbox as Sandbox (sandbox.ts)
    participant Git as Git Operations (sandbox-git.ts)
    participant Filter as File Filter (parallel.ts)

    Runner->>Agent: Execute task in parallel
    Agent->>Sandbox: createSandbox(originalDir, sandboxDir)
    Sandbox->>Sandbox: Filter items using DEFAULT_IGNORED
    Sandbox->>Sandbox: isIgnored(item, DEFAULT_IGNORED, isDir)
    Sandbox->>Sandbox: Symlink dependencies (node_modules, .git)
    Sandbox->>Sandbox: Copy source files recursively
    Note over Sandbox: .ralphy/ directory excluded from sandbox
    Sandbox-->>Agent: Sandbox created with isolation
    
    Agent->>Agent: Execute task modifications
    Note over Agent: progress.txt instruction removed
    
    Agent->>Filter: getModifiedFiles(worktreeDir, workDir)
    Filter->>Filter: Compare file timestamps
    Filter-->>Agent: Return modified files list
    
    Agent->>Filter: Filter files using DEFAULT_IGNORED
    loop For each modified file
        Filter->>Filter: Check directory patterns (e.g., ".ralphy/")
        Filter->>Filter: Check basename patterns (e.g., "nul", "*.log")
        Filter->>Filter: matchesPattern(baseName, pattern)
    end
    Note over Filter: Infrastructure files filtered out
    Filter-->>Agent: Return filtered files
    
    Agent->>Git: commitSandboxChanges(filteredFiles)
    Git->>Git: Create new branch
    Git->>Git: Copy filtered files to original dir
    
    Note over Git: Phase 1: Stage explicitly filtered files
    Git->>Git: safeGitAdd(git, filesToStage)
    Git->>Git: Batch files (20 per batch)
    Git->>Git: Filter via git check-ignore
    Git->>Git: Retry on index.lock contention
    
    Note over Git: Phase 2: Catch additional files
    Git->>Git: git status (find untracked/modified)
    loop For each untracked file
        Git->>Git: Check against DEFAULT_IGNORED
        Git->>Git: Filter infrastructure files
    end
    Git->>Git: safeGitAdd(git, additionalFiles)
    Note over Git: Handles composer/npm installs in symlinked dirs
    
    Git->>Git: git commit
    Git->>Git: Return to original branch
    Git-->>Agent: Commit successful
    
    Agent-->>Runner: Task completed with branch
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

- fix files counter not incremented when copying regular files
-  Remove unreachable code  (line 197-207).
- fix middle wildcard syntax error
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

BasselBlal and others added 2 commits January 28, 2026 10:14
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 28, 2026

Additional Comments (1)

cli/src/execution/sandbox-git.ts
logging modifiedFiles.length instead of filesToAdd.length - reports incorrect count when some files were filtered by .gitignore

		logDebug(`Agent ${agentNum}: Committed ${filesToAdd.length} files to ${branchName}`);
Prompt To Fix With AI
This is a comment left during a code review.
Path: cli/src/execution/sandbox-git.ts
Line: 127:127

Comment:
logging `modifiedFiles.length` instead of `filesToAdd.length` - reports incorrect count when some files were filtered by `.gitignore`

```suggestion
		logDebug(`Agent ${agentNum}: Committed ${filesToAdd.length} files to ${branchName}`);
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@BasselBlal
Copy link
Author

I really appreciate the project and hope this gets accepted!
P.S. This is my first open source PR 🚀

Change: Implemented robust "Safe Commit" logic using Git's magic pathspecs (git add . ":!.ralphy/progress.txt") to replace fragile file filtering.

Why it fixes the issue:

Atomicity: Instead of adding files one-by-one (which fails on ignored files) or adding all and then resetting (which is race-prone), this command performs a single atomic operation. It stages everything while excluding the progress log in one nanosecond.
Prevents "Dirty Checkout" Errors: By using git add ., we ensure absolute coverage of all agent-generated files (lockfiles, vendor updates, build artifacts). This leaves the working directory 100% clean, solving the "Local changes would be overwritten by checkout" crash.
Conflict Prevention: Explicitly excluding .ralphy/progress.txt ensures that local runner logs are never committed to the agent's branch, preventing merge conflicts when integrating parallel work.
Graceful Fallback: Added a fallback mechanism that reverts to standard behavior (logging as debug) if the git client is too old to support pathspecs.
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Processes files in chunks of 20 to prevent `ENAMETOOLONG` errors on Windows.
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