Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ GH_TOKEN=
# PR_AF_NO_BUDGET=false
# PR_AF_MAX_DURATION_SECONDS=300
# PR_AF_MAX_COST_USD=2.0

# Concurrency for review_dimension fan-out. Default 10 lets all 6–8
# dimensions run in parallel; raise/lower based on your provider's
# per-key rate limits. Was 3 before — caused 3× wall-clock multiplier
# in production.
# PR_AF_MAX_CONCURRENT_REVIEWERS=10
14 changes: 11 additions & 3 deletions src/pr_af/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ class BudgetConfig(BaseModel):
}
)

# Concurrency — kept low to avoid cascading rate-limit backoff
# when using OpenRouter or other rate-limited providers.
max_concurrent_reviewers: int = 3
# Concurrency for review_dimension fan-out.
#
# Production data showed 8 review_dimensions throttled by this semaphore at
# the previous default of 3, turning per-dimension cost (~25 min) into a
# 3× wall-clock multiplier (≥75 min for the review phase alone). Bumped to
# 10 — well within OpenRouter's per-key rate limits on Kimi K2.5 and the
# other models we run through opencode. Override via PR_AF_MAX_CONCURRENT_REVIEWERS
# if a deployment needs to dial it back for a stricter rate-limit ceiling.
max_concurrent_reviewers: int = Field(
default_factory=lambda: int(os.getenv("PR_AF_MAX_CONCURRENT_REVIEWERS", "10"))
)

# Stagger delay (seconds) between launching parallel tasks to avoid
# burst rate-limit hits. Set to 0 to disable staggering.
Expand Down
22 changes: 18 additions & 4 deletions tests/test_staggered_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,21 @@ async def fail() -> str:


def test_budget_config_defaults():
"""Verify the updated concurrency and stagger defaults."""
config = BudgetConfig()
assert config.max_concurrent_reviewers == 3
assert config.stagger_delay_seconds == 2.0
"""Verify the updated concurrency and stagger defaults.

Concurrency was raised from 3 → 10 after production data showed 8
review_dimensions throttled by the old semaphore, turning ~25-min
per-dimension cost into a 3× wall-clock multiplier. The default is
overridable via PR_AF_MAX_CONCURRENT_REVIEWERS — clear that env var
so the test pins the in-code default rather than the runtime override.
"""
import os

prior = os.environ.pop("PR_AF_MAX_CONCURRENT_REVIEWERS", None)
try:
config = BudgetConfig()
assert config.max_concurrent_reviewers == 10
assert config.stagger_delay_seconds == 2.0
finally:
if prior is not None:
os.environ["PR_AF_MAX_CONCURRENT_REVIEWERS"] = prior
Loading