Repository navigation
fix(run-cycle): survive host task limits and record interrupted stages - #133
Conversation
SIGTERM, SIGHUP or SIGINT used to end run_cycle.py on the spot: the running stage left no telemetry row, the status file kept saying it was running, and the agent it had started kept editing an unsupervised checkout. The driver now turns the first stop request into CycleInterrupted. The streaming runner stops the agent it started, CycleRecorder records the stage with the new dispatch outcome 'interrupted', and the cycle closes with the stop reason 'interrupted' and a finished status file. Telemetry schema 12 adds both tokens. Refs #130
Agent hosts run shell commands as tasks with a time limit; Claude Code stops a background command after 30 minutes by default, taking the executor with it. run_cycle.py --detach validates the invocation where the person can still read a refusal, then restarts the same cycle in its own session and process group with no terminal, and returns at once with its process ID, a log path beside the status files, and the cycle_status.py command that follows it. Refs #130
An interrupted implementation has no change request for --from to resume, so it used to start from scratch. run_cycle.py --continue --cwd <checkout> tells the implementer that a previous run was interrupted and to keep and continue the partial work in that checkout, including any change request it already opened, instead of redoing it. It refuses a checkout that is clean on its default branch, a missing --cwd, and a resuming --from. The issue review is not repeated, and the cycle row records continued (schema 12). Refs #130
cc-orchestrator now tells an agent to start run_cycle.py with --detach, never to hold the cycle in a task of its own or raise a task's time limit instead, to follow it with cycle_status.py, and to resume an interrupted stage with --from or --continue rather than starting the work item again. The package validator keeps those instructions in place. Refs #130
[CCR-20260930-001] · manual · unknown/gpt-6-luna→? · high · schema:1ReviewVerdict: APPROVED — reviewed the complete 16-file diff from Findings[REV-001] · low · open · - · blocks:no — Qualify the Claude Code background timeout claim
Security triageThe deterministic rule did not fire: no changed path, filename, or PR label matches the built-in security triggers, and VerificationPreflight found Python 3.10.12 and the repository configuration. The tests use isolated temporary state; no database, migration, or service prerequisite applies. The CLI/subprocess boundary was exercised by the installed-runtime process tests, including an actual SIGTERM interruption and detached process-group launch.
CI and residual riskAll current PR checks passed: The detached launch's Windows process-creation behavior remains unverified at runtime. The documented APPROVED — the reviewed head matches the PR head, all required checks passed, and there are no open blocking findings. |
Closes #130 — #130
Diagnosis
Symptom: a cycle launched from Claude Code was stopped mid-implementation at the host's background-task limit (about 30 minutes). The Codex executor ended with it, the work was lost, and nothing was recorded.
Reproduction (before the fix): I ran
run_cycle.py --issue-review offwith a fakecodexwhose implementation never finishes, then sent SIGTERM torun_cycle.pyalone:implement … finished: False;codexchild kept running, orphaned.When a host stops the whole process group, the child dies too, which matches the reported symptom.
Cause: this matches the issue's hypothesis. Two gaps combine:
--fromcannot resume an implementation, because no change request exists yet.Invariant: every dispatched stage ends with a row and a finished status. A cycle's lifetime is not tied to the lifetime of a host task.
Related work: widened search (bug label), by title and body terms timeout, SIGTERM, background, interrupted, killed, resume, detach. Related but not duplicates:
--fromresume, which this extends to implementation);cycle_status.py).Fix shape:
Deliberate deviation from the issue's proposal 2: there is no
--host-limitguard. The runtime cannot know a host's limit unless the agent declares it, and a declared limit would carry the same instruction as "use--detach". Detaching removes the limit instead of checking against it.Work units
WU-1CycleInterrupted. The streaming runner stops the agent it started. The running stage is recorded with the outcomeinterrupted, the cycle closes with the stop reasoninterrupted, and the status file is marked finished. Telemetry schema 12.scripts/executors.py,scripts/cycle.py,scripts/run_cycle.py,scripts/telemetry.py,docs/instrumentation.md,docs/telemetry.md,tests/fakes/fake_agent.pyInterruptionTests,InterruptibleTests,test_an_interrupted_streaming_run_stops_its_agent,test_a_stopped_cycle_records_where_it_stopped_and_stops_its_agent(real process, installed runtime)InterruptionTestsfail. The manual reproduction now shows the child stopped, animplement interruptedrow, a cycle row with stop reasoninterrupted, and a finished status.independentWU-2--detachvalidates first, restarts the same cycle in its own session and process group with no terminal, and returns at once with the PID, a log path beside the status files, and thecycle_status.py --followcommand.scripts/run_cycle.py,docs/workflows.md,docs/configuration.md,docs/instrumentation.mdtest_a_detached_cycle_returns_at_once_and_runs_in_its_own_session,test_a_detached_cycle_is_refused_before_it_detaches,DetachFlagTestssid = pgid = run_cycle pid, different from the launching shell's session.dependenton WU-1 (the docs describe a detached run's stop as recorded)WU-3--continue --cwd <checkout>tells the implementer to keep and continue the interrupted partial work and any change request it already opened. It refuses a clean default-branch checkout, a missing--cwd, and a resuming--from. It skips the issue review and recordscontinued.scripts/run_cycle.py,scripts/telemetry.py,docs/workflows.md,docs/configuration.md,docs/instrumentation.md,docs/telemetry.mdContinueImplementationTests,CheckContinuationTests,test_an_interrupted_implementation_continues_from_its_checkout(installed runtime)independentWU-4cc-orchestratortells agents to launch with--detach, never to hold the cycle in their own task or raise a time limit instead, to follow the run withcycle_status.py, and to resume with--from/--continue. The validator enforces this. CHANGELOG entry.skills/cc-orchestrator/SKILL.md,scripts/validate-package.py,tests/test_validate_package.py,CHANGELOG.mdtest_rejects_an_orchestrator_that_does_not_detach_the_runtimevalidate-package.py→ VALIDdependenton WU-2 and WU-3 (it names their flags)Most of the
scripts/run_cycle.pydiff is reindentation: the cycle flow moved intodrive()so that oneexcept CycleInterruptedcloses it wherever it stops.Verification (agent-reported)
python3 scripts/validate-package.py→ exit 0,VALID: 15 skills (7 cycle, 8 supporting), shared sections in sync, cross-agent manifests alignedpython3 -m unittest discover -s tests→ exit 0, 934 tests OKclaude plugin validate .→ passedgit diff --check→ clean--detachlaunch whose session and process group were checked.Environment: Linux (WSL2), Python 3.10.12. The tests set their own Git identity and use temporary HOME, PATH and databases, so no user-global state is involved. The signal and session tests are POSIX-only and skip on Windows. The Windows
--detachbranch (DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP) is not executed by any test.Residual risk
SIGKILL, including one a host sends before cleanup finishes, still ends a run without a row. The docs say so.codex exec resume) is not used.--continueworks for any executor by pointing it at the checkout, which relies on the agent following the continuation instruction.