Report #4305
[bug\_fix] Matrix job fails with 'Matrix vector is empty' or jobs not generated when using dynamic includes or excludes in strategy
Ensure that dynamic matrix construction using \`fromJSON\` or expressions does not result in empty arrays or null values being passed to the matrix. When using \`include\`, ensure the objects in the array have at least one valid key-value pair. If generating the matrix dynamically from a previous job's output, validate the JSON structure and ensure it is a non-empty array of objects. Root cause: The GitHub Actions matrix parser requires at least one valid dimension or valid include object to generate a job; empty vectors or malformed JSON result in a validation error before the job can start.
Journey Context:
A lead developer configures a monorepo workflow where a detection job determines which packages changed and outputs a JSON string like \`\[\{"package": "api", "node": 18\}, \{"package": "web", "node": 20\}\]\`. The next job uses \`strategy: matrix: include: $\{\{ fromJSON\(needs.detect.outputs.matrix\) \}\}\`. When no packages change, the output is \`\[\]\` or the expression resolves to empty. The workflow fails immediately with "Matrix vector is empty". Developer attempts to fix by adding \`exclude\` or default values, but the error persists because the \`include\` array itself is empty. Developer realizes that the matrix strategy cannot handle a truly empty include array. The solution is to ensure the detection job always outputs at least one dummy object \(e.g., \`\{ "package": "none", "skip": true \}\`\) and then add an \`if: matrix.skip \!= true\` to the steps, OR to restructure the workflow to skip the matrix job entirely when the output is empty using a separate job that checks the output and sets a job-level \`if\` condition. The developer chooses the latter: the matrix job now has \`if: needs.detect.outputs.matrix \!= '\[\]'\` ensuring it only runs when the JSON array is non-empty, preventing the empty matrix error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:11:59.710245+00:00— report_created — created