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
2 changes: 2 additions & 0 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ Behavior:
is too loaded to deploy
- counts only controller states that still consume runtime capacity; pending
labels by themselves do not count as active previews
- admits up to five concurrent previews by default; set
`ENVCTL_PREVIEW_MAX_OTHER_ACTIVE` to override that capacity
- expires overdue previews before evaluating a new start, so delayed GitHub
schedules cannot leave stale runtimes occupying every admission slot
- keeps failed stop/cleanup states and their dependency leases capacity-visible
Expand Down
2 changes: 1 addition & 1 deletion python/envctl_engine/pr_preview_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def from_env(cls, args: argparse.Namespace) -> "ControllerConfig":
max_load_per_cpu=float(os.environ.get("ENVCTL_PREVIEW_MAX_LOAD_PER_CPU", "1.50")),
min_memory_available_percent=float(os.environ.get("ENVCTL_PREVIEW_MIN_MEMORY_AVAILABLE_PERCENT", "10")),
min_disk_free_percent=float(os.environ.get("ENVCTL_PREVIEW_MIN_DISK_FREE_PERCENT", "10")),
max_other_active_previews=int(os.environ.get("ENVCTL_PREVIEW_MAX_OTHER_ACTIVE", "2")),
max_other_active_previews=int(os.environ.get("ENVCTL_PREVIEW_MAX_OTHER_ACTIVE", "5")),
dry_run=args.dry_run or parse_bool(os.environ.get("ENVCTL_PREVIEW_DRY_RUN", "false")),
qa_user_enabled=parse_bool(os.environ.get("ENVCTL_PREVIEW_QA_USER_ENABLE", "true")),
qa_user_email=env_value(
Expand Down
69 changes: 69 additions & 0 deletions tests/python/runtime/test_pr_preview_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,75 @@ def test_overload_reasons_report_real_threshold_breaches(tmp_path):
assert any("other envctl previews" in reason for reason in reasons)


def test_controller_config_defaults_to_five_concurrent_previews(monkeypatch):
controller = load_controller()
monkeypatch.delenv("ENVCTL_PREVIEW_MAX_OTHER_ACTIVE", raising=False)
args = controller.build_parser().parse_args(
["--repo", "OrgPele/pele-monorepo"]
)

config = controller.ControllerConfig.from_env(args)

assert config.max_other_active_previews == 5


def test_capacity_five_admits_fifth_preview_and_rejects_sixth(tmp_path):
controller = load_controller()
base_config = make_config(controller, tmp_path)
config = controller.ControllerConfig(
**{**base_config.__dict__, "max_other_active_previews": 5}
)
stats = controller.MachineStats(
load_1m=0.0,
load_5m=0.0,
load_15m=0.0,
cpu_count=4,
memory_total_bytes=100,
memory_available_bytes=100,
disk_total_bytes=100,
disk_free_bytes=100,
docker_running_containers=0,
docker_error=None,
top_processes=(),
)
active_previews = [
controller.PreviewState(
pr_number=number,
label="deploy-app",
project=f"feature/{number}",
root=str(tmp_path / str(number)),
head_ref=f"feature/{number}",
head_sha=f"sha-{number}",
status="running",
label_added_at="2026-07-15T17:00:00Z",
started_at="2026-07-15T17:00:00Z",
expires_at="2026-07-15T17:30:00Z",
updated_at="2026-07-15T17:00:00Z",
endpoints={},
)
for number in range(1, 6)
]

fifth_reasons = controller.overload_reasons(
stats,
active_previews[:4],
current_pr_number=99,
config=config,
)
sixth_reasons = controller.overload_reasons(
stats,
active_previews,
current_pr_number=99,
config=config,
)

assert not any("other envctl previews" in reason for reason in fifth_reasons)
assert any(
"5 other envctl previews are already active, meeting limit 5" in reason
for reason in sixth_reasons
)


def test_overloaded_start_comments_stats_lists_other_previews_and_removes_label(
tmp_path,
monkeypatch,
Expand Down
Loading