Skip to content

Add parallel PR review processing with queue depth monitoring#4

Merged
Tyler-Rak merged 3 commits intoreleasefrom
feature/queue-depth-monitoring
Dec 9, 2025
Merged

Add parallel PR review processing with queue depth monitoring#4
Tyler-Rak merged 3 commits intoreleasefrom
feature/queue-depth-monitoring

Conversation

@Tyler-Rak
Copy link
Copy Markdown
Owner

Summary

Adds concurrent PR review processing capability with semaphore-based queue depth monitoring to handle multiple PRs efficiently while preventing resource exhaustion.

Features

1. Parallel Webhook Endpoint (/webhook-parallel)

  • New endpoint for concurrent PR review processing
  • Uses asyncio.create_task() for true parallel execution
  • Semaphore-based concurrency limiting

2. Configurable Concurrency Control

[bitbucket_app]
enable_parallel_reviews = true
max_concurrent_reviews = 3

3. Queue Depth Monitoring

  • Tracks active review tasks globally
  • Logs queue depth metrics (queue_depth, active_reviews, review_start_time)
  • Thread-safe task tracking with asyncio.Lock

4. Comment Filtering Enhancement

  • Filters out non-actionable comments (UNAPPROVED, NEEDS_WORK)
  • Only processes reasonable comments on parallel endpoint
  • Prevents duplicate processing of approval/needs-work events

Changes

Core Implementation

pr_agent/servers/bitbucket_server_webhook.py:

  • Added /webhook-parallel endpoint (200+ lines)
  • Global review_semaphore for concurrency limiting
  • Global active_review_tasks dictionary with async lock
  • Queue monitoring with structured logging
  • Comment filtering for parallel endpoint

tests/unittest/test_bitbucket_server_webhook.py:

  • Added 174 lines of unit tests
  • Tests for comment filtering logic
  • Tests for queue monitoring

pyproject.toml:

  • Version bump (tracking changes)

Logging Fix

  • Changed log_context["event"]log_context["webhook_event_type"]
  • Fixes conflict with function parameter event= in logger

Benefits

  1. Improved Throughput: Process multiple PRs concurrently
  2. Resource Protection: Semaphore prevents overload
  3. Observability: Queue depth metrics for monitoring
  4. Reduced Noise: Filters non-actionable webhook events
  5. Backward Compatible: Original /webhook endpoint unchanged

Configuration

Enable parallel processing in .secrets.toml:

[bitbucket_app]
enable_parallel_reviews = true
max_concurrent_reviews = 3  # Adjust based on resources

Testing

Unit tests added: 174 lines of test coverage

  • Comment filtering scenarios
  • Queue monitoring logic

Deployment Notes

  • Default behavior: Parallel reviews DISABLED by default
  • Migration path: Can enable gradually per environment
  • Monitoring: Check logs for queue_depth and active_reviews metrics
  • Tuning: Adjust max_concurrent_reviews based on pod resources

Related Work

This PR works independently but pairs well with async subprocess improvements (#3) for even better performance on large PRs.

Documentation

See commit messages for detailed implementation notes:

  • b3a2b338 - fix queue logging (queue monitoring implementation)
  • 1f726954 - only filtering reasonable comments (comment filtering)

Move all custom documentation to docs/rakuten/ for clear separation
from upstream docs:
- Move architecture docs to docs/rakuten/architecture/
- Add CONCURRENCY_LIMITS.md with analysis of API rate limits and
  safe concurrency levels for Rakuten CaaS deployment
- Add README.md to explain custom vs upstream documentation

This organization makes it clear which docs are Rakuten-specific and
prevents merge conflicts with upstream changes.
@Tyler-Rak Tyler-Rak changed the base branch from main to release December 9, 2025 12:11
@Tyler-Rak Tyler-Rak merged commit 8754150 into release Dec 9, 2025
@Tyler-Rak Tyler-Rak deleted the feature/queue-depth-monitoring branch December 9, 2025 12:14
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