Skip to content

fix(run-cycle): survive host task limits and record interrupted stages - #133

Merged
datacas merged 4 commits into
mainfrom
issue-130-survive-host-limits
Sep 30, 2026
Merged

datacas merged 4 commits into
mainfrom
issue-130-survive-host-limits

Conversation

@datacas

@datacas datacas commented Sep 30, 2026

Copy link
Copy Markdown
Owner

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 off with a fake codex whose implementation never finishes, then sent SIGTERM to run_cycle.py alone:

    • the process exited with 143;
    • the stages table had no row;
    • the status file stayed at implement … finished: False;
    • the codex child 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:

    • Nothing tells the agent to launch the runtime outside the host's task. Claude Code's default limit for background tasks (30 minutes) is shorter than the runtime's own dispatch timeout (3600 s).
    • Nothing handles a stop request. Python's default SIGTERM action ends the interpreter at once: no recorder row, no status finish, and no stop signal to the child. --from cannot 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:

  • Fix shape:

    • turn the first catchable stop request into an interruption that is recorded;
    • stop the executor the runtime started;
    • add a first-class detached launch;
    • add a continuation path for an implementation.
  • Deliberate deviation from the issue's proposal 2: there is no --host-limit guard. 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

Unit Behaviour Files Tests Verification Rollback
WU-1 SIGTERM/SIGHUP/SIGINT becomes CycleInterrupted. The streaming runner stops the agent it started. The running stage is recorded with the outcome interrupted, the cycle closes with the stop reason interrupted, 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.py InterruptionTests, 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) New tests pass. With the fix removed, the executor test and InterruptionTests fail. The manual reproduction now shows the child stopped, an implement interrupted row, a cycle row with stop reason interrupted, and a finished status. independent
WU-2 --detach validates 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 the cycle_status.py --follow command. scripts/run_cycle.py, docs/workflows.md, docs/configuration.md, docs/instrumentation.md test_a_detached_cycle_returns_at_once_and_runs_in_its_own_session, test_a_detached_cycle_is_refused_before_it_detaches, DetachFlagTests New tests pass. Manually, the command returned in 0.07 s with sid = pgid = run_cycle pid, different from the launching shell's session. dependent on 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 records continued. scripts/run_cycle.py, scripts/telemetry.py, docs/workflows.md, docs/configuration.md, docs/instrumentation.md, docs/telemetry.md ContinueImplementationTests, CheckContinuationTests, test_an_interrupted_implementation_continues_from_its_checkout (installed runtime) New tests pass independent
WU-4 cc-orchestrator tells agents to launch with --detach, never to hold the cycle in their own task or raise a time limit instead, to follow the run with cycle_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.md test_rejects_an_orchestrator_that_does_not_detach_the_runtime validate-package.py → VALID dependent on WU-2 and WU-3 (it names their flags)

Most of the scripts/run_cycle.py diff is reindentation: the cycle flow moved into drive() so that one except CycleInterrupted closes 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 aligned
  • python3 -m unittest discover -s tests → exit 0, 934 tests OK
  • claude plugin validate . → passed
  • git diff --check → clean
  • Manual boundary runs with fake agents on a temporary PATH (no provider): SIGTERM during a hanging implementation, before and after the fix, plus a --detach launch 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 --detach branch (DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP) is not executed by any test.

Residual risk

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
@datacas

datacas commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20260930-001] · manual · unknown/gpt-6-luna→? · high · schema:1

Review

Verdict: APPROVED — reviewed the complete 16-file diff from a3741a66b807353d6b12a9090686183ae008fd4e to 64159a3e7c2bb6f373862ece6182fccf7481488d, covering interruption recording, executor shutdown, detached launches, implementation continuation, telemetry, documentation, package validation, and tests. One low-severity documentation clarification remains open and does not block approval.

Findings

[REV-001] · low · open · - · blocks:no — Qualify the Claude Code background timeout claim

docs/workflows.md:262 states that Claude Code stops a background command after 30 minutes by default. The same blanket claim appears in CHANGELOG.md:14 and skills/cc-orchestrator/SKILL.md:246. Current Claude Code tool documentation describes a default 2-minute Bash timeout, a default 10-minute maximum requested timeout, and commands moving into the background when that timeout is reached. It describes task lifetime by command owner (for example, a foreground subagent's command ends with that subagent), not a general 30-minute background-command limit. The linked issue reports a 30-minute limit in its affected environment, so identify it as that environment's observed host limit or otherwise explain the distinction. The guidance to detach may remain useful for host-owned task lifetimes.

Security triage

The deterministic rule did not fire: no changed path, filename, or PR label matches the built-in security triggers, and .code-cycle.yml declares no replacement rule. Reviewer judgment did fire because this change alters CLI subprocess and signal handling. The security audit ran; no security finding was confirmed.

Verification

Preflight 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.

  • python3 scripts/validate-package.py — passed (exit 0).
  • python3 -m unittest discover -s tests -v — passed, 934 tests (exit 0).
  • claude plugin validate . — passed (exit 0).
  • git diff --check a3741a66b807353d6b12a9090686183ae008fd4e...HEAD — passed (exit 0).
  • The Windows-specific --detach creation-flags path was not exercised locally. The Windows CI installer job passed, but it does not provide runtime evidence for this branch.

CI and residual risk

All current PR checks passed: Skills, manifests, and Bash installer (both runs) and PowerShell installer (both runs). No check is pending, failed, cancelled, or skipped. These are the two jobs defined by .github/workflows/validate.yml; no expected PR workflow is missing.

The detached launch's Windows process-creation behavior remains unverified at runtime. The documented SIGKILL limitation also remains: a process killed before cleanup cannot write an interruption record.

APPROVED — the reviewed head matches the PR head, all required checks passed, and there are no open blocking findings.

@datacas
datacas merged commit facc828 into main Sep 30, 2026
4 checks passed
@datacas
datacas deleted the issue-130-survive-host-limits branch October 6, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long stages are killed by the host's background-task limit and cannot be recovered

1 participant