Skip to content

Watch for contract drift in the background

Before you begin

Plan
Included in Pro and Team. How plans and limits work
Role
Viewer or higher to see the setting and contract health and Admin or higher to turn background checks on or off.
You need
  • A project with an OpenAPI contract
  • Request logs stored for the project

Find out when your upstream or your mocks start answering in a way the contract does not allow, without checking logs by hand: MockHub checks a sample of new responses on its own and keeps the findings.

  1. Open the project’s OpenAPI tab.

  2. In Background checks, turn on Check new traffic in the background.

  3. Under Which responses, tick Responses from your upstream, Responses from your mocks, or both. A project that forwards to an upstream starts with the first ticked, and any other with the second, since it has no upstream responses to sample.

  4. Select Save background checks.

The first run happens about 15 minutes later, and later runs every 15 minutes. Next run and Last run show when, and what the last run did, such as Checked a sample of the new traffic. with each kind’s counts, for example 12 sampled, 3 invalid.

Only traffic logged after you turned the checks on is sampled. The checks use the active revision, and each one is recorded as the log’s latest check against it, so coverage shows it as checked … by a background check.

Each run looks at the logs stored since the last run, leaving out the last two minutes, which may not be stored yet, and at most the 24 hours before. It reads the newest 5,000 of each kind and checks at most 20 of them, spread across methods, paths and statuses. Everything it reports is therefore a sample.

Some responses are never checked, because they say nothing about the contract:

  • An upstream response with a 5xx status or 429, which includes MockHub’s own 502 when your upstream could not be reached.
  • Any response a chaos profile shaped.
  • A mock response from a request no mock matched.

A run that reaches its time limit is marked partial: it keeps what it checked, and the responses it did not reach are not tried again. The checks spend the workspace’s contract-check allowance, the one bulk checks and AI assistants spend. A run is skipped, and tried again at the next run, when less than half of the minute’s allowance would remain.

  1. Open the project’s Insights tab.

  2. Choose Contract health, then a period such as Last 7 days.

Each kind of response has a tile headed Invalid, of sampled checks with a result, with the sample beside it, such as 40 sampled · 6 invalid · 2 inconclusive. It also says how many checks were not reached and how many runs stopped early or sampled from only the newest 5,000 logs. The chart shows valid and invalid checks per hour or day, in UTC. The table lists each operation with the checks that failed, such as Body 5, its First violation in the period, and its Latest violation as the run recorded it, with View request log opening that exact request. If it has been deleted or expired, the log view says it is no longer retained.

Refresh contract health, the round button beside the period, reads the latest runs. A notice explains when the period is longer than your plan keeps the runs. While background checks are off, the view says “Background checks are off.” and links to the OpenAPI tab.

An AI assistant reads the same figures with the MCP tool get_contract_health, which needs a personal API token; see MCP workflows.

Contract health reads the runs MockHub kept, so it is available on every plan, survives a deleted log, and stays after a downgrade. The log a violation names may be gone, or may have been checked again since.

Create an alert rule with Contract violations; see Get alerted when traffic changes. The link in its email opens Contract health.

  • The percentage is the share of sampled checks with a result that were invalid, never the share of all traffic. A check that is Inconclusive because logging cut the response short has no result.
  • A run does not check every request, and groups of requests may go unsampled for some time.
  • Background checks read responses only. To check requests as they arrive, use Report mode.
  • Background checks need a plan with OpenAPI contract checks. Turning them on or changing what they check is refused without one. The setting is kept if the plan changes, and nothing runs.
  • A run is skipped when the project does not store request logs, has no contract, or its workspace is paused. The panel names the reason.
  • Three failed runs in a row show a warning.
  • Background checks are not part of config as code (the CLI), so a clone of a project starts with them off.
  • Run records are kept as long as the plan keeps insights.

Report a problem with this page