Put an AI Agent into Safe Mode Before You Debug It
When a consequential AI agent behaves strangely, my first goal is not to fix it. My first goal is to stop the incident from producing new facts.
That distinction matters. A broken web worker can often be restarted. An agent may have already sent a message, changed a repository, opened a ticket, rotated a credential, or started a deployment. Restarting it can repeat the effect while erasing the state that would explain what happened.
I want an explicit safe mode between normal execution and shutdown. Safe mode stops new consequential work, preserves the evidence needed for recovery, and allows only operations that reduce uncertainty.
This is an incident-response mechanism, not another retry policy.
The wrong first move is “restart the agent”
A restart is attractive because it is simple. It is also destructive when the runtime has unresolved effects.
Suppose an agent submitted a release request and lost the response. The local trace says “timeout.” The target system may say “accepted.” If the process restarts and repeats the call with a new request identity, the incident becomes a duplicate release rather than a timeout.
The same problem appears with email, payments, infrastructure changes, issue trackers, database writes, and any API whose response can disappear after the server accepted the action.
Before restart, I need answers to three questions:
- Which effects are known to have completed?
- Which effects are known not to have started?
- Which effects are ambiguous?
Only the first two sets are easy. The third set defines the incident.
Safe mode is a restricted execution state
Safe mode should be a runtime state with a closed list of permitted actions:
mode: safe
admission:
new_runs: denied
new_effects: denied
allowed_operations:
- read_trace
- snapshot_state
- query_external_effect
- revoke_or_reduce_authority
- complete_read_only_validation
- build_recovery_plan
forbidden_operations:
- retry_effect
- start_new_workflow
- mutate_policy
- delete_evidence
The important property is asymmetry. Safe mode may observe more, but it may change less.
This is different from pausing one workflow. Durable execution systems can pause a failed workflow and resume it after repair. That is useful at the run level. Safe mode is the operational boundary above individual runs: it changes admission and authority for the affected agent, workflow version, tenant, tool, or failure domain.
It is also different from a kill switch. A kill switch stops execution. Safe mode preserves a narrow recovery surface after execution stops expanding.
Step 1: freeze admission before touching the process
The first action is to stop new work from entering the affected boundary.
That boundary should be as narrow as the evidence permits. If one workflow version is failing, freeze that version. If one credential or tool endpoint is compromised, freeze work that depends on it. If the runtime cannot identify the boundary, freeze the whole agent class.
The order matters:
close admission
-> revoke queued authority
-> stop dispatch
-> then inspect active work
If I inspect first, the queue can keep feeding the incident while I am reading logs.
This connects to AI agent failure domains. A runtime that already knows shared credentials, mutable resources, and deployment targets can freeze the causal domain instead of stopping every unrelated task.
The freeze itself needs an identity and timestamp. “We disabled the agent around ten” is not enough for reconstruction.
{
"freeze_id": "freeze_2026_11_16_073412Z",
"scope": "workflow:release-assistant@sha256:...",
"reason": "ambiguous_external_effect",
"effective_at": "2026-11-16T07:34:12Z",
"authority_change": "deny-new-effects"
}
Step 2: snapshot volatile evidence
After admission is closed, preserve the state that a restart, cleanup job, lease expiry, or log rotation could destroy.
I want a compact incident snapshot:
- active run and attempt IDs;
- workflow, model, policy, and tool versions;
- queued, running, paused, and completed steps;
- checkpoints and artifact hashes;
- tool requests and responses;
- stable effect IDs and target identifiers;
- authority leases and their expiry;
- last known external observations;
- scheduler and worker ownership;
- the freeze record itself.
The snapshot should reference large artifacts by content identity rather than copying secrets into an incident document.
A Kubernetes pod termination sequence illustrates the general operational constraint: once termination begins, software receives a bounded grace period before forced shutdown. Agent runtimes need the same awareness. Evidence capture cannot assume the worker will remain alive indefinitely.
The snapshot is not a full forensic image. It is the minimum state required to distinguish completed, absent, and ambiguous effects after the original process disappears.
Step 3: divide active work into stop, drain, and reconcile
“Stop everything” is too blunt. “Let everything finish” is too dangerous.
I classify active work into three lanes:
| Lane | Meaning | Default action |
|---|---|---|
| Stop | Work has not crossed an effect boundary | Cancel and preserve its checkpoint |
| Drain | Work is read-only or completing it reduces uncertainty | Let it finish under a deadline |
| Reconcile | An external effect may have happened | Query the target; do not repeat the action |
A read-only test suite may safely drain. A draft that has not been published can stop. A timed-out deployment request must reconcile.
This classification should depend on effect state, not task labels. A task named prepare_release may be read-only for five steps and consequential at the sixth. The runtime must know when the boundary was crossed.
For ambiguous effects, I use the same rule as in Effect IDs Before Retry: query the external system using the stable effect identity. If the target confirms the effect, import the receipt. If the target proves absence, a later recovery plan may authorize a retry with the same effect ID. If neither is possible, ambiguity remains and automation stops.
Step 4: reduce authority while uncertainty is high
An incident is the wrong time to preserve broad credentials “just in case.”
Safe mode should reduce authority to the minimum needed for diagnosis:
- replace write scopes with read scopes where possible;
- revoke queued approvals;
- prevent the model from selecting tools dynamically;
- pin the recovery toolset;
- expire unattended authority leases;
- require a new approval for any compensating action.
This prevents a diagnostic run from becoming another source of side effects.
It also makes the recovery plan honest. If recovery requires production write access, that requirement appears as a new transition rather than hiding inside the original authorization.
Step 5: write a recovery plan before resuming
Safe mode should not end because the error stopped appearing. It should end when a recovery plan names what changed and what will be verified.
A minimal plan looks like this:
incident: inc_01K...
root_boundary: workflow:release-assistant@sha256:...
resolved_effects:
- effect_id: release_2026_11_16
status: completed
evidence: receipt://sha256:...
changes:
- pin tool adapter to 4.8.2
- repair response parser
resume:
from: checkpoint://run_01K.../validate-release
preserve_effect_ids: true
canary_runs: 1
exit_checks:
- no ambiguous effects
- policy hash matches reviewed version
- target state matches release artifact
- trace join is complete
The plan separates repair from proof. “Parser fixed” is a change. “The target state and imported receipt agree” is evidence.
For durable workflows, resuming from a checkpoint can preserve completed work. For stateless agents, replay may be necessary. Neither is automatically safe. Replay must use pinned inputs and versions, and it must suppress or reconcile effects that already occurred.
Step 6: reopen in stages
I do not move directly from safe mode to normal traffic.
A staged exit is easier to reason about:
SAFE
-> READ_ONLY
-> SINGLE_CANARY
-> LIMITED_ADMISSION
-> NORMAL
Each transition should have explicit checks. The canary uses one bounded run. Limited admission caps concurrency and effect volume. Normal mode returns only after the runtime shows that traces, receipts, policy decisions, and external state agree.
If a check fails, the system returns to safe mode without inventing a new incident workflow.
This resembles a deployment rollout, but the object under test is not only code. It is the complete execution contract: workflow version, model route, tool adapters, policy, authority, state migration, and effect reconciliation.
What safe mode cannot prove
Safe mode does not guarantee that every external effect is discoverable. Some APIs lack idempotency keys or queryable request identities. Some logs arrive late. A compromised credential may have produced actions outside the runtime’s trace. A model provider may not expose the exact serving revision.
In those cases, the correct result may be an unresolved incident and manual reconciliation. Safe mode makes that uncertainty visible; it does not manufacture certainty.
The design also depends on prior work. Stable run IDs, effect IDs, checkpoints, versioned policies, and durable traces cannot be added after the incident and expected to reconstruct the past.
That is why safe mode belongs in the AI engineering runtime, not in an operator’s improvised checklist.
The operational invariant
My rule is simple:
During an AI incident, the system may perform only actions that reduce uncertainty or reduce authority until every consequential effect is classified.
That rule changes the order of operations. Freeze before debugging. Snapshot before restart. Reconcile before retry. Reduce authority before repair. Resume through a canary, not through hope.
An agent is not recovered when the process is running again. It is recovered when the system can explain what happened, prove the state it is resuming from, and stop the same uncertainty from expanding twice.
Sources
- Microsoft Azure: Durable Task for AI agents
- Temporal: Pause a Workflow on failure and resume it after a fix
- Kubernetes: Pod lifecycle and termination
The safe-mode state and recovery-plan schema described here are engineering proposals, not released FACET or IOSM schemas. This article makes no measured reliability or production-readiness claim.