← Back to all stories

Debug a Failing CI Build with AI, Safely

Turn a CI failure into a small, reviewable fix: isolate the first error, test the diagnosis, and keep repository secrets out of the prompt.

Capture the useful error and create a minimal reproduction before changing code. Diagnose it locally first; an approved AI tool is optional.

Start with evidence, not a vague prompt

A failed build is only useful once you separate the first real error from the cascade below it. Copy the command that failed, the package manager and runtime version, the first error block, and the smallest relevant file. Leave out access tokens, customer data, private URLs, lockfiles, and the rest of the repository.

The goal is not to ask an AI assistant to repair everything. It is to turn a confusing failure into two or three concrete hypotheses you can test yourself. You can investigate the packet yourself or use a model your team already permits. Switching providers or buying inference is optional.

  • The exact command and its exit code
  • The first actionable error, plus 20 to 40 lines of context
  • Runtime, package-manager, framework, and dependency versions
  • Only the smallest code excerpt needed to understand the failure
  • One stopping point: end the request after a diagnosis, before asking for a patch
  1. Record the command, versions and first failure in a disposable reproduction. If you choose OpenCode, complete the linked setup and denied-action check first; another approved tool or manual diagnosis also works.
  2. If using a model, copy the diagnostic prompt below into the approved session. Replace each bracketed field with the failing command, versions, and approved redacted excerpts. Submit once and save the hypotheses.
  3. In your original project terminal, run one proposed verification after reviewing what it changes. Record its result before requesting a patch.

Make a diagnostic request the model can answer

Ask for ranked hypotheses, evidence from the log, one low-risk verification step for each hypothesis, and no code changes. This constrains the output to investigation instead of encouraging a confident but unreviewed patch.

Use a model access key with the smallest practical scope and keep it in your deployment secret manager or local environment, never in the prompt, source code, or browser bundle. DigitalOcean Serverless Inference accepts direct model requests, so a short server-side route is enough for this workflow.

TEXT
You are reviewing a build failure. Do not suggest edits yet.

1. Identify the earliest likely root cause.
2. List up to three hypotheses in likelihood order.
3. Cite the log line that supports each one.
4. Give one reversible verification step per hypothesis.
5. State what information is missing.

Environment: [runtime and package versions]
Command: [failed command]
Log excerpt: [redacted first error]
Relevant file: [small redacted excerpt]

Set up an AI coding agent with Serverless Inference

Verify the diagnosis before accepting a fix

Run the suggested verification yourself. For example, inspect the resolved dependency version, run the failing command against a clean install, or check whether a configuration option changed names. If the evidence does not support the leading hypothesis, send the new result back and ask the model to revise its ranking.

Only after the cause is clear should you request a patch. Limit it to one file where possible, ask for a unified diff, and compare it with the framework documentation. Run the original build command and the narrowest relevant test after applying it.

A reproducible module-contract failure

This purpose-built local fixture models an import/export mismatch that can stop a Node CI test job before assertions run. It was run with Node.js 24.19.0 on October 8, 2026. It is not a report of a production incident or an AI-generated diagnosis.

Save these files together, or download format.mjs and the deliberately failing format.test.mjs.

format.mjs
export default function formatLabel(value) {
  return value.trim().toUpperCase();
}
format.test.mjs
import test from 'node:test';
import assert from 'node:assert/strict';
import { formatLabel } from './format.mjs';

test('formats a label', () => {
  assert.equal(formatLabel(' hello '), 'HELLO');
});

Run node --test format.test.mjs. The observed first error was:

TEXT
SyntaxError: The requested module './format.mjs' does not provide an export named 'formatLabel'

The command exited 1. A missing dependency is a plausible initial hypothesis, but this error names a resolved local module. Opening format.mjs shows a default export, while the test requests a named export. That inspection rejects the missing-package explanation for this fixture; reinstalling packages would not repair the contract.

Replace only the import line with import formatLabel from './format.mjs';, then rerun the same command. The corrected local run exited 0 with one passing test. Keep both logs and the one-line diff. No model call was used to establish this result.

Node ECMAScript modules · Node test runner

A practical boundary for AI-assisted debugging

Do not paste production logs containing personal data, credentials, signed URLs, internal hostnames, or proprietary source files. Redact values rather than replacing the whole log with a summary, because structure is often the clue that matters.

Treat the model as a fast second set of eyes. It can reduce time spent on familiar dependency, type, and configuration failures, but the person who understands the codebase should still choose and review the fix.

Frequently asked questions

Can an AI assistant safely debug a private repository?

It can help with a deliberately small, redacted diagnostic packet. Do not send secrets, customer data, private URLs, or broad source archives. Keep the request to the failing command, relevant versions, a redacted log excerpt, and the smallest code sample needed.

Should I let the assistant apply the fix automatically?

Not for an unfamiliar failure. First ask for hypotheses and verification steps. Once you understand the cause, request a small diff, review it, and validate it with the original build and a focused test.

What proves that an AI-assisted build fix is ready to review?

Keep the original failing command, the small verification that supported the cause, and the same command after the patch. Add the narrowest relevant test when one exists. A persuasive explanation or a changed error message is not enough on its own.