Repository navigation
fix(runner): reap orphaned episode runs and end an orphaned run's instance - #950
Open
andrewpark-scaleai wants to merge 3 commits into
Open
andrewpark-scaleai wants to merge 3 commits into
andrewpark-scaleai wants to merge 3 commits into
Conversation
A started LocalRunner fails a run left in flight by a process that is gone, but only runs recorded by the local runner, so an episode whose trainer died stays RUNNING; and it leaves the run's task instance running, so the instance never reads as done. A resumed instance must not be ended while the run resuming it is live, and must be once that run ends too. A live episode must keep marking its run seen, as the lease on another host needs. A run whose owner marks it seen after the reconciler listed it, and a run on this host name whose pid is not visible but whose seen mark is fresh, must both be left running with their instances. An instance that already ended is left alone when its dead run is failed.
A started LocalRunner failed a run left in flight by a process that is gone, but it queried only its own runner's records, so an episode whose trainer died stayed RUNNING for good. It also failed only the run record and left the run's task instance running, so the explorer's instance progress never reported it done and teardown needed --force. The reconciler now covers episode runs as well, which record their owning process the same way, and ends the instance failed before it fails the run, in one compare-and-swap that writes only a running instance. Each read inside it re-reads the run index: the write is cancelled when the run has ended, when its owner marked it seen since the reconciler listed it, or when another live run (one that resumed the instance) holds it. A run whose instance is held is left in flight for a later pass, so the instance is still ended if the holder ends without touching it. A live episode now marks its run seen as a LocalRunner does, so a reconciler on another host does not fail it once the lease runs out. On the reconciler's host, a pid that looks gone now counts only once the owner's lease has lapsed too. A host name can be shared across pid namespaces, as by containers on the host's network, so a pid check alone would fail every live episode there in one pass.
RunOrphanReaping.tla models how a started LocalRunner fails runs whose process died, episodes included, and ends their task instances, against the processes running them, a run that resumes the instance, a process that stalls past its lease and comes back, and an episode that shares the reconciler's host name. Five configs check the code; seven more break each rule, before the fix or with one guard removed. check.sh runs every config against its expected outcome, and AGENTS.md gives the rules, the code each action covers, and how to read a failure.
andrewpark-scaleai
force-pushed
the
andrew-park/reap-orphaned-runs
branch
from
November 29, 2026 06:07
f53ac0b to
f16351a
Compare
This branch has not been deployed
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.
Why
A run whose process died could stay in flight forever. The local runner's reconciler only reaped runs recorded as
local, so an episode whose trainer died stayedRUNNING. When it did reap a run, it failed only the run record and left the task instancerunning. The explorer then never reported the instance done, and teardown refused it without--force.What changed
localandepisoderuns. For each dead run it ends the instance first, then the run. The instance write is a compare-and-swap that only touches arunninginstance. It holds back while any other run of that instance is alive, or while the target run has renewed its lease since the reconciler listed it.OWNER_SEEN_SECONDS, through teardown.tst/formal/run_orphan_reaping/, withAGENTS.mdand acheck.shthat pins TLC and checks 12 configs against their expected results.Scope
AGENTS.md: a lease renewal in the one round trip between the re-check and the write, and a process that stalls past its lease before it registers its instance.Blast Radius
Only the reconciler and the episode loop change. A live run is never failed: the write re-checks liveness inside the compare-and-swap, and real end writes (
record_task_failure,record_task_cancelled) still overwrite the reconciler'sfailed.Verification
tst/unit/runner/local_runner_test.pyandtst/unit/task/episode/run_test.pyfail onmain(for example'running' == 'failed'for the instance, and the episode run leftRUNNING) and pass here.tst/unit/runnerandtst/unit/task/episodegive 163 passed, andmake lintpasses.bash tst/formal/run_orphan_reaping/check.shexits 0. Every config gives its expected result. The fixed configs hold every rule (for example 222,709 states with stalls), and each config that removes one guard breaks the rule that guard protects.

Confidence Score: 5/5
The PR appears safe to merge within its documented lease limits.Summary
The PR ends orphaned
localandepisoderuns and fails their running instances first.Review was based on source inspection; tests and TLC were not run.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[List active local and episode runs] --> B{Owner alive?} B -->|Yes| C[Leave unchanged] B -->|No| D[Read current runs sharing the instance] D --> E{Run ended or a live run holds it?} E -->|Yes| C E -->|No| F[Fail instance only if still running] F --> G[Fail orphaned run]Reviews (2) · Last reviewed commit: "chore: add the run-orphan-reaping TLA+ m..." · Reviewed by Greptile