$ fssg build --deterministic --validate |

I Count Cleanup as Part of the Work

Logs

I do not consider an AI task finished while its scaffolding is still lying around.

A correct patch can leave a dirty workspace. A successful experiment can leave a background process, a temporary directory, a detached worktree, a generated report, and three files named final-v2-really-final. None of these proves that the main result is wrong. Together, they make the next piece of work harder to trust.

For me, cleanup is not cosmetic. It is the final state transition of the task.

Every run borrows state

An agent rarely works only on the artifact I asked for. It borrows surrounding state to get there:

  • temporary files for transfer or transformation;
  • branches, worktrees, snapshots, and caches;
  • local servers and background jobs;
  • downloaded fixtures and generated outputs;
  • diagnostic logs;
  • one-off configuration overrides.

Some of that state should survive. Evidence, the accepted patch, and the commands needed to reproduce a check may be valuable long after the run. Other state exists only because the work was in progress.

The problem begins when the system cannot tell the difference.

If every intermediate artifact is preserved forever, the workspace becomes an archaeological site. If everything is deleted automatically, the run may erase the only evidence that explains a failure. “Keep everything” and “clean everything” are both refusals to classify state.

I want each borrowed object to have an owner and a disposition:

keep       accepted result or durable evidence
archive    useful for review, not active work
remove     temporary and reproducible
leave      pre-existing or outside this task's authority

That small vocabulary is more useful than a generic cleanup command. It forces the run to say what it created, what it is allowed to remove, and what must remain untouched.

Cleanup must use the same boundary as creation

The most dangerous cleanup is broad cleanup.

An agent creates one directory and later runs a pattern that matches ten. It starts one server and kills every process with a similar name. It adds three files, then uses a repository-wide reset to recover from a failed attempt. The intention is tidy; the authority is not bounded.

My rule is simple: a run may clean only the state it can identify as its own.

That means recording identity at creation time, not trying to reconstruct ownership at the end. A temporary directory has an exact path. A background process has a process identifier and a start record. A worktree has a registered path. A generated file belongs to a manifest. If the run did not record the object, deletion should stop and ask for a narrower decision.

This is the same reason I review AI work as a diff. Scope is easier to defend when it is concrete. Cleanup deserves the same reviewability as creation because deletion is also a change.

The residue manifest

I use a compact mental model that can become a real artifact when the task is consequential:

run: refactor-auth-20260915
created:
  - path: /tmp/refactor-auth
    disposition: remove
  - path: ../auth-experiment
    kind: git-worktree
    disposition: remove-if-clean
  - path: reports/auth-baseline.json
    disposition: keep
started:
  - pid: 4128
    purpose: local-test-server
    disposition: stop
protected:
  - .env
  - existing-uncommitted-files
verify_after_cleanup:
  - git status --short
  - git worktree list --porcelain
  - process 4128 is absent

This is not an IOSM CLI schema. It is an example of the contract I want: ownership, intended lifetime, protected state, and a check after removal.

The verification matters. A successful delete call does not prove the task left the intended state. The process may have spawned a child. The worktree directory may be gone while Git still retains administrative records. A temporary file may be removed while its generated copy remains under another path.

Git makes this distinction visible. Its worktree documentation tells users to remove a linked worktree with git worktree remove; if a directory is deleted manually, stale administrative data may remain until pruning. Python's high-level tempfile interfaces make lifetime explicit through context managers, while lower-level mkstemp() and mkdtemp() require manual cleanup. Different tools, same lesson: lifecycle belongs in the interface.

Failure changes what should survive

Cleanup is easiest after success and most important after failure.

On success, I can keep the accepted artifact and remove reproducible scaffolding. On failure, I may need the opposite: preserve the smallest diagnostic bundle, remove unsafe active state, and leave the original workspace recoverable.

That creates three different endings:

Outcome Keep Remove Prove
accepted result and verification evidence temporary scaffolding expected final state
rejected failure evidence and useful diff candidate outputs baseline still works
interrupted resume marker and owned diagnostics active processes and unsafe partial state restart is bounded

A task that fails and then erases every trace is not clean. It is opaque. A task that fails and leaves everything running is not observable. It is abandoned.

This is where cleanup meets recovery without becoming the same thing. A checkpoint before a risky refactor protects a named workspace state. Cleanup decides what happens to the additional state created around that experiment. Rollback restores a boundary; cleanup closes the run.

Clean does not mean empty

I do not want agents to leave no trace. I want them to leave the right trace.

IOSM CLI deliberately writes cycle artifacts under .iosm/cycles/<cycle-id>/ and orchestration artifacts under .iosm/orchestrate/<run-id>/. Its public repository also includes explicit pruning for completed background-process records and cleanup telemetry for task failures. Those are different lifecycles: durable engineering history, bounded operational records, and active runtime state should not be flattened into one directory and one retention rule.

The result I trust is a legible workspace:

accepted source change
verification artifact
named recovery point, if still needed
no unexplained process
no anonymous temporary directory
no unrelated file touched

This is also why I keep the command line between AI and the system. The terminal gives cleanup inspectable nouns: paths, process IDs, exit codes, worktrees, and status. It lets the final claim be challenged by the environment.

Completion includes what is no longer there

Agents are usually evaluated on what they produce. Files created. Tests passed. Messages sent. Features shipped.

I also evaluate the negative space.

Which temporary privileges expired? Which process stopped? Which candidate was removed? Which pre-existing changes remained untouched? Which evidence survived? What would surprise the next engineer opening the repository?

This does not require elaborate ceremony for every small task. A context manager may be enough. A trap handler may be enough. A disposable worktree with an explicit removal step may be enough. The discipline is proportional; the ownership rule is not.

AI makes it cheap to create branches of action. That makes closure more valuable, not less. I want every run to leave behind a result I can inspect and a workspace I do not have to decode.

The work is not done when the agent has produced the answer. It is done when the result remains, the borrowed state has a declared fate, and the next task can begin without inheriting unexplained residue.

Sources

FACET AI CLI Terminal
facet@ai:~$