Skip to content

feat(ci): limit how many CPU-heavy gates run at once on one host #2336

Closed

Description

@dan-petty

Problem or Motivation

Several agents work on this repository at the same time. Each agent runs devops ci in its own worktree. Nothing limits how many gates run on the host at once, and the pytest of each run starts -n logical workers (16 on this host). ADR 0014 records the effect: "Nothing limits how many runs share the host, and the pytest of each run uses every CPU. The load average reached 88."

Measured effect, from the 399 passing entries in the CI cache of this host:

Check Median p90 Maximum
test 243 s 526 s 1435 s
security 98 s 450 s 1688 s
typecheck 57 s 239 s 856 s

Every other check has a p90 below 90 s. A full gate takes 2.5 minutes on a quiet host (#1752) and 7 to 15 minutes under the load of parallel agents. A timed test then fails (#2069, #2092), and the whole run starts again. The container also has a hard pids.max of 2048, so a burst of gates can fail to fork. AGENTS.md rule 5 says that a check which averages more than 5 minutes is a P0 bug.

Proposed Solution & Architectural Design

Add a host-wide admission limit for the gate. A gate that runs a CPU-heavy check waits for a free slot and then runs alone with the CPU. It does not run beside every other gate.

  • A slot is one lock file in <data dir>/ci-gate-slots/. Every worktree of the repository shares that directory (resolve_data_path).
  • filelock.FileLock(timeout=0) takes a slot. The lock is fcntl.flock, so the operating system frees it when the holder exits or dies. A killed agent cannot leak a slot.
  • A gate tries each slot, then waits and tries again. While it waits, it prints which worktree and process hold the slots.
  • A check is heavy when its p90 is above 200 s in the table above: test, security and typecheck. CheckSpec gets a heavy flag. A run needs a slot only when it selects a heavy check. The pre-push hook (--only lint,format,actionlint,zizmor) takes no slot and never waits.
  • devops ci test and devops ci coverage take a slot too, because they start the same workers.
  • --dry-run and a cached verdict take no slot.
  • One setting, ci.gate_slots, sets the number of slots. The default is max(1, cpu_count // 8), which is 2 on a 16-CPU host. DEVOPS_CLI_CI_GATE_SLOTS sets it from the environment.
  • GitHub-hosted runners have 4 CPUs, so the default there is 1 slot and a single job never waits.

Target Subsystem

SDLC, Git & PR Governance

Existing Tool Considered

  • filelock (tox-dev, maintained) covers the lock. It is already in uv.lock as a dependency of tldextract, so the change adds no package. It has no counting semaphore, so a loop over N lock files supplies the count (about 15 lines).
  • GNU parallel sem is a counting semaphore, but it is a host package. CI and the devcontainer must not need a host install (the project rule for runners).
  • systemd-run with CPU quotas needs systemd, which the devcontainer does not run.
  • POSIX named semaphores (posix_ipc) keep their count when a holder dies, which leaks slots.
  • A merge queue does not apply: ADR 0014 records that a user account owns the repository.

Feasibility

  • filelock 4.2.4 calls fcntl.flock(fd, LOCK_EX | LOCK_NB) (filelock/_unix.py).
  • A scratch probe held a slot in a child process, refused a second acquire, killed the child with SIGKILL and then took the slot 1 ms later.

Activity

  1. added
    source/agent
    type/infra
    on Oct 27, 2026
  2. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/infra. The change affects infrastructure and CI systems, specifically how gates are managed in the CI environment.
    • Priority: P1-High. This issue impacts CI performance and stability under load, causing test failures and requiring retries.
    • Value: High. Improving CI performance and reducing test flakiness benefits all developers and users of the project.
    • Effort: Medium. The implementation requires changes to how CI gates are scheduled and managed, involving file locking and configuration handling.
    • Related: ci(gate): checks of committed files and tool configuration run as devops ci rows, not as pytest tests that start the tool #2164, which asks for a different change. Both items deal with CI checks but the candidate focuses on limiting parallel CPU-heavy runs while #2164 reorganizes how committed file checks are run.
  3. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Reopened. Pull request #2339 carried only the OpenSpec plan, and its Closes #2336 closed this issue before any code existed. The code follows in a new pull request.

  4. added 3 commits that reference this issue on Oct 27, 2026
    518db63
    a3b164d
    c845583
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source/agenttype/infra

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions