# Subscribe to Agent Lifecycle Requests

These instructions apply to the current Admin Console.

{% hint style="info" %}
Alerts are in early access and may not be available in your account. [Contact Contextual support](mailto:help@contextual.io) to request that Alerts be enabled for your tenant.
{% endhint %}

Lifecycle notifications report a requested action on an Agent or Worker. They do not confirm the action completed. Configure them as subscriptions, independently of threshold rules and the metrics connection.

| Template ID | Admin Console title | Signal |
| --- | --- | --- |
| `agent-crash-threshold-organization` | **Stop requested** | Stop requests. `stopCoverage: crash-protection` selects crash-protection requests; `any` includes other stop requests. |
| `agent-restart-requested` | **Restart requested** | Restart requests through the Admin Console or the API. Container restarts after a crash are not this signal. |
| `agent-deletion-requested` | **Deletion requested** | Deployment deletion requests. Check the deployment separately to confirm removal. |

The historical template ID `agent-crash-threshold-organization` refers to a subscription for Agent and Worker stop requests. Use the catalog's title, parameters, and version to identify a template's behavior.

## Configure a Subscription

In the Admin Console, select a lifecycle template under **Operate → Alerts → Templates**. Choose a destination. The default coverage is **All current and future Agents and Workers**. To narrow coverage, choose **Specific deployments** and pick the Agents or Workers under **Selected deployments**. Review the scope and destination before enabling the subscription.

### From an Agent

Open the agent's **Monitoring** tab and choose **Set up Stop requested**, **Set up Restart requested**, or **Set up Deletion requested**. Choose the destination, review the configuration, and enable it. This entry point fixes coverage to the current agent. Use the separate **Metrics** tab for [chart-based threshold alerts](https://docs.contextual.io/operate/alerts/create-alerts-from-charts.md).

**Existing notifications** shows recognized lifecycle routes with coverage labeled **This agent**, **All agents**, or **Shared with other agents**. With subscription-delete permission, you can delete a route that covers only this agent. Custom routing policies may also apply.

### Edit a Lifecycle Subscription

Open the **Monitoring** tab for an agent or a deployed Worker. Under **Existing notifications**, select **Edit** on the recognized lifecycle route. You can also open **Operate → Alerts → Destinations**, expand **Advanced routing**, and select **Edit** under **Notification routes**. The editor requires lifecycle authoring to be enabled, `contextual:alert-subscriptions:update`, and read access to subscriptions, destinations, rules, and agents.

Change the destination, agent coverage, or enabled state. For stop requests, you can also change stop coverage. Select **Review changes**, check which deployments the subscription will cover, then select **Save changes**. Editing a shared or all-agent route changes the saved subscription for every deployment it covers, even when you open it from a single deployment.

### Through the API

Render `POST /templates/agent-restart-requested/render` with:

```json
{
  "parameters": {
    "destinationId": "DESTINATION_ID",
    "agentIds": ["TEST_AGENT_ID"]
  }
}
```

The response has `kind: subscription`. Save its `config` directly with `POST /subscriptions`; do not create an `event-match` rule. Generic event-match rules are not evaluated by the supported authoring path.

## Verify Delivery

Perform an intended action on a test agent and inspect alert history and its delivery details. Lifecycle entries use `state: event`; they have no pending-duration or resolved transition. A matching event may still be silenced or fail delivery.

Read the event's intent and reason before describing its outcome. A stop request does not establish that a process stopped, and a deletion request does not establish that the workload or record was removed.

To stop future lifecycle notifications, delete an agent-only route from the agent's **Monitoring** tab, or disable or delete the subscription through the [configuration API](https://docs.contextual.io/tenants/tenant-apis/alerts-api/configuration.md). This does not change the agent itself. Lifecycle subscriptions have no recovery notification preference because events do not resolve.
