Repository navigation
feat(task): agent-env task teardown finishes the teardown a run left, which the run names - #786
Merged
earakely-scale merged 4 commits intoNov 18, 2026
Conversation
… which the run names A run whose teardown a second signal stopped, or that couldn't tear a sandbox down, listed what was still up and left it there: no command removed it, and a cancelled run's record didn't hold what a step the signal cut short had deployed. Such a run now keeps on its instance the context its teardown ended with (record_teardown), and agent-env run and task run --keep name agent-env task teardown --instance <id>, which tears down what the instance records still up as the run's own teardown does, skipping what it took down, and exits 1 while any is still up. An instance recorded running is left alone unless --force, as for a run killed outright. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… does; AGENTS.md names agent-env task teardown Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… command counts what the run lists Greptile and an independent review found four gaps: - The command tore down outside the run's namespace, so a recording it ended or registered used the configured stores. It now runs in the instance's run scope. - A record written as a teardown ended could overwrite an attempt that took the instance over meanwhile. It's now fenced by the instance's attempt epoch as the teardown began. - A sandbox terminated whose folder wasn't removed was marked torn down, so the command found nothing to do. A run now keeps what its teardown left up (left_up_sandbox_ids), and the command takes those too. - Only a teardown that left something up was recorded, so a finished one still listed its sandboxes up. Every teardown is recorded now, and a local sandbox whose folder is gone counts as gone, as agent-env run lists it. The command also keeps its record inside its signal handling, and BundleRun.teardown routes namespaces, as run_bundle does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… teardown attempt_epoch now returns None, logged, for an instance it can't read, and a teardown it can't fence goes unrecorded, so a store error before task run --keep's teardown no longer leaves every kept sandbox up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
enabled auto-merge (squash)
November 18, 2026 22:03
earakely-scale
disabled auto-merge
November 18, 2026 22:03
earakely-scale
deleted the
edgararakelyan/fd-6255-a-run-whose-teardown-was-stopped
branch
November 18, 2026 22:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
agent-env task teardown --instance <id>finishes the teardown a run left.agent-env runnames it whenever something is still up.When a second Ctrl-C or SIGTERM stopped a run's teardown, or a sandbox couldn't be torn down, the run listed what was still up and exited. No command removed it: the user had to
docker rm -fthe container and delete its folder by hand. Two gaps sat behind that:record_task_cancelledwrites no context, so a sandbox recorded by a step the signal cut short was in the run's memory but not in the store. Nor did the store hold which sandboxes the teardown had already taken down.This PR adds:
record_teardownintask/teardown.py). It keeps on the instance the context the teardown ended with: what the run deployed, an interrupted step's records included; what it took down (torn_down_sandbox_ids); and what it left up (left_up_sandbox_ids, a new key, covering a sandbox terminated whose folder couldn't be removed).run_scope(instance_id)), since instance ids derive from task ids.run_bundleandBundleRun.teardowncall it once their loop has closed, as_mark_cancelleddoes;task run --keepafter its own teardown of kept runs, stopped or not; and the command.attempt_epochreturns None) leaves that teardown unrecorded, never stopped.agent-env runandtask run --keepprint:agent-env task teardown --instance <id>tears down what the record still has up (recorded_still_up), through the run's own teardown (teardown_run), in the run's namespace:agent-env runalready lists it (gone()incli/teardown_output.py, now shared). That covers instances recorded before this.runningalone, since its run may still be using the sandboxes, unless--force, as for a run killed outright. It rejects an unknown instance.BundleRun.teardownturns namespace routing on, asrun_bundledoes, so a script's--keepteardown finds its@localenvs and record.FD-6255, under FD-6253.
Not here:
running;--forcecovers those by hand.run_bundle's own teardown of a run (settle) still runs outside the run's scope, as before this PR. With a configured remote object store, a recording it ends or registers may use the configured store rather than the run's own. That's worth a look separately.For the docs: the CUA docs' "Deploying your computer environment" says a stopped teardown "prints what is still up". It can now add that the run names
agent-env task teardown --instance <id>, which finishes it.Proof
tst/unit/bundle/run_teardown_test.py, through the CLI with the fake backend):Nothing instance … recorded is still up.With the record off, the command finds nothing, since the interrupted step never completed.left_up_sandbox_ids == ["sb-ok"]. The command, still failing, exits 1. Once the backend recovers, it tears down, and the record showstorn_down_sandbox_ids == ["sb-ok"].torn_down == ["sb-ok"],left_up == []), and the command says nothing is up and terminates nothing again.local).--forceand torn down with it. An unknown instance is refused.tst/unit/cli/task_run_teardown_test.py):task run --keep, whose teardown can't take a sandbox down, names the command with its instance and keeps the context the teardown ended with.tst/unit/bundle,cli,task,runnerandtask_stepgave 5,609 passed, 14 skipped. Ruff is clean.BundleRun.teardown; all are fixed above.desktopexample'sprobetask.Cancelling. GNUtimeoutsent only one there, and two sent at once are taken as one.Tore down 1 sandbox, exit 0. No container was left, and the folder was gone.Nothing … recorded is still up., exit 0.Nothing … recorded is still up.🤖 Generated with Claude Code


Confidence Score: 5/5
The follow-up changes appear safe to merge.Summary
Adds a command to finish cleanup that a run left behind, saves cleanup progress, and prints the recovery command when sandboxes remain up.
The previous findings are addressed. No new actionable issues were found in the follow-up changes.
Reviews (8) · Last reviewed commit: "fix(task): reading an instance to record..." · Reviewed by Greptile