Skip to content

Conversation

@ofir-frd
Copy link

Benchmark PR Significant-Gravitas#11008

Type: Corrupted (contains bugs)

Original PR Title: fix(backend): prevent duplicate graph executions across multiple executor pods
Original PR Description: ## Problem
Multiple executor pods could simultaneously execute the same graph, leading to:

  • Duplicate executions and wasted resources
  • Inconsistent execution states and results
  • Race conditions in graph execution management
  • Inefficient resource utilization in cluster environments

Solution

Implement distributed locking using ClusterLock to ensure only one executor pod can process a specific graph execution at a time.

Key Changes

Core Fix: Distributed Execution Coordination

  • ClusterLock implementation: Redis-based distributed locking prevents duplicate executions
  • Atomic lock acquisition: Only one executor can hold the lock for a specific graph execution
  • Automatic lock expiry: Prevents deadlocks if executor pods crash or become unresponsive
  • Graceful degradation: System continues operating even if Redis becomes temporarily unavailable

Technical Implementation

  • Move ClusterLock to backend/executor/ alongside ExecutionManager (its primary consumer)
  • Comprehensive integration tests (27 test scenarios) ensure reliability under all conditions
  • Redis client compatibility for different deployment configurations
  • Rate-limited lock refresh to minimize Redis load

Reliability Improvements

  • Context manager support: Automatic lock cleanup prevents resource leaks
  • Ownership verification: Locks can only be refreshed/released by the owner
  • Concurrency testing: Thread-safe operations verified under high contention
  • Error handling: Robust failure scenarios including network partitions

Test Coverage

  • ✅ Concurrent executor coordination (prevents duplicate executions)
  • ✅ Lock expiry and refresh mechanisms (prevents deadlocks)
  • ✅ Redis connection failures (graceful degradation)
  • ✅ Thread safety under high load (production scenarios)
  • ✅ Long-running executions with periodic refresh

Impact

  • No more duplicate executions: Eliminates wasted compute resources and inconsistent results
  • Improved reliability: Robust distributed coordination across executor pods
  • Better resource utilization: Only one pod processes each execution
  • Scalable architecture: Supports multiple executor pods without conflicts

Validation

  • All integration tests pass ✅
  • Existing ExecutionManager functionality preserved ✅
  • No breaking changes to APIs ✅
  • Production-ready distributed locking ✅

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com
Original PR URL: Significant-Gravitas#11008

Compliance Violation

  • Rule: Protected Frontend Routes Must Update Middleware Configuration
  • Language: N/A
  • File: N/A - Cannot inject this violation

majdyz and others added 8 commits September 27, 2025 12:46
## Summary
Add complete integration test suite for ClusterLock in synchronize_test.py covering all aspects of Redis-based distributed locking.

## Test Coverage (27 tests across 7 categories)

### Basic Functionality
- Lock acquisition success/failure
- Lock contention handling
- Release behavior (confirms flag-only approach is correct)

### Lock Refresh & TTL Management
- TTL extension and rate limiting (timeout/10 with 10s minimum)
- Ownership verification during refresh
- Natural expiry via Redis TTL

### Context Manager Support
- Blocking/non-blocking acquisition modes
- Automatic cleanup after context exit
- Proper exception handling

### Concurrency & Thread Safety
- Multiple threads competing for same lock
- Sequential lock reuse after expiry
- Refresh during concurrent access attempts

### Error Handling & Edge Cases
- Redis connection failures handled gracefully
- Parameter validation (empty keys, invalid timeouts)
- Manual key deletion scenarios

### Real-World Scenarios
- Graph execution coordination simulation (mirrors ExecutionManager usage)
- Long-running execution with periodic refresh
- Graceful degradation when Redis becomes unavailable

## Technical Details
- Uses same Redis configuration as backend (HOST, PORT, PASSWORD from .env)
- decode_responses=False for ClusterLock's raw bytes ownership verification
- No mocking - tests against real Redis for authentic distributed behavior
- Validates dynamic refresh interval calculation: max(timeout // 10, 10)

## Validation
- All 27 tests pass ✅
- Confirms release() strategy of just setting flags is correct
- Real integration with existing ExecutionManager infrastructure
- Thread-safe cluster coordination verified

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

Co-Authored-By: Claude <noreply@anthropic.com>
…rehensive tests

Move ClusterLock from utils to executor folder where it belongs logically.
Add comprehensive integration tests and improve Redis compatibility.

Fixes duplicate node execution issues by providing proper distributed locking.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Fix failing store tests by adding the missing is_available field to StoreAgent test fixtures.
The prisma.models.StoreAgent requires this field which was recently added but tests weren't updated.

Also fix graceful degradation test timing by using shorter timeout and longer wait.

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

Co-Authored-By: Claude <noreply@anthropic.com>
…s for clearer ownership checking

Summary: Change try_acquire() return semantics to make ownership checking more intuitive.

Changes Made:
- Returns self.owner_id when successfully acquired (instead of None)
- Returns different owner_id when someone else holds the lock
- Returns None only when Redis is unavailable or connection fails
- Updated manager.py to use new check: current_owner != self.executor_id
- Updated all 21 test cases to expect new return values

Benefits: More intuitive success checking, clearer ownership visibility,
eliminates confusing None-means-success pattern.

Validation: All 1061 backend tests pass with 0 failures.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants