CI Rebuilds Test Matrix: Does the Agent Get a Vote?
No, in standard CI/CD practice, the agent does not get a vote in whether a rebuild of the test matrix is triggered. The decision to rebuild is controlled by the pipeline configuration, the CI server, and human-defined rules—not by the agent that executes the jobs.
Background: What Is a Test Matrix and Why Rebuild It?
A test matrix is a set of configurations that define multiple combinations of parameters for running tests—for example, different operating systems, browser versions, or database backends. Each cell in the matrix is a separate job that runs the same test suite under a different environment. Rebuilding the matrix means re-running those jobs, either partially or fully, after a change in the codebase, a dependency update, or a configuration tweak.
The need for a rebuild often arises when a test fails intermittently (flaky test), when a new commit is pushed, or when the CI system decides to re-run a previously failed job. The agent—the machine or container that actually executes the test commands—has no authority to decide whether a rebuild happens. It simply executes the instructions it receives from the CI orchestrator.
How CI Decides to Rebuild the Matrix
The rebuild decision is made by the CI server (e.g., Jenkins, GitLab CI, GitHub Actions) based on triggers defined in the pipeline configuration file (e.g., .gitlab-ci.yml, .github/workflows/*.yml, Jenkinsfile). Common triggers include:
- A push to a specific branch (e.g.,
mainordevelop) - A pull request being opened or updated
- A manual trigger by a developer via the CI interface
- A scheduled cron job (e.g., nightly builds)
- A dependency update detected by a bot (e.g., Dependabot)
Once a trigger fires, the CI server compiles the matrix definition and schedules the jobs. The agent then picks up a job and runs it. If a job fails, the CI server may automatically re-run it (auto-retry) or wait for a human to click “Retry.� The agent has no say in this process; it is a passive executor.
How the Agent Fits In (and Its Limits)
The agent’s role is to provide a runtime environment for the job. It pulls the code, installs dependencies, runs the tests, and reports the results back to the CI server. The agent can influence the outcome of a rebuild through its configuration (e.g., environment variables, available tools), but it cannot initiate or veto a rebuild. Even if an agent crashes mid-job, the CI server decides whether to re-queue the job on another agent.
Some CI systems allow the agent to send signals back to the server (e.g., exit codes, custom status messages), but these are interpreted by the server according to predefined rules. For example, a test script might exit with code 42 to indicate “retry,� but that only works if the pipeline configuration explicitly maps that exit code to a retry action. The agent is not making a decision; it is following a protocol.
Common Misconceptions and Real-World Scenarios
A frequent misunderstanding is that an agent can “vote� by failing a test and thus forcing a rebuild. In reality, a failed test triggers a rebuild only if the CI server is configured to retry on failure. By default, most CI systems mark the job as failed and stop, unless auto-retry is enabled. Even then, the retry is a server-side policy, not an agent action.
Another scenario is when a developer manually re-runs a failed job from the CI dashboard. That action is a human decision, not an agent vote. Similarly, if a pipeline uses a matrix generation script (e.g., a script that dynamically creates the matrix based on file changes), the agent runs that script, but the script’s output is evaluated by the server to decide which jobs to create.
How to Configure Rebuilds (Without Agent Input)
To control rebuild behavior, you edit the CI configuration file. Here are common patterns:
- Auto-retry on failure: Set
retry: 2in a GitLab job to allow up to 2 retries. In GitHub Actions, usejobs.<job_id>.strategy.fail-fast: falseand acontinue-on-errorflag to control behavior. - Manual approval: Use environments with required reviewers in GitLab or GitHub to pause the pipeline until a human approves.
- Conditional rebuilds: Use
rules:(GitLab) orif:(GitHub) to only run certain matrix cells when specific files change. - API-triggered rebuilds: Use the CI API to programmatically re-run a pipeline, but that is still a server call, not an agent decision.
Remember: the agent is just a worker. All decision-making logic lives in the pipeline definition and the CI server’s scheduler.
Comparison: Agent vs. Orchestrator Responsibilities
To clarify, here is a breakdown of who does what in a typical CI run:
- Orchestrator (CI server): Parses the configuration, schedules jobs, tracks status, applies retry policies, and sends notifications.
- Agent: Executes the job’s commands, manages its local environment, and reports logs and exit codes.
- Human: Defines the pipeline, triggers manual runs, and reviews results.
The orchestrator is the only component that can decide to rebuild a matrix. The agent’s “vote� is limited to the exit code it returns, which the orchestrator interprets according to the configuration. If the configuration says “exit code 1 means fail and stop,� then a failed test will not trigger a rebuild unless a retry policy is set.
Costs and Safety Considerations
Rebuilding a test matrix can be expensive in terms of compute time and cloud costs. Each matrix cell runs in a separate environment, so a matrix with 10 cells and 3 retries can consume 30 job runs. To minimize costs, use fail-fast to stop the matrix when one cell fails (if that is acceptable for your workflow), and set retry limits to avoid infinite loops.
Safety-wise, be cautious with auto-retry on flaky tests. If a test is genuinely broken, retrying will just waste resources. Instead, use a flaky-test detection tool or quarantine the test. Also, ensure that agents are properly isolated so that a rebuild does not carry over stale state from a previous run.
Frequently Asked Questions
Can an agent force a rebuild by crashing?
No. If an agent crashes, the CI server marks the job as failed and may retry it based on the configured retry policy. The agent itself cannot request a rebuild; it can only fail.
Is there any CI system where the agent has a vote?
Not in mainstream systems. Even in distributed systems like Jenkins agents, the agent only executes. The master (or controller) makes all scheduling decisions. Some custom scripts might give the agent a say, but that would be a non-standard design.
How do I stop a matrix from rebuilding too often?
You can limit triggers by using rules or only/except to specify which branches or paths trigger a rebuild. You can also disable auto-retry and require manual approval for re-runs.
What happens if an agent is offline when a rebuild is triggered?
The CI server will queue the job until an available agent matches the job’s tags or labels. If no agent is available, the job stays pending. The rebuild does not fail immediately; it waits for a suitable agent.
Does the agent’s operating system affect the rebuild decision?
Only indirectly. The matrix defines which OS to run on, and the agent must match that label. If no agent with that OS is available, the job cannot run, but the decision to schedule it is still the server’s.
Can a developer give the agent a “vote� in a rebuild?
Not directly, but you can design a custom script that runs on the agent and calls the CI API to trigger a new pipeline. That would be a workaround, but it is not a native feature and is generally discouraged because it can create infinite loops.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.