Fix random ci test failure

From dotnet/macios · View interactive version

Fix random ci test failure is an AI agent skill from the GitHub repository dotnet/macios. Investigate and fix flaky/random CI test failures in dotnet/macios. Trigger on GitHub issues describing intermittent test failures, CI postmortem issues, or when asked to fix a flaky test. Analyzes test code, identifies root causes (shared state, environment dependencies, race conditions), and appli

How to use this skill

Skill file

Fix Random CI Test Failure

Investigate and fix flaky CI test failures reported in GitHub issues for dotnet/macios.

When to Use

Workflow

1. Gather Failure Context

Read the GitHub issue to extract:

If build URLs are provided, inspect logs for additional context (stack traces, timing info).

2. Locate and Analyze the Test

Find the test source file:

grep -r "TestMethodName" tests/

Read the full test method and all helper methods it calls. Understand:

3. Identify Root Cause Category

Common flaky test root causes in this repo:

Shared State / Resource Conflicts
Environment-Dependent State
Unhandled Error Codes
Race Conditions / Timing
LAContext / Authentication Issues (Security tests)

4. Apply the Fix

When fixing:

  1. Prefer unique identifiers over shared ones. Use Process.GetCurrentProcess ().Id, Guid.NewGuid (), or {bundleId}-{testType}-{pid} patterns for resource identifiers.
  1. Create minimal query records. For search/delete operations, don't attach unnecessary attributes (like LAContext) that can cause intermittent errors.
  1. Handle all status codes. Never silently return false for unexpected error codes. Either handle them with a fallback path or fail with a descriptive assertion message.
  1. Add diagnostic logging. Use TestContext.Out.WriteLine to log operation results that would help diagnose future failures.
  1. Clean up legacy state. If renaming identifiers, also clean up entries from old names that may linger on CI agents.
  1. Always clean up in finally blocks. Ensure test resources are released even on failure.

5. If the Fix is Unclear

If you cannot determine the root cause with available information:

  1. Add diagnostic logging to capture operation results (status codes, error details) in future failures.
  2. Log the initial state at test start (e.g., does the resource already exist before the test runs?).
  3. Include all relevant status codes in assertion failure messages.
  4. Explain to the user what additional information the logging will provide and what hypotheses it will help test.

6. Create the PR

Key Patterns in This Repo

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.