GuidesUpdated

Why do my agent tests pass locally but fail in GitHub Actions?

Compare the PR commit, first failing CI step, runner, install, environment and test command before you change code or rerun a GitHub Actions job.

On this page

An agent reports passing tests, but the PR's GitHub Actions check is red. The two results only compare once they share a commit and command. The example is a Node app where the agent tested against existing dependencies while CI failed on a clean install. In other languages, follow the same order with your own workflow and package manager.

Canopy pull request and running project beside the agent workspace
Canopy pull request and running project beside the agent workspace

Pin the failed run to the PR's current commit

Open the failing run and note its run ID, event, commit SHA, job and attempt. Compare that SHA with the PR's latest head and the agent's checkout. An old failure can stay visible after a newer commit, and an old local log can predate the agent's last edit. A rerun repeats the original SHA and ref, so it never tests a newer commit.

  • Tell apart a failed run, a cancelled run and a job that never started.
  • Don't declare a fix from a rerun of the old SHA.

Find the first failing step

Read the job from setup to its first actionable error. An install failure needs a different fix from a type error, assertion or timeout. Capture the command, a short sanitized error, runner OS, tool versions and matrix entry. GitHub-hosted jobs start on fresh runners, so the agent's local dependencies and untracked files aren't there. Compare the workflow file and lockfile in the commit that ran.

Compare local and CI evidence for one failed PR run.
BoundaryAgent's local evidenceGitHub Actions evidence
CodeCheckout branch and exact commitRun SHA and PR head
InstallPackage manager and local dependency stateInstall command and committed lockfile
RuntimeOS, language version, environmentRunner image, matrix entry, setup step
CheckCommand and result after final editFirst failing step and error

Reproduce the CI boundary locally

In the Node example, CI runs npm ci; the agent ran npm test with an old node_modules. npm ci does a clean install and fails if package.json and package-lock.json disagree. Run the repository's clean-install and test commands in a disposable checkout or container. If the lockfile is out of sync, update it and review the dependency diff; don't disable the check.

If the test fails only in CI, compare language version, OS, case-sensitive paths, timezone and external services one at a time.

  • Use the exact workflow command, not a local substitute.
  • Check untracked and ignored files your local run depends on.

Treat missing configuration as an access question

If CI reports a missing variable or credential, check whether the workflow should have it for this event. GitHub withholds most secrets from fork PR workflows, and reusable workflows need secrets passed explicitly. Never paste a production secret into a PR, prompt or log. Ask the owner for a safe fixture, restricted test service or separate trusted workflow. Switching to a privileged event to expose secrets is a serious security risk.

  • Record the secret's name and scope, never its value.
  • The owner approves any change to CI permissions.

Give the agent one failure, then check the new head

Send the agent the run URL, SHA, first failing step, sanitized error and your comparison. Ask it to explain the difference before editing, then make the smallest fix and run the equivalent check. In Canopy, keep the session, branch, PR and services in view while you read the diff. Review the checks on the new head, and test the user journey if CI doesn't cover it.

  • A rerun that passes with no code change points to flakiness or an external service.
  • If a fix changes test expectations, check the test still catches the original failure.

Copyable resources

Local-pass, CI-fail handoff

Share only sanitized errors and configuration names; never paste credentials or private fixture data.

PR URL and latest head commit: [ ]
Failed run ID / attempt / SHA: [ ]
Runner OS, image, language version, matrix entry: [ ]
First failing job, step, command, short error: [ ]
Agent local commit and command/result after final edit: [ ]
Workflow install command and committed lockfile: [ ]
Difference to test first: [ ]
Disposable local reproduction and result: [ ]
Fix owner and changed files: [ ]
New PR head and its check result: [ ]
Feature journey still passes: [ ]

Frequently asked questions

Why did npm test pass locally while npm ci failed in Actions?

Your local test may use packages already in node_modules. npm ci does a clean install and rejects a mismatch between package.json and the lockfile. Read the install log and committed files before changing the test.

Will rerunning the failed Actions job test my latest PR commit?

No. A rerun uses the original event's SHA and ref. Check the run attached to the latest PR head.

Should I add my API key to Actions to make a fork PR pass?

No. Don't expose a production key to an untrusted PR; GitHub withholds most secrets from fork-triggered workflows. Ask the owner for a fixture, restricted test service or separate trusted check.

Can the agent fix CI by skipping the failing test?

Only if the team decides the test is invalid and documents why. Check what behavior it guarded and keep an equivalent check before the PR is ready.

More questions and answers →

Sources and further reading