How IOSM CLI Changes Strategy After an Agent Failure
A retry that repeats the same strategy is not recovery. It is another invoice for the same mistake.
This matters most in delegated agent work. A subagent can fail because its context was too large, a command timed out, a dependency was missing, or its reasoning reached an invalid state. A generic “try again” prompt hides those differences. The second attempt receives the same task, uses the same habits, and often reaches the same boundary.
IOSM CLI now takes a narrower approach: classify the failure, decide whether a retry is legitimate, and inject guidance that changes the next attempt. I think this is a small but important runtime mechanism. The system does not pretend that the model learned from the failure. It converts the failure into an explicit control input.
The mechanism has three steps
The implementation in IOSM CLI separates three decisions:
- What failed? The error message is mapped to a bounded cause such as
token_limit,logic_error,timeout,dependency_env,empty_output,aborted, orunknown. - May the runtime retry? Cancellation and empty output are handled differently from failures that can benefit from a changed strategy. An aborted operation is not silently restarted.
- What must change? The runtime generates a retrospective directive for the root task or delegated task with cause-specific instructions.
The directive is deliberately simple:
[RETROSPECTIVE_RETRY]
target: delegate
attempt: 1
cause: timeout
previous_error: deadline exceeded while running repository scan
retry_policy:
- Split work into smaller bounded steps.
- Reduce expensive commands and long-running checks.
- Prioritize fast targeted verification first.
[/RETROSPECTIVE_RETRY]
This is not a hidden chain of thought. It is an operational artifact: a compact diagnosis plus a policy for the next attempt.
Failure classes should change behavior
The useful part is not the taxonomy itself. It is the behavioral difference attached to each class.
| Failure cause | Changed strategy |
|---|---|
token_limit |
Narrow files and commands, avoid broad reads, compress the result |
logic_error |
Diagnose the failed assumption, choose another path, validate a smaller step |
timeout |
Split the task, reduce expensive operations, verify the cheapest signal first |
dependency_env |
Check prerequisites before implementation and report an exact blocker |
aborted |
Stop; resume only through an explicit new run |
unknown |
Reduce scope, reconsider assumptions, and produce a verifiable outcome |
That asymmetry is essential. A timeout is not evidence that the engineering hypothesis is wrong. A logic failure is not evidence that the environment is broken. An external abort is not permission to recreate side effects.
A runtime that collapses all of them into retry=true loses the most valuable information produced by the failed attempt.
One bounded retry is a design choice
IOSM CLI reads the retrospective retry allowance from IOSM_SUBAGENT_RETRO_RETRIES. The current implementation bounds it to zero or one, with one retry as the default.
That limit matters. Retrospective retry is not an infinite self-healing loop. It is one controlled opportunity to apply a different strategy. If the changed approach also fails, the system should surface the failure rather than keep manufacturing attempts.
This complements the broader decision model I described in When IOSM Should Retry—and When It Must Stop. The policy article defines the possible actions. The runtime mechanism here shows how a retry can carry a concrete strategy delta.
Recovery needs counters, not anecdotes
The task runtime records more than the final success or failure. It tracks retrospective attempts, recovered attempts, and failure-cause counts. This makes two questions answerable:
- Did the retry mechanism recover delegated work?
- Which failure class dominates the orchestration workload?
Those counters do not prove correctness. A recovered subagent may still produce a wrong result. They do, however, distinguish “the second attempt returned output” from “nothing happened,” and they create a basis for later evaluation.
I would keep them next to the run artifacts described in How to Turn an IOSM CLI Run into Reviewable Evidence. A trace can show when the first attempt failed, which directive was injected, and what the replacement attempt produced. The final engineering claim still needs tests, gates, or other domain evidence.
Classification is useful, but not infallible
The current classifier is intentionally lightweight. It uses patterns in error messages. That makes it deterministic and easy to test, but it also creates boundaries:
- provider wording can change;
- one error message can contain signals from several causes;
- a dependency failure may be reported as a generic command failure;
unknownremains a necessary outcome.
For that reason, the class should guide the retry, not rewrite history. The original error must remain in the trace. If classification becomes more sophisticated later, old runs should still be interpretable from their raw evidence.
This is the same reason IOSM separates working state from proof. The IOSM CLI runtime may coordinate sessions, tools, checkpoints, and agents, but a successful orchestration path is not automatically a successful engineering change.
The deeper rule: retries need a delta
I use a simple test for any agent retry:
What is different about the next attempt?
If the answer is only “the model gets another chance,” the runtime has no recovery policy. It has repetition.
A valid retry delta can be smaller scope, a different tool path, repaired prerequisites, a reduced command, a changed verification order, or a new human decision. The IOSM CLI retrospective directive makes that delta explicit and bounded.
That is the engineering move I care about. Failure is not converted into optimism. It is converted into a typed reason, a permitted action, and a changed execution strategy.