Skip to content

Let resume restart a run its Validator left incomplete - #174

Merged
shanebarakat merged 2 commits into
mainfrom
fix/resume-after-validator-exit
Dec 4, 2026
Merged

shanebarakat merged 2 commits into
mainfrom
fix/resume-after-validator-exit

Conversation

@shanebarakat

@shanebarakat shanebarakat commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Since #162, a Validator that exits before acceptance retires the run with outcome: incomplete. That covers a crash, a killed tmux server, a closed terminal or an accidental /exit. After that, every factory resume refuses with this run is retiring or stopped; create a new run, so the run's work is stranded.

Reproduced live on devshell dev (chiron 4bd3fde): start a run, kill its tmux server, run factory resume, and it is refused permanently. The installed b04c32a resumes the same run.

Change

  • start(), which factory resume goes through, now calls run_lifecycle.reopen_incomplete() under the lifecycle lock.
  • An incomplete stop whose teardown is verified (stopped) is moved aside to lifecycle-terminal.reopened-<observed_at>.json, kept as evidence, and the run starts again.
  • A ci-green stop, or one whose teardown is still pending, stays final and refuses exactly as before.
  • Retire finished Factory runs and reclaim disposable validation storage #162's teardown is unchanged. A Validator exit still stops the run's processes and records the outcome.

Tests

test_resume_reopens_only_a_run_stopped_incomplete covers four cases: validator-exited and validator-closed reopen; pending teardown and ci-green refuse. The two reopen cases fail on main. test_run_lifecycle.py and the retirement test files pass. ruff and mypy are clean on the changed files.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Since #162, a Validator that exits before acceptance (a crash, a killed tmux
server, a closed terminal, an accidental /exit) retires the run with outcome
incomplete, and every later `factory resume` refuses with "this run is
retiring or stopped; create a new run". The run's work is stranded, where
b04c32a resumed the same run.

start() now moves an incomplete stop record whose teardown is verified aside
(lifecycle-terminal.reopened-<observed_at>.json, kept as evidence) and starts
the run again. A CI-green stop, or one whose teardown is still pending, stays
final and refuses as before.

@adaptcom adaptcom Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confidence Score: 2/5

Summary

Lets factory resume reopen a run retired incomplete once teardown is verified. Works for native-Validator runs, but kickoff-mode state (stop.json, stale external binding) is not reset, so those reopened runs are torn down again within one watcher tick.

Important Files Changed

File Overview
harness/run_lifecycle.py reopen_incomplete moves verified incomplete stop aside; ignores kickoff stop.json and external binding
harness/run_record.py start() reopens under lifecycle lock before _start_locked, prints stderr notice
tests/test_run_lifecycle.py Four parametrized cases; _start_locked stubbed, watcher behaviour after reopen untested

Findings

  • README.md:279-283 and the CHANGELOG Unreleased section still describe an incomplete retirement as final; note that factory resume reopens a torn-down incomplete run.

Reviewed 4bd3fde...2b96795 · ↻ Re-run review · View in Adapt

Comment thread harness/run_lifecycle.py Outdated
if not os.path.lexists(path):
return False
terminal = run_record.read_json(path)
if terminal.get("outcome") != "incomplete" or terminal.get("teardown") != "stopped":

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reopening validator-closed keeps inbox-wake/stop.json: the fresh inbox-wake poller exits and the kickoff watcher re-retires the run on its first tick (reproduced); exclude that reason or remove the file.

Comment thread harness/run_lifecycle.py
raise ValueError("this run is retiring or stopped; create a new run")


def reopen_incomplete(root: Path) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kickoff validator-exited runs keep the dead orchestrator/validator-process.json binding (bind-validator refuses overwrite), so the new watcher re-retires within ~5s; limit reopen to native Validators or reset it.

Comment thread harness/run_lifecycle.py Outdated
if terminal.get("outcome") != "incomplete" or terminal.get("teardown") != "stopped":
refuse_terminal(root)
stamp = re.sub(r"[^0-9A-Za-z]", "", str(terminal.get("observed_at", ""))) or "unknown"
os.replace(path, root / f"lifecycle-terminal.reopened-{stamp}.json")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.replace silently overwrites an existing reopened-<stamp>.json (always when observed_at is missing, stamp unknown); create exclusively or add a counter so repeated reopens keep every record.

Comment thread harness/run_lifecycle.py Outdated

A crashed, killed or closed Validator must not strand the run's work: the stop record moves
aside (kept as evidence) once its teardown is verified. A CI-green stop, or one whose teardown
is still pending, stays final. Call under the lifecycle lock.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A watcher lost mid-teardown (host reboot) leaves teardown: pending with nothing to finish it, so resume is refused forever; consider re-running _retire from resume under the lock.

"evidence": {}, "owned": []}
(root / run_lifecycle.TERMINAL).write_text(json.dumps(record))
started = []
monkeypatch.setattr(run_record, "_start_locked", lambda runs_dir, run: started.append(run))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stubbing _start_locked leaves the watcher unexercised; add a case asserting _validator_terminal returns None after reopen so the kickoff regressions above are caught.

Review: a kickoff Validator keeps its dead conversation binding and a
deliberate close keeps inbox-wake/stop.json, so reopening either was torn
down again on the next watcher tick. Reopen only validator-exited on a run
whose Validator is its own seat; kickoff, closed, CI-green and pending-teardown
stops stay final. Each reopened record gets its own file (hard link, never
overwritten), so repeated crashes keep every record. README and CHANGELOG say so.
@shanebarakat

Copy link
Copy Markdown
Collaborator Author

Addressed in 1213527:

  • Kickoff validator-exited / validator-closed: reopen is now limited to validator-exited on a run whose Validator is its own seat (kickoff_validator false). Kickoff runs and deliberate closes stay final, as before. Making a crashed kickoff conversation resumable needs a rebind, which is a separate change.
  • os.replace overwrite: each reopened record is hard-linked to its own name (-1, -2, … on collision), so repeated crashes keep every record.
  • Watcher after reopen: verified live on a native-Validator run. Starting it, killing its tmux server and running factory resume reopens the run, a new run_lifecycle watcher starts, and the run stays up past several watcher ticks. The test now covers kickoff exit, kickoff close, pending, ci-green, and a second crash and resume.
  • README / CHANGELOG: updated.
  • Pending teardown after a host reboot: left as is, since it needs a reboot between the stop record and the end of teardown. Worth a follow-up that re-runs _retire from resume.

@adaptcom review

@adaptcom

adaptcom Bot commented Dec 4, 2026

Copy link
Copy Markdown

Re-reviewed 1213527: both blockers are fixed. Reopen now only applies to validator-exited on a run with its own Validator seat (kickoff_validator false). The os.link loop keeps every reopened record. README and CHANGELOG are updated. test_run_lifecycle.py passes, and ruff and mypy are clean. Confidence 4/5.

Non-blocking:

  • Finished run that then exits: a native-Validator run where inbox_wake.py stop was run and the Validator then exited still reopens. inbox-wake/stop.json survives the reopen (reproduced), so on runs with Claude seats the new inbox-wake poller exits right away and inbox delivery stops. Consider refusing reopen when that file exists, or clearing it.
  • Link then unlink: if a crash lands between os.link and path.unlink(), the record is kept twice, and the next resume adds one more copy (-1). That's harmless, but worth a comment.
  • Pending teardown after reboot: agree it's a follow-up.

↻ Re-run review · View in Adapt

@shanebarakat
shanebarakat merged commit da67b06 into main Dec 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant