Skip to main content

Labels, deletes and retention

A CI pipeline records a version for every build, so a busy pacticipant collects thousands of versions nobody will deploy again. This page covers three things you can do about that, and one way to keep pacticipants organised:

  • Labels group pacticipants (team-billing, tier-1).
  • Delete removes a version or a whole pacticipant. A delete can be undone for the workspace's restore window (30 days unless you change it).
  • Clean-up keeps the versions your rules name and removes the rest every night. You always see what it will remove before it removes anything. A retention run does the same once, on demand.
  • Purge removes deleted data for good once the restore window has passed.

The clean-up rules, their preview and Recently deleted are on Contracts → Settings → Clean-up (see Set the clean-up rules), and in apiome pact retention show|set|preview. Labels and single deletes are on the Pacticipants pages. Everything is also in the Pacticipants API and the Pact Broker API. Both take an API key, in X-API-Key or as a bearer token.

Set the clean-up rules​

Contracts → Settings opens on the Clean-up tab. It says what is kept, shows what the rules would remove if they ran now, and lists what was deleted recently.

The Clean-up tab: keep rules as sentences with a count each, the nightly switch and restore window, If it ran now with 412 of 1,904 versions, and Recently deleted with Restore.The Clean-up tab: keep rules as sentences with a count each, the nightly switch and restore window, If it ran now with 412 of 1,904 versions, and Recently deleted with Restore.
Route/ade/dashboard/pacts/settings
  1. Read what is kept. Each rule under What to keep is a sentence with how many versions it keeps today. A version that any rule keeps stays:

    RuleKeeps
    Every version deployed or released anywhereAlways on. It has no remove button, and no rule set can turn it off.
    The latest N versions on each pacticipant's main branchThe newest N on the branch set as the pacticipant's main branch. A pacticipant with no main branch keeps nothing by this rule.
    The latest N on every other branch, for D daysThe newest N of each other branch, while they were recorded in the last D days. Leave the days empty to keep them however old they are.
    Anything tagged …Every version carrying one of the tags. Separate several with commas.

    Each pacticipant's latest version is also always kept.

  2. Change a rule. Type a new number in its sentence, click the × to remove it, or click Add a rule to bring one back.

  3. Check the preview. If it ran now redraws as you edit: how many versions would go, with how many pacts and verification results. Click See the list for the versions, per pacticipant. The preview is planned by the same code as the nightly run, so it lists exactly what the next run removes, unless something is published, deployed or deleted in between.

  4. Turn on Run clean-up nightly. While it is off, nothing is ever removed, and the preview says Nothing is removed while clean-up is off. When it is on, the clean-up runs once a night after 02:00 UTC.

  5. Choose Keep deleted items restorable for — 7, 30 or 90 days. This is the workspace's restore window: a deleted version or pacticipant is purged when it has passed.

  6. Click Save rules. Discard goes back to the saved rules.

A rule set that would remove a deployed or released version cannot be saved: the answer is Deployed and released versions are always kept.

Recently deleted lists the deleted pacticipants, and the versions deleted on their own, newest first: who deleted each (Clean-up for the nightly run), what comes back with it, and when it is purged. Click Restore to bring one back. A restored version comes back with its pacts, results and deployments; a restored pacticipant with the versions deleted with it.

Saving the rules and Restore need the Contracts admin permission (pacts:delete: Admin or Owner). Everyone else sees the tab read-only, with a note saying so.

From the CLI​

apiome pact retention show
apiome pact retention preview --main-branch-latest 5 --other-branch-latest 1 --other-branch-days 90
apiome pact retention set --main-branch-latest 5 --other-branch-latest 1 --other-branch-days 90 \
--keep-tag keep --nightly --restore-days 30

set changes only the flags you give and keeps the rest as saved; 0 removes a rule (--main-branch-latest 0), and --no-tags removes the tag rule. preview without flags previews the saved rules; with flags it previews them changed by the flags, without saving. The Clean-up tab's The same, from anywhere block shows the command for what the form holds. See apiome pact retention.

From the REST API​

