Skip to content

DAG instances don't reliably self-terminate: terminal task lingers on success, failed tasks stay running (v0.10.1) #96

Closed

Description

@scttfrdmn

DAG task instances don't reliably self-terminate — the terminal task lingers on success, and a mid-DAG failure leaves instances running

Running a 5-process fan-out+join DAG (executor = 'spawn') on v0.10.1 (with #92 fixed — the pipeline now completes clean), the instance lifecycle at DAG scale still has a gap:

On success: the terminal task's instance lingers after the pipeline reports completed=5. Observed twice (v0.8.0 run and this v0.10.1 run): the four upstream tasks (MAFFT, MUSCLE, both TREEs) had self-terminated by the time I checked, but the join task (OBSERVE_RF) instance was still running — same task both times, so it's a consistent pattern, not random termination lag. I terminated it manually each time; TTL would eventually reap it.

On failure (from the pre-#92-fix runs): a failed task's instance did not self-terminate at all — it stayed running after the pipeline aborted, and Nextflow's "Killing running tasks" did not tear down the EC2 instance. Two failed runs each left their instance up (terminated manually).

Why it matters: at Shape-F scale, N instances have N lifecycles. A workflow that fails partway (a common case — one bad rule) can leave several instances running, not one. The single-task path (spawn task run directly) self-terminates reliably on both success and failure; the executor path doesn't inherit that for the terminal task or for failures.

Repro: any multi-process DAG; check aws ec2 describe-instances --filters Name=tag:spawn:task-id,Values=nf-* immediately after the run — the terminal task's instance is typically still running.

Suggested fix: ensure nf-spawn issues spawn task's terminate for every dispatched task on both completion and pipeline abort (not just relying on on_complete: terminate / TTL for the terminal and failed tasks). Until then, consumers should verify terminations explicitly after a run rather than trusting the pipeline's success line — which is what our recipe's README now says.

Found building the Shape-F recipe for scientific-codes-cookbook (nf-spawn v0.10.1, Graviton). Distinct from the now-fixed #92 (socket) — this is the instance-lifecycle side.

Activity

  1. scttfrdmn commented on Sep 5, 2026

    @scttfrdmn
    CollaboratorAuthor

    Adding the severity framing, because this is the more consequential of the two lifecycle findings: every Shape-B spawn task run self-terminates to nothing on both success and failure — the executor path does not yet inherit that. So a large DAG that fails partway can leave several instances running, and even a clean run leaves the terminal task's box up. With TTL-as-backstop the worst-case exposure is TTL × instance count, not a few minutes — for a wide fan-out that's real money before the reaper catches it. That's why the recipe README tells users to verify terminations explicitly after every Shape-F run rather than trusting the pipeline's success line.

  2. scttfrdmn commented on Sep 5, 2026

    @scttfrdmn
    CollaboratorAuthor

    Live re-test on v0.10.1 (main @ 4982237) — could not reproduce either symptom

    Built nf-spawn from current main (v0.10.1, includes #92's docker-socket fix) and ran a real fan-out+join DAG via executor = 'spawn' against spore-host-dev (account 435415984226, us-east-1), t3.micro, ttl='10m' — the DAG topology #93 never exercised (two independent processes feeding a genuine join step).

    Test 1 — success path (TASK_A, TASK_B independent → JOIN_C depends on both)

    event time (UTC) instance
    TASK_A + TASK_B submitted 22:24:41 nf-9f823df5a707 (A), nf-6f88bda5ce8b (B)
    TASK_A completed (exit 0) 22:26:21
    TASK_B completed (exit 0) 22:26:26
    JOIN_C submitted 22:26:27 nf-b2b44debfb0f
    check: A + B instances already terminated, JOIN_C running 22:27:37 —
    JOIN_C completed (exit 0) 22:28:11
    check: JOIN_C instance still running 22:28:45 (34s post-completion)
    check: JOIN_C instance terminated 22:30:19 (128s post-completion)

    The join task's instance self-terminated on its own, with no manual intervention, in a window consistent with the same ~1-2 min spored lifecycle-ticker bound documented in #93 for independent tasks (TASK_A/B terminated in ~71-76s; JOIN_C in ~128s — a bit longer but still one tick-alignment away, and JOIN_C's boot+setup start later in wall-clock time than A/B's). I did not observe the reported "lingers indefinitely, needs manual termination" behavior — it just took the same kind of bounded tick delay independent tasks take.

    Test 2 — failure path (TASK_A exits 1; TASK_B sleeps 90s; JOIN_C depends on both)

    event time (UTC) instance
    TASK_A + TASK_B submitted 22:31:02 nf-12dc53f9374e (A, will fail), nf-896c9914afde (B, long-running)
    TASK_A failed (exit 1) 22:32:42
    Nextflow aborted session, "Killing running tasks (1)" 22:32:42.7
    check: TASK_B instance already terminated; TASK_A instance running 22:33:48
    check: TASK_A instance terminated 22:35:25 (163s post-failure)

    killTask() fired immediately for the in-flight TASK_B on Nextflow's abort and its instance was gone within ~66s (explicit spawn terminate, fast — as designed). The failed TASK_A's own instance self-terminated via its own on_complete terminate within a normal tick-bound window (~163s) — no manual termination needed. This directly contradicts the second symptom in the issue, but matches the reporter's own caveat that this part of the report was from pre-#92 runs.

    Code review (no topology-aware gap found)

    Read SpawnTaskHandler.groovy (checkIfRunning/checkIfCompleted/killTask/buildTaskSpec) and spawn's pkg/agent/agent.go (Monitor/checkAndAct/checkCompletion/terminate) and pkg/taskproto/wrapper.go (generateWrapper). Nothing in either path is aware of a task's position in Nextflow's DAG:

    • Completion detection is per-task-instance, driven purely by .exitcode/completion.json landing in the task's own S3 work dir — Nextflow's dependency graph is invisible to spawn/spored entirely.
    • The 1-minute spored lifecycle ticker (agent.go Monitor) starts from that instance's own boot; it has no notion of "am I a join step" or "was I the last task to finish."
    • killTask() in SpawnTaskHandler.groovy calls spawn terminate <taskId> unconditionally (outside pool mode) — no branch keyed on dependency count.

    So there's no plausible mechanism I can find for a join task to behave differently from an independent one, and the live re-test bears that out.

    Conclusion

    Both reported symptoms are not reproducible on current main (v0.10.1). Closing, mirroring how #93 was closed — same "confirmed not a bug" outcome, now with a repro that actually covers the join/DAG-dependency topology #93 didn't test. The two original join-task-lingering observations (v0.8.0 and v0.10.1) are most plausibly explained the same way #93's original report was: checked before the next tick fired, then manually terminated out of caution — not a hang. If it resurfaces with a longer lingering window (well past ~2-3 min) or a captured journalctl -u spored showing the ticker stalled, that would be strong evidence of a real, different bug worth reopening against.

    Cost-safety confirmation: all 5 instances launched during this investigation are confirmed terminated via aws ec2 describe-instances (raw API, not spawn/spored tooling): i-9f823df5a707→nf-9f823df5a707, i-0399cf42af553db9d, i-059b420d87b61e43d→nf-6f88bda5ce8b, i-064aa2d9580e6e52f→nf-b2b44debfb0f, i-0a26d38570cb71c9e→nf-12dc53f9374e, i-06d67d5bd159f12ea→nf-896c9914afde. A follow-up region-wide sweep (describe-instances --filters instance-state-name=running,pending,stopping,stopped) returned zero results.

  3. scttfrdmn commented on Sep 5, 2026

    @scttfrdmn
    CollaboratorAuthor

    Closing per the comment above: both symptoms are not reproducible on current main (v0.10.1) with a live DAG repro that actually exercises the join-task topology. Reopen with fresh evidence (e.g. a captured spored journalctl showing a stalled ticker, or a lingering window well past ~2-3 min) if it resurfaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions