How to Run a Safe Parallel Refactor with IOSM CLI
Parallel agents do not make a refactor safe. They make every unclear boundary fail faster.
When several workers can edit the same repository, the hard problem is no longer task decomposition. It is preserving one coherent change while work happens out of order. IOSM CLI addresses that problem with a concrete execution sequence: Scopes → Touches → Locks → Gates → Done.
This is the workflow I would use for a risky refactor such as separating session handling from token validation. It is deliberately practical. The goal is not to maximize the number of agents. The goal is to make parallel work inspectable, bounded, and recoverable.
1. Start with a contract, not a worker count
A command like this looks precise:
/swarm run "Refactor authentication" --max-parallel 5
It is not. “Authentication” may include request parsing, session storage, token validation, middleware, tests, configuration, migrations, and public API behavior. Five workers only multiply the ambiguity.
IOSM CLI blocks /swarm when there is no effective /contract. Use that boundary. Define at least:
- the modules allowed to change;
- behavior that must remain invariant;
- commands that prove the refactor still works;
- files or interfaces that require explicit approval;
- a rollback point for the workspace.
For a brownfield repository, I would make the invariant executable: existing authentication tests must pass, the public middleware signature must remain stable, and no database migration is allowed. This turns “be careful” into conditions the run can evaluate.
If the scope is still uncertain, begin with /singular rather than inventing a detailed plan too early:
/singular "Separate session handling from token validation without changing the public middleware API"
Choose one proposed option only after its boundaries are legible. Then hand that option to the swarm runtime. The decision phase and the execution phase remain separate.
2. Create a checkpoint before parallelism
Parallel execution increases the number of intermediate states. Before starting it, create a recovery boundary:
/checkpoint
The checkpoint is not permission to accept arbitrary edits. It is an escape route if integration reveals that the decomposition itself was wrong. For broad refactors, I want both the IOSM session history and the workspace snapshot to describe the same engineering moment; I explain that invariant in Why Agent Rollback Needs Two Checkpoints.
Do not wait for a failure to discover whether rollback exists. If the change is especially risky, rehearse the restore path first using the method from How to Rehearse Rollback Before an IOSM Cycle.
3. Begin with less parallelism than the runtime allows
The current IOSM CLI command surface accepts a run-level --max-parallel from 1 to 20:
/swarm run "Separate session handling from token validation without changing the public middleware API" --max-parallel 3 --budget-usd 12
That range is a capability limit, not a recommendation. I would start with two or three workers for a refactor whose dependency graph is not yet proven.
Why? Parallelism is useful only while tasks touch independent surfaces. If three tasks all modify the authentication middleware, the scheduler can serialize them through locks, but the original decomposition has already failed to create useful concurrency. IOSM CLI includes a conflict-density guard that reduces parallelism when touch overlap becomes heavy. Treat that reduction as diagnostic evidence, not as lost performance.
The budget flag is equally important. It sets a run boundary and gives /swarm watch a concrete consumption signal, including an 80% warning state. A budget does not prove value, but it prevents an open-ended orchestration run from hiding behind a vague instruction to “finish the refactor.”
4. Read touches and locks as an architecture review
During the run, inspect it:
/swarm watch
The current runtime reports ready, running, blocked, done, and error counts, along with budget use, locks, current touches, critical path estimates, throughput, and bottlenecks.
The most useful fields are often not the impressive ones. The touches map and lock snapshot show whether the proposed module boundaries exist in the codebase.
Suppose the plan creates three tasks:
| Task | Intended surface | Gate |
|---|---|---|
| Extract token verification | auth/token/* |
token unit tests |
| Extract session lifecycle | auth/session/* |
session integration tests |
| Rewire middleware | auth/middleware.* |
full auth suite |
If the first two tasks repeatedly need the same middleware file, that is not merely scheduler contention. It may mean the repository has no stable seam between token and session concerns. Stop pretending the work is independent. Narrow the tasks, introduce the seam first, or run the conflicting step sequentially.
This is where IOSM differs from “launch several agents and merge later.” Locks protect files, but the touches map exposes architectural coupling while there is still time to change the plan.
5. Let gates decide completion
A worker saying “done” is not completion. In the swarm consistency model, Done comes after Gates.
Each task should have a local proof, and the integrated run should have a wider proof. For the example above:
- token tests prove the extracted verifier;
- session tests prove lifecycle behavior;
- the full authentication suite proves integration;
- a diff review proves the public middleware contract did not drift;
- the budget and artifact record make the run reviewable.
This is the same reason I treat IOSM as an improvement layer rather than an agent framework: the methodology owns the decision that a change improved the system. A scheduler can finish tasks; it cannot redefine acceptance after the fact.
6. Retry one failed task, not the whole story
IOSM CLI provides targeted recovery:
/swarm retry <run-id> <task-id>
Use --reset-brief only when the task instruction itself was defective:
/swarm retry <run-id> <task-id> --reset-brief
That distinction matters. A transient test failure may justify another attempt under the same brief. A task that touched the wrong boundary needs a corrected brief. Re-running the entire swarm would discard useful completed work and blur the reason for the retry.
The runtime classifies retry causes such as permission, dependency/import, test, timeout, and unknown. Keep the cause visible. “Second attempt passed” is weaker evidence than “the dependency failure was repaired, then the same gate passed.”
If the process is interrupted, resume the recorded run:
/swarm resume <run-id>
Do not start a fresh swarm with the same prose and assume it is the same operation. The original run has state, checkpoints, locks, task outcomes, and evidence under .iosm/orchestrate/<run-id>/.
7. Review the artifacts before accepting the refactor
A swarm run writes an inspectable directory:
.iosm/orchestrate/<run-id>/
├── run.json
├── dag.json
├── state.json
├── events.jsonl
├── checkpoints/latest.json
└── reports/
├── integration_report.md
├── gates.json
└── shared_context.md
I would review four things before accepting the result:
dag.json: did the actual dependency graph match the planned decomposition?events.jsonl: where did tasks block, retry, or change state?gates.json: which checks passed, failed, or remained unknown?integration_report.md: does the final result explain what changed and what was verified?
These files are not administrative residue. They are the difference between a refactor that merely exists and one whose execution can be challenged.
A compact operating recipe
/contract
/checkpoint
/singular "Separate session handling from token validation without changing the public middleware API"
# choose one bounded option
/swarm from-singular <run-id> --option 1 --max-parallel 3 --budget-usd 12
/swarm watch <run-id>
# if one task fails:
/swarm retry <run-id> <task-id>
# if interrupted:
/swarm resume <run-id>
# inspect .iosm/orchestrate/<run-id>/reports/ before acceptance
The limitation is important: IOSM CLI can enforce the contract, locks, run budget, state transitions, and configured gates. It cannot make a poorly chosen test suite prove behavior it never checks. The quality of the final claim is still bounded by the quality of the contract and evidence.
Parallelism should be the result of independent change surfaces, not an aspiration. Start with a contract. Observe contention. Reduce concurrency when the architecture demands it. Accept the refactor only after the integrated gates pass and the run artifacts tell one coherent story.