RequestWhat it doesNeeds
GET /v1/tenants/acme/pact-retention/policyThe rules, the nightly switch, the restore window, the last and next nightly run, and can_edit.pacts:view
PUT /v1/tenants/acme/pact-retention/policyReplace the rules (a field left out takes its default).pacts:delete
POST /v1/tenants/acme/pact-retention/policy/previewWhat the saved rules ({}) or a draft ({"rules": {…}}) would remove now. Changes nothing.pacts:view
GET /v1/tenants/acme/pact-retention/deletedRecently deleted, newest first, a page at a time (limit, cursor).pacts:view
curl -X PUT https://api.apiome.dev/v1/tenants/acme/pact-retention/policy \
-H "X-API-Key: sk_live_…" \
-H "Content-Type: application/json" \
-d '{
"keep_main_branch_latest": 5,
"keep_other_branch_latest": 1,
"keep_other_branch_days": 90,
"keep_tags": ["keep"],
"nightly_enabled": true,
"restore_window_days": 30
}'

An unknown field, a repeated tag, or keep_other_branch_days without keep_other_branch_latest is refused with the reason; nothing is dropped silently.

Label pacticipants​

A label is a free-form name on a pacticipant. A pacticipant can carry any number of labels.

  1. Add a label.

    curl -X PUT https://api.apiome.dev/v1/tenants/acme/pacticipants/billing-service/labels/team-billing \
    -H "X-API-Key: sk_live_…"

    The answer is 201 when the label is new and 200 when the pacticipant already had it. A label may contain / (team/billing).

  2. List the pacticipants with a label: GET /v1/tenants/acme/pacticipants?label=team-billing.

  3. List every label in the workspace: GET /v1/tenants/acme/pacticipant-labels.

  4. List one pacticipant's labels: GET …/pacticipants/billing-service/labels. The answer comes a page at a time, by name: pass limit (1 to 200, default 50), and while has_more is true pass the answer's next_cursor as cursor to read the next page.

  5. Remove a label: DELETE …/pacticipants/billing-service/labels/team-billing.

The Pact Broker's label routes work too, so a script written for a Pact Broker runs unchanged:

Pact Broker routeWhat it does
GET …/pact-broker/labelsEvery label, under _embedded.labels.
GET …/pact-broker/pacticipants/label/{label}The pacticipants with that label.
PUT …/pact-broker/pacticipants/{p}/labels/{label}Add a label. 201 with a Location header when it is new.
GET / DELETE …/pact-broker/pacticipants/{p}/labels/{label}Read or remove one label.

A pacticipant's labels are also embedded in its Pact Broker document (_embedded.labels), and a contract webhook can send them with ${pactbroker.consumerLabels} and ${pactbroker.providerLabels}.

One difference from the Pact Broker: labelling a pacticipant that does not exist answers 404. The Pact Broker would create the pacticipant.

Delete a version​

curl -X DELETE "https://api.apiome.dev/v1/tenants/acme/pacticipants/billing-service/versions/3f2a9c1?reason=broken%20build" \
-H "X-API-Key: sk_live_…"

The answer is 204. Straight away:

  • The version is gone from every read. That includes its pacts, the verification results it published as a provider, and its deployments and releases. The matrix and can-i-deploy no longer see it.
  • A branch it headed falls back to the latest version still on that branch. A branch with no version left is hidden until a new version is recorded on it.
  • The version number is free. Publishing 3f2a9c1 again records a new version.
  • reason is kept with the delete and in the audit trail. It is optional, up to 500 characters.

DELETE …/pact-broker/pacticipants/{p}/versions/{v} does the same through the Pact Broker API.

In the console, open the pacticipant's Versions tab and choose Delete version from the row's ⋯ menu, or select several rows and click Delete. See Manage versions. From a pipeline, run apiome pact delete-version -a "Billing Service" -e 3f2a9c1 --reason "broken build".

A deployed version is protected​

A version that is currently deployed to an environment, or released and still supported, is refused with 409 pacticipant-version-in-use. The message names the version. Do one of these:

  • Record the undeployment first (pact-broker record-undeployment, or record-support-ended for a release), then delete.
  • Add force=true to delete it anyway. Its deployment disappears with it, so can-i-deploy will no longer count it as running there.

The Versions tab and apiome pact delete-version never send force. They say, for example, 3f2a9c1 is running in Production. Record its undeployment first.

Delete a pacticipant​

curl -X DELETE "https://api.apiome.dev/v1/tenants/acme/pacticipants/billing-service?reason=service%20retired" \
-H "X-API-Key: sk_live_…"

