Repository navigation
Description
Summary
cancel_task sets the pipeline status to CANCELLED, tears down its containers, and clears its
runtime state — but it never stops the _run_pipeline driver thread or the BRC event loop. Both
keep running in-process, so a cancelled pipeline keeps driving its slice DAG: admitting the next
slice, creating its integration branch, and spawning agents.
Observed on issue-3596-v2, which spawned slice-3 agents two hours and seven minutes after it
was cancelled.
Related but distinct from #3632. That one is "cancel destroys the state it promised to preserve";
this one is "cancel does not stop the work it promised to stop." They are opposite halves of the
same broken contract and probably want fixing together.
Mechanism
The cancel path is update_pipeline → status CANCELLED (routes/pipelines/_routes_crud.py). It
does exactly three things:
- spawns
_background_cleanup, which callsspawner.cleanup_pipeline(...)to remove containers; - calls
_clear_pipeline_runtime_state(tracker + message store — see cancel_task(cleanup=false) destroys the consensus + message state its own contract promises to preserve #3632); - writes the new status.
It never calls stop_event_loop, and it never signals the driver thread. The only callers of
stop_event_loop in the tree are in routes/pipelines/_run_concurrent.py (lines 486, 567, 1144) —
i.e. the concurrent phase stops its own loop when the phase function returns normally. A cancel
from outside does not make it return.
So killing the pods removes the symptom while the thing that spawns pods keeps running. The next
poll re-derives its arms and spawns again.
Note the assumption this violates, already written down in _routes_restart.py:314:
Unlike a RUNNING pipeline — whose live event loop picks up the consensus reset below and respawns
within one poll — a FAILED/CANCELLED pipeline has NO live event loop:_run_concurrent_phase
already returned andstop_event_loop()tore the loop down on its way out, and the
_run_pipelinedriver thread has exited.
The restart path's correctness argument depends on that being true. It is not true for a pipeline
cancelled mid-phase.
Evidence
issue-3596-v2 was cancelled at 20:48:52Z via cancel_task(cleanup=false). Branch state
captured immediately after the cancel — there is no slice-3:
origin/egg/issue-3596-v2/slice-1 tip=66d99b53c 39 commits ahead of main
origin/egg/issue-3596-v2/slice-2 tip=4f6217292 33 commits ahead of main
origin/egg/issue-3596-v2/work tip=94057299c 60 commits ahead of main
At 22:55:35Z, with the pipeline still persisted as CANCELLED, two agent pods appeared:
egg-sandbox-egg-agent-issue-3596-v2-slice-3-coder-104ee0c848hdt 0/1 Completed
egg-sandbox-egg-agent-issue-3596-v2-slice-3-documenter-754wb9s7 0/1 Completed
They were live enough to call home — the orchestrator logged their traffic at 22:56:50Z:
POST /api/v1/pipelines/issue-3596-v2/heartbeat status=200
POST /api/v1/pipelines/issue-3596-v2/consensus/next-action status=200
And a slice-3 integration branch now exists, forked from slice-1's tip:
origin/egg/issue-3596-v2/slice-3 tip=66d99b53c 39 commits ahead of main
Pipeline status throughout, and still now:
status: cancelled phase: implement updated: 2026-07-25T22:55:25Z run_epoch: 2026-07-25T04:50:56Z
It was not startup reconciliation. startup_reconciliation.py:133 and :305 both skip any
pipeline whose status is not RUNNING, and the replacement orchestrator pod's log contains no
non-API mention of issue-3596-v2 at all. Kubernetes events show a single pod transition (old pod
killed, replacement created ~30s later), so the spawn came from the original orchestrator process
that had been running since before the cancel.
Impact
Bounded in this instance, but only by luck of timing — the agents were killed by the redeploy about
a minute in:
- Two agent pods spawned and ran against a cancelled pipeline (real model spend).
- One integration branch created and pushed.
- No commits, no PRs.
The general case is worse. A cancelled pipeline that is not about to be redeployed keeps its loop
indefinitely, so it can walk the entire remaining slice DAG: spawn agents, let them commit, push
branches, and open slice PRs — all for a run the operator believes is stopped. Given auto_create_pr
defaults on, "cancelled" pipelines opening PRs is reachable today.
It also corrupts anything that counts operator interventions or agent invocations for a run, which
is exactly what #3601's evaluation is measuring.
What I could not establish
Why the spawn happened at 22:55 rather than shortly after the 20:48 cancel. Something let the slice
scheduler admit slice-3 at that moment — plausibly slice-2's agents being torn down by the redeploy
freeing the concurrency slot, or a poll tick after a park expired — but the original orchestrator
pod's log died with the pod, so this is unverified. The two-hour gap means a naive repro ("cancel,
then watch for a minute") may show nothing; the loop is alive the whole time regardless.
Suggested fix
Make cancel stop the driver. Concretely:
- Signal the
_run_pipelinedriver thread to exit on a terminal status transition (a per-pipeline
stop event checked at the phase loop's poll points), and callstop_event_loopfor the pipeline
from the cancel path rather than relying on_run_concurrent_phasereturning. - Have the event loop and slice scheduler re-read pipeline status and refuse to spawn when it is
terminal — defence in depth, so a missed stop signal costs a no-op poll rather than a slice. - Order it so the loop stops before
_background_cleanupremoves containers; today the cleanup
races a live loop that is entitled to spawn replacements. - Add a regression test: cancel a pipeline mid-implement with an un-admitted slice remaining, then
assert no Jobs are created and no new branches appear on subsequent poll intervals.
Activity
simplifier: update human-facing summary per operator feedback
simplifier: add human-focused plan summary for issue #3632
architect: plan proposal for #3632 — ACK task_planner plan with R6 ga…
jwbron commentedon Jul 26, 2026
Third observation, on
issue-3632-v1at cancel time (2026-07-26 21:05Z).cancel_task(cleanup=false)returned and the pipeline persisted ascancelled. Within the next minute the event loop spawned two more agent Jobs:Both exited in ~5 seconds, so the blast radius here was trivial — but the mechanism is the same one that walked
issue-3596-v2onto slice-3 two hours after its cancel: the driver and event loop are not stopped, so the next poll derives arms and spawns.Two things this adds to the report:
auto_create_pron — can open a PR from a pipeline the operator believes is stopped.Allowlist two files pushed over the size cap by #3633 review fixes
Stop the slice loop when a restart supersedes it too (#3633)
Merge pull request #3645 from jwbron/issue-3633-cancel-stops-driver