AI

AgentOps: test the emergency stop before enabling production writes

A production runbook for proving an AI agent emergency stop across new intents, in-flight tool calls, queues, backend operations and controlled recovery.

06 Nov 2026 aiagentopsagentsmcpmicrosoft-foundryautomationguardrailssecurityobservabilityincidentrunbookrollbackproduction

An internal operations agent can inspect Azure resources and submit a bounded restart after human approval. During a canary, the agent starts repeating the action because a delayed MCP response is interpreted as a failure. The team removes the write tool from the catalog and assumes production is safe. A queued call is still accepted by the execution worker, while another backend operation is already running.

This is the gap an emergency stop must close. Hiding a tool changes discovery; it does not cancel accepted work, revoke the execution identity, purge retries or prove which effects already happened. The running case uses an agent runtime, an MCP tool server, a durable queue and an automation backend. The runbook ends with a decision: keep writes blocked, reopen one canary path, compensate a partial effect or roll back the stop mechanism because it also disabled essential read-only diagnosis.

Define what the stop must contain

Treat the emergency stop as a control spanning the complete action path. Name each boundary and the owner who can operate it without deploying a new agent version.

yaml 01-agent-emergency-stop-contract.yml
control_id: agentops-write-stop-v1
scope:
agent: ops-assistant-prod
write_tools:
  - restart_deployment
  - apply_route_change
environments:
  - production

boundaries:
admission: reject new write intents
approval: invalidate unused approvals
tool_gateway: deny write tool calls
queue: stop dispatch and quarantine pending writes
worker: cancel before backend commit when supported
backend: deny new operations for the execution identity

preserve:
- read_only_inventory
- incident_evidence
- operation_status_lookup

success:
- no new backend operation after cutoff
- every accepted operation reconciled
- stop state visible to operators and agent
- recovery requires explicit approval

One switch may drive several enforcement points, but do not make one process its only authority. If the agent runtime is unhealthy or compromised, the backend still needs an independent deny path. Conversely, revoking a credential alone can break status queries and leave operators unable to reconcile an ambiguous action.

Freeze evidence before pressing the stop

Capture a UTC cutoff, the triggering conversation, intent and tool call identifiers, active approvals, queued messages and backend operation identifiers. Do not start by deleting conversations or queues. Their contents establish whether work existed before the stop and whether any effect appeared afterward.

json 02-emergency-stop-incident.json
{
"incident_id": "INC-AI-20261106-07",
"cutoff_utc": "2026-11-06T08:25:00Z",
"agent_release": "ops-assistant-2026.11.05.3",
"tool_catalog_version": "ops-tools-42",
"policy_version": "agent-writes-18",
"suspect_intents": ["intent-8041"],
"tool_calls": ["call-8041-1", "call-8041-2"],
"backend_operations": ["op-17391"],
"pending_queue_messages": 3,
"active_approvals": ["approval-551"],
"evidence_owner": "platform-on-call"
}

The cutoff is an analytical boundary, not proof that later events are invalid. A backend operation accepted before the cutoff may finish afterward. The investigation must distinguish a new intent, a retry of an existing intent and late completion of work already committed.

Stop new work at more than one boundary

Activate admission and tool-gateway denial first so no new write reaches the pipeline. Invalidate unconsumed approvals and pause queue dispatch. Then apply the backend deny control for the write identity or action class. Keep inventory and operation-status reads available through a separate permission where the architecture supports it.

text 03-stop-sequence.txt
1. Record cutoff UTC and current control versions
2. Reject new production write intents at the agent policy
3. Deny write tools at the MCP gateway or tool router
4. Invalidate unused approvals bound to the affected actions
5. Pause dispatch; quarantine, do not delete, pending write messages
6. Deny new backend operations for the execution identity or action
7. Request cancellation for work not yet committed
8. Preserve read-only status and evidence collection
9. Reconcile every accepted intent against backend state

Ordering reduces new exposure while preserving evidence. Backend denial must fail closed, but it should target the write capability rather than every token held by the server. Removing the entire service identity can also stop log export, status lookup or compensation tooling.

Tool discovery is not an enforcement layer. A cached catalog, direct MCP client, resumed conversation or queued worker may still know the old tool. The negative test must call the write path directly with a previously valid request and prove a policy denial before backend acceptance.

Reconcile in-flight and queued work

After the stop, build one ledger from intent to final effect. Queue depth alone is insufficient: a message may be invisible because a worker leased it, and a timed-out tool call may already have created a backend operation.

