# Define DSM Operating Contracts

## When to use

Use this task before release to define monitoring, security, readiness, shutdown, and capacity validation.

## Inspect first

- Locate diagnostics, metrics, traces, security extensions, lifecycle state, and JMH fixtures.
- Record how the deployment platform determines readiness, stops traffic, and completes shutdown.
- Read [observability](/en/19-observability.html) through [capacity evidence](/en/22-capacity.html).

## Required inputs

Obtain the threat model, key custody, metrics backend, on-call ownership, rollout process, target load, and capacity criteria.

## Implementation path

1. Combine diagnostics, low-cardinality metrics, and traces for replica divergence.
2. Validate admission, authentication, encryption, replay protection, rate limiting, and audit separately.
3. Open readiness only when the runtime is `RUNNING` and dependencies are available.
4. Stop new traffic, freeze the registry, drain, and close the runtime in that order.
5. Run JMH or scenario benchmarks with a fixed environment, parameters, and raw results.

## Constraints

- Example keys and local backends do not establish production key custody or on-call capability.
- A microbenchmark alone cannot establish a production capacity SLA.
- Runtime state does not replace load-balancer and drain behavior.

## Failure patterns

- Placing high-cardinality business keys in metric labels.
- Combining encryption and identity authentication into one gate.
- Reporting only mean latency without environment, parameters, percentiles, and raw results.

## Validation

Run security rejection paths, readiness and shutdown tests, and a capacity smoke with raw output. Record target-environment acceptance separately.

## Evidence

- [Validation scopes](/agent/en/v/0.1.2/reference/validation-scopes.md)
- [Safe change boundaries](/agent/en/v/0.1.2/policies/safe-change-boundaries.md)
- [Pinned DSM source](https://github.com/xbdotl/dsm/tree/505e7557da94e3f74da84ecf75bc8a9282732e4f)