This deletes the pacticipant with all of its versions, and with them their pacts, verification results, deployments, branches, tags and labels. The handle is free again at once: publishing a pact that names Billing Service registers a new pacticipant. The project and the consumer it was bound to are not touched.

As with a version, a pacticipant with a deployed or released version is refused with 409 pacticipant-version-in-use unless you add force=true. DELETE …/pact-broker/pacticipants/{p} does the same through the Pact Broker API.

Restore what you deleted​

Everything you delete stays restorable for the workspace's restore window: 30 days unless you change it on the Clean-up tab.

  1. Find it. Add state=deleted to a list:

    To findRequest
    Deleted pacticipantsGET /v1/tenants/acme/pacticipants?state=deleted
    Deleted versions of a pacticipantGET …/pacticipants/billing-service/versions?state=deleted

    Each row has deleted_at, deleted_by_label, delete_reason and purge_after: when it goes for good. A version also has delete_cause: version if it was deleted on its own, pacticipant if it went with its pacticipant, or retention if a retention run deleted it.

  2. Restore it.

    # A version
    curl -X POST https://api.apiome.dev/v1/tenants/acme/pacticipants/billing-service/versions/3f2a9c1/restore \
    -H "X-API-Key: sk_live_…"

    # A pacticipant: by its id (from step 1), or by its handle
    curl -X POST https://api.apiome.dev/v1/tenants/acme/pacticipants/2f9c…/restore \
    -H "X-API-Key: sk_live_…"

In the console, anything deleted is listed under Contracts → Settings → Clean-up → Recently deleted, with Restore. A deleted version can also be restored from the pacticipant's Versions tab: click Deleted, then Restore on its row. See Restore a deleted version. A deleted pacticipant is restored from the Pacticipants page. From a pipeline, run apiome pact restore-version -a "Billing Service" -e 3f2a9c1.

What comes back:

  • A version comes back with its pacts, results and deployments. A branch it headed is headed by it again.
  • A pacticipant comes back with the versions that were deleted with it. A version you had deleted on its own before stays deleted; restore it separately. With several deleted pacticipants of the same handle, restoring by handle brings back the most recently deleted one.

A restore is refused with 409 pacticipant-restore-conflict when a live pacticipant has taken the handle, or a live version has taken the number, in the meantime. Delete that one first if you want the old one back.

Clean up old versions with a retention run​

A retention run is a one-off clean-up with rules you send in the request, rather than the saved clean-up rules. It keeps the versions you name and deletes the others. A version is kept when any of these is true:

RuleKeeps
AlwaysThe pacticipant's latest version.
keep.latest_per_branch: NThe newest N versions of each branch.
keep.latest_per_main_branch: NThe newest N versions of the pacticipant's main branch.
keep.latest_per_other_branch: N (with keep.other_branch_days: D)The newest N versions of every other branch (recorded in the last D days).
keep.deployed_or_released (on by default)Every version currently deployed or released.
keep.tags: [...]Every version carrying one of the tags.
keep.created_within_days: DEvery version recorded in the last D days.

A run always starts as a dry run, so you see the plan before anything is deleted.

:::note Imported history keeps its dates A version imported from another Pact Broker keeps the date the source recorded, so keep.created_within_days counts it from that date, not from the import. Read the dry run's plan before you apply a first retention run after a migration. :::

  1. Ask for the plan. dry_run defaults to true, so this deletes nothing:

    curl -X POST https://api.apiome.dev/v1/tenants/acme/pact-retention \
    -H "X-API-Key: sk_live_…" \
    -H "Content-Type: application/json" \
    -d '{
    "keep": { "latest_per_branch": 10, "created_within_days": 30 },
    "pacticipants": ["billing-service"],
    "reason": "monthly cleanup"
    }'

    The answer counts what each pacticipant keeps and why (kept_by), lists the versions it would delete (oldest first, up to 100 per pacticipant), and ends with a plan_digest. Leave out pacticipants to clean every pacticipant in the workspace.

  2. Check the plan. Look at deleted and the deletions of each pacticipant.

  3. Apply it. Send the same request again with "dry_run": false and the plan_digest from step 1:

    curl -X POST https://api.apiome.dev/v1/tenants/acme/pact-retention \
    -H "X-API-Key: sk_live_…" \
    -H "Content-Type: application/json" \
    -d '{
    "keep": { "latest_per_branch": 10, "created_within_days": 30 },
    "pacticipants": ["billing-service"],
    "reason": "monthly cleanup",
    "dry_run": false,
    "plan_digest": "sha256:…"
    }'

    The answer is the same plan with "applied": true.