kusto 04-reconcile-agent-writes-after-cutoff.kql
let Cutoff = datetime(2026-11-06T08:25:00Z);
let IncidentEnd = datetime(2026-11-06T09:00:00Z);
AgentToolCallEvents
| where TimeGenerated between ((Cutoff - 15m) .. IncidentEnd)
| where Effect == "write" and Environment == "production"
| project TimeGenerated,
        IntentId,
        ToolCallId,
        ToolName,
        ApprovalId,
        QueueMessageId,
        BackendOperationId,
        Attempt,
        Result,
        PolicyDecision
| summarize
  FirstSeen=min(TimeGenerated),
  LastSeen=max(TimeGenerated),
  Attempts=max(Attempt),
  Results=make_set(Result, 10),
  Decisions=make_set(PolicyDecision, 10),
  BackendOperations=make_set(BackendOperationId, 10)
by IntentId, ToolName, ApprovalId
| extend StartedAfterCutoff = FirstSeen > Cutoff
| order by LastSeen desc

Adapt the table to the telemetry pipeline and join it with the queue and backend audit logs. For every intent, assign one state: never admitted, denied, quarantined, accepted but not started, running, completed, failed without effect, failed with partial effect, cancelled or unknown. Unknown keeps production writes blocked.

Do not replay quarantined messages during containment. An approval may have expired, the target may have changed, or the original request may already have succeeded through another attempt. Reconciliation comes before retry.

Handle partial effects as backend recovery

An emergency stop cannot undo a committed action. If the backend changed one route before a second step failed, recovery follows the backend’s rollback or compensation contract. The agent must not improvise an inverse tool call.

Record the before state, actual state, desired safe state, operation ID and compensation owner. Use idempotency keys to identify duplicates, but verify the resource state directly. A single operation ID does not prove that every downstream effect completed.

Keep the stop active while compensation runs through a separately approved path. Otherwise the same agent can issue new writes while operators are restoring state. If the only compensation path uses the disabled tool, authorize one exact operation with target, expiry and approver rather than reopening the whole catalog.

Exercise the stop before production needs it

Test the control with a side-effect-free canary and a disposable target. The exercise must include work at different stages, not only a fresh rejected call.

yaml 05-emergency-stop-evaluation.yml
cases:
- id: new_write_after_cutoff
  setup: no_existing_work
  expected: denied_before_backend_accept

- id: queued_write_before_cutoff
  setup: message_waiting_for_dispatch
  expected: quarantined_and_not_started

- id: worker_leased_not_committed
  setup: worker_paused_before_backend_commit
  expected: cancelled_or_backend_denied

- id: backend_accepted_before_cutoff
  setup: operation_running
  expected: status_reconciled_no_duplicate_retry

- id: cached_catalog_direct_call
  setup: client_uses_previous_tool_catalog
  expected: server_side_policy_denied

- id: read_only_diagnosis
  setup: status_lookup_during_stop
  expected: allowed_and_traced

gates:
post_cutoff_backend_operations: 0
unknown_intents: 0
duplicate_effects: 0
read_only_evidence_available: true

Measure detection-to-stop time, last accepted operation time and reconciliation time separately. A fast visible switch with an unreconciled queue is not a fast stop. Repeat the test after changes to the agent runtime, tool gateway, queue consumer, identity or backend authorization.

Reopen one path, then decide

Recovery is a new change. Pin the known-good agent release, tool catalog, policy and execution identity. Reissue approval for one canary intent; never reuse an approval invalidated by the stop. Start with a no-effect or disposable target, then prove one intent, one tool call and one backend operation.

Reopen production writes only when all intents are classified, no operation was accepted after the cutoff, partial effects are compensated, direct and cached calls fail closed, read-only diagnosis remained available and the canary produces one explainable effect.

Keep writes blocked when any intent is unknown, cancellation cannot be distinguished from completion, the backend lacks independent denial or the stop requires an application deployment. Those are control gaps, not reasons to accept residual risk silently.

Roll back the stop mechanism when it blocks the evidence or recovery path it was designed to preserve. Restore the previous read-only policy, not unrestricted writes, then repair the control. Roll back the agent release separately if it caused the incident; changing the model or prompt does not replace containment at the execution boundary.

Conclusion

An AgentOps emergency stop is a coordinated state transition, not a hidden button in the tool catalog. It must reject new intents, contain queued and in-flight work, deny backend acceptance, preserve diagnosis and account for every effect already committed.

The production decision is concrete: writes are enabled only after a failure exercise proves that the stop works from agent policy to backend authorization and that recovery can reopen one bounded path. Until then, keep the agent useful in read-only mode and treat every unknown operation as unresolved production state.