Skip to content

Investigate: failed-task instance reported still running past on_complete terminate (#92 secondary observation) #93

Closed

Description

@scttfrdmn

Context

Split out from #92 (docker socket permission fix). The reporter observed, while diagnosing the exit-126 docker-permission bug:

instances did not promptly self-terminate. A failed task's instance (exit 126) was still running after the pipeline aborted (I terminated it manually; TTL would eventually reap it), and even a completed task's instance lingered ~1-2 min post-completion.

What's confirmed NOT a bug

The completed-task ~1-2 min lingering matches spored's known lifecycle ticker: Agent.Monitor in spawn's pkg/agent/agent.go polls checkAndAct (which drives on_complete) on a ticker that defaults to 1 * time.Minute (interval := a.monitorInterval; if interval <= 0 { interval = 1 * time.Minute }, line ~316-319). A completion signal that lands just after a tick fires waits up to ~1 tick period before the next tick notices it and acts — bounded, expected behavior, not a bug.

What's NOT yet explained — needs live investigation

The failed-task instance allegedly stayed running (not just laggy — requiring manual termination) is harder to reconcile with the code as read statically:

  • nf-spawn's SpawnTaskHandler.buildTaskSpec (src/main/groovy/io/nextflow/spawn/SpawnTaskHandler.groovy) does NOT set spec.container — nf-spawn does its own docker run inside its staging script, and that whole staging script is handed to spawn as spec.command = ['/bin/bash', '-lc', stagingScript].
  • spawn task run executes this via taskproto.GenerateWrapper (pkg/taskproto/wrapper.go in spore-host/spawn), which runs the ENTIRE nf-spawn staging script as a subshell (( %s )), captures rc=$? from it, and then unconditionally writes completion.json and /tmp/SPAWN_COMPLETE based on that rc — regardless of whether the failure was a docker permission error (rc=126) or anything else. This is the default signalComplete=true path (one-instance-per-task, not the pooled-worker path).
  • Given that, on_complete (terminate) should fire on the very next 1-minute tick even for a failed exit-126 task — same as a successful one.

So there's no obvious code-level reason a failed task's instance would linger any longer than a completed one. Possible explanations, none confirmed:

  1. The reporter checked before the next 1-minute tick fired (i.e., not actually a bug — just impatience/timing, same bound as the completed case).
  2. Some interaction between Nextflow's pipeline-abort behavior (when other tasks in the DAG fail and Nextflow tears down the run) and spored's completion signal / instance state at that moment.
  3. A genuine gap specific to the failure path — e.g., IMDS/tag propagation, or an interaction with nf-spawn's killTask() (which calls spawn terminate when Nextflow explicitly kills a task) racing or conflicting with spored's own on_complete self-termination.
  4. Possibly noise from the Containerized processes fail exit 126: nf-spawn's docker run can't reach the Docker socket (task user not in docker group) #92 bug itself (every task was failing in a confusing way) that may not reproduce now that Containerized processes fail exit 126: nf-spawn's docker run can't reach the Docker socket (task user not in docker group) #92's docker-socket fix has landed.

Ask

Needs a live, real-AWS re-run (now that #92 is fixed) with a deliberately-failing containerized task (e.g. container pointing at an image with a script that exits non-zero) to observe:

  • Does the failed instance's /tmp/SPAWN_COMPLETE / completion.json get written promptly?
  • Does on_complete terminate fire within the expected ~1-2 min bound, same as the completed case?
  • If not, capture spored's own logs on the instance (journalctl -u spored or wherever it logs) to see what it observed and when.

This is intentionally NOT bundled into #92's fix — it needs live observation to confirm or refute, not a code-level fix based on speculation.

Activity

  1. scttfrdmn commented on Sep 5, 2026

    @scttfrdmn
    CollaboratorAuthor

    Live re-run — confirmed NOT a bug (hypothesis 4, "#92-era noise")

    Ran a real DAG on AWS today with nf-spawn built from current main (7412d54, plugin manifest Plugin-Version: 0.10.0, includes #92's sudo-docker fix and #90/#91) against spawn v0.104.0 (git 2ff3412). Account/region: spore-host-dev (435415984226), us-east-1.

    Pipeline (/tmp/issue93-repro/main.nf): two container 'ubuntu:22.04' processes, t3.micro, ttl=10m, workDir = s3://spawn-results-435415984226-us-east-1/nf-runs/issue93-repro-20260905-213804 —

    • OK_TASK — exits 0
    • FAIL_TASK — deliberately exit 3

    What happened (timestamps UTC)

    time event
    21:38:35 both tasks submitted (nf-5c21879fafe7 OK, nf-ba74367de3ef FAIL)
    21:38:40 both instances launched
    21:40:10 FAIL_TASK's docker run exits rc=3 (command.log: command exit rc=3)
    21:40:11–14 FAIL_TASK's S3 completion record lands: completion.json (state: failed, exit_code: 3, retry_class: app_error), .exitcode = 3
    21:40:11 Nextflow's checkIfCompleted() observes it, task handler logs Task 'FAIL_TASK' failed (exit 3)
    21:40:11 Nextflow aborts the run (single-task DAG, no dependents) and calls killTask() on the other, still-running OK_TASK — explicit spawn terminate
    21:40:21 OK_TASK explicit terminate confirmed (Terminated spawn instance 'nf-5c21879fafe7') — this one died via killTask(), not on_complete
    21:41:40 FAIL_TASK's instance (i-0e06ed1d72b840fd0) still running
    21:42:00 FAIL_TASK's instance → shutting-down
    21:42:22 FAIL_TASK's instance → terminated

    So FAIL_TASK's own instance self-terminated via spored's on_complete: terminate ~2m08s–2m28s after its completion record landed — the same ~1-2 min ticker bound documented for the successful case (spawn's Agent.Monitor/checkAndAct 1-minute ticker), not materially different. No lingering, no manual intervention needed, no gap in the failure path.

    Which hypothesis this confirms

    Hypothesis 4 — noise from #92 itself. #92 (fixed, PR #94, merged before this run) meant every containerized task failed exit 126 with docker: permission denied, before nf-spawn's own docker-run line ever produced a real, task-level exit code. Under that bug it's plausible the completion record / S3 artifacts the reporter was checking for were confused with the docker-permission failure itself, or the reporter observed the box before this same ~1-2 min bound elapsed and (reasonably) assumed something was stuck, since it was already suspicious that every task was failing in a confusing, opaque way.

    With #92 fixed, the completion record for a failed task is written just as promptly as for a successful one (both via taskproto.GenerateWrapper's unconditional stage-out + completion-record path, exactly as the static read in this issue predicted), and on_complete: terminate fires on the identical ~1-2 min ticker bound in both cases. I did not find any gap specific to the failure path, and no interaction between killTask() and on_complete caused a leak either — killTask() only fired against the other, non-failed task in the DAG (an explicit spawn terminate, logged and confirmed), which is expected Nextflow DAG-abort behavior (hypothesis 2 territory) and worked correctly, not a race.

    One adjacent, real bug worth noting for context (not a nf-spawn issue, and already fixed upstream): spawn had spore-host/spawn#566 — a task whose command failed produced no completion record at all (the wrapper inherited set -e from pkg/launcher/bootstrap.go's preamble and aborted before rc=$?/stage-out/the completion write), so a failed task really did ride to TTL instead of self-terminating. That's fixed in spawn v0.103.1 (set +e made explicit in the wrapper, spawn#567) and is what this run was implicitly re-verifying at the spawn layer too — the repro above shows the fixed behavior (prompt completion record + prompt on_complete on the failure path).

    Cost-safety confirmation

    • Instances launched: i-0e06ed1d72b840fd0 (FAIL_TASK, nf-ba74367de3ef), i-08d8c9fdee85b8a1f (OK_TASK, nf-5c21879fafe7).
    • i-08d8c9fdee85b8a1f: terminated via nf-spawn's killTask() (spawn terminate) at 21:40:21, confirmed terminated.
    • i-0e06ed1d72b840fd0: self-terminated via spored's on_complete: terminate at 21:42:22, confirmed terminated.
    • Independently re-verified via aws ec2 describe-instances in us-east-1 (and spot-checked us-east-2/us-west-2): zero non-terminated instances remain from this investigation.

    Conclusion

    Closing as confirmed-not-a-bug: hypothesis 4 (noise from the now-fixed #92) is the best fit for the original observation, with hypothesis 1 (timing/impatience) plausibly compounding it — a "stuck" box during the #92 outage, re-checked today with #92 fixed, now self-terminates on the same bound as a successful task. No nf-spawn code change needed.

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