If anything changed between the two calls, the run deletes nothing. That covers a version published, deployed or deleted in between. The answer is 409 pact-retention-plan-changed, with the new plan under detail.plan: check it and apply its own plan_digest.

A run deletes at most 5,000 versions, oldest first. remaining counts the ones left for the next run. A run reads at most 100,000 versions; for a larger workspace, name the pacticipants in groups.

Every deletion a run makes is a normal soft delete, with delete_cause: retention and the run's reason. You can restore any of them during the restore window.

Run it on a schedule. The simplest way is to save the rules and turn on Run clean-up nightly. To run your own rules from a scheduled CI job instead, make the two calls: ask for the plan, then apply its digest. Applying needs pacts:delete, so use an API key of an Admin or Owner.

How the purge works​

The retention sweep runs every 5 minutes. Once a night after 02:00 UTC it first runs the clean-up of each workspace that has it turned on. Then it removes for good every pacticipant and version deleted longer ago than its workspace's restore window, with its pacts, verification results and deployment records. A contract webhook limited to a purged pacticipant is removed with it, and so are its owner team and its entries in the Unowned findings report. After that, nothing can bring them back. A deleted pacticipant keeps its owner until then, so restoring it brings the owner back.

Who can do what​

ActionNeedsViewerEditorAdminOwner
Read labels, list deleted pacticipants and versionspacts:view✓✓✓✓
Ask for a retention plan (dry run), read the clean-up rules and their preview, list Recently deletedpacts:view✓✓✓✓
Add or remove a labelpacts:edit—✓✓✓
Delete or restore a version or a pacticipantpacts:delete——✓✓
Apply a retention run, save the clean-up rulespacts:delete——✓✓

Everything is audited. Every delete, restore, label change, applied retention run and purge writes an entry to the workspace's Access audit (pacts.version.delete, pacts.retention.apply, pacts.retention.policy for saved rules, pacts.retention.nightly for a nightly run, pacts.purge and so on), in the same transaction as the change, so neither happens without the other. The entry records who acted, the target, the reason and the counts. A dry run changes nothing and writes no entry. The rest of the Pact Broker's permissions are on Who can do what.

When something is refused​

StatuscodeWhat to do
400pacticipant-invalid-labelA label is 1–255 characters, with no leading or trailing space and no control characters.
400pacticipant-invalid-reasonA reason is at most 500 characters, with no control characters.
404pacticipant-label-not-foundThe pacticipant does not carry that label.
404pacticipant-not-found, pacticipant-version-not-foundNothing deleted or live by that name, or a pacticipant named in a retention run does not exist. A run never skips a name silently.
409pacticipant-version-in-useA version is deployed or released. Record the undeployment, or add force=true.
409pacticipant-restore-conflictA live pacticipant or version has the handle or number now.
409pacticipant-not-deletedYou asked to restore something that is not deleted.
409pact-retention-plan-changedThe plan moved since the dry run. Check detail.plan and apply its digest.
422pact-retention-no-selectorTurn on at least one keep rule. With deployed_or_released: false and no other rule, a run would keep only the latest versions.
422pact-retention-plan-digest-requiredSend the plan_digest of the dry run with dry_run: false.
422pact-retention-keeps-in-useDeployed and released versions are always kept: leave keep_deployed_or_released out or true.
422pact-retention-bad-cursorPass the next_cursor of the previous Recently deleted page as it was returned.
422pact-retention-too-many-pacticipants, pact-retention-too-many-versionsName at most 200 pacticipants, and fewer per run in a very large workspace.

For operators​

  • Migration V437 adds the deletion columns and the pacticipant_label table. It rewrites no existing rows.
  • Migration V456 adds pact_retention_policy (one row per workspace) and two partial indexes for Recently deleted.
  • APIOME_PACT_DELETION_GRACE_DAYS (default 30, at least 1) is the restore window of a workspace that never saved clean-up rules; a saved restore window replaces it for that workspace. The nightly clean-up and the purge run on the async-job retention tick.
  • If a workspace has more than 100,000 live versions, the nightly run is refused and deletes nothing. last_run.error on GET …/pact-retention/policy says so, and the tab shows it.