Skip to content

buildLaunchCommand missing -y flag — spawn silently fails to launch when stdin is a pipe #18

Closed

Description

@scttfrdmn

Summary

SpawnTaskHandler.buildLaunchCommand() does not include -y (auto-approve cost estimate). Without -y, spawn 0.36.9 reads from stdin expecting a JSON cost-approval response. When called from a Java ProcessBuilder (no TTY, stdin is a pipe), spawn returns exit 0 with a "failed to parse JSON" error message — which nf-spawn's exitCode != 0 check misses, so it silently sets status = RUNNING without the instance ever launching.

Reproduction

# Exact command nf-spawn 0.2.1 issues (from SpawnTaskHandler.groovy buildLaunchCommand):
sudo HOME=/root spawn launch nf-test \
    --instance-type t4g.nano \
    --region us-east-1 \
    --ttl 5m \
    --on-complete terminate \
    --user-data-file /tmp/script.sh \
    --wait-for-running=false \
    --wait-for-ssh=false
# → "failed to parse input: failed to parse JSON: unexpected end of JSON input"
# → exit 0 (!)

Fix

Add -y to the command list in buildLaunchCommand():

List<String> cmd = [
    'spawn', 'launch', instanceName,
    '--instance-type', instanceType,
    '--region', region,
    '--ttl', ttl,
    '--on-complete', 'terminate',
    '--user-data-file', scriptPath,
    '--wait-for-running=false',
    '--wait-for-ssh=false',
    '-y',          // ← add this
]

Additional missing flag

buildLaunchCommand() also doesn't pass --ami. Without it, spawn auto-detects via SSM (ssm:GetParameter on /aws/service/ami-amazon-linux-latest/...), which requires the spored-instance-role to have that permission (tracked in spawn#38). To avoid that dependency, nf-spawn should pass ext.ami if provided:

String ami = (ext.ami ?: '') as String
if (ami) cmd.addAll(['--ami', ami])

Context

Activity

  1. added
    bug
    on Jun 3, 2026
  2. scttfrdmn commented on Jun 3, 2026

    @scttfrdmn
    CollaboratorAuthor

    I reproduced this against the actual code before acting, because the primary diagnosis doesn't hold on spawn 0.36.9 (the version cited). Results are mixed — one half doesn't reproduce, the other is real:

    The -y / "silent exit-0 failure" half does NOT reproduce on 0.36.9

    I ran nf-spawn's exact command (no -y, --instance-type t4g.nano, stdin piped/closed) against a real spawn 0.36.9 binary:

    launch nf-test --instance-type t4g.nano --region us-east-1 --ttl 5m \
      --on-complete terminate --wait-for-running=false --wait-for-ssh=false   # no -y, stdin closed
    → EXIT=0, and the instance DID launch (i-8966…; `list` shows 1 instance)
    

    No "failed to parse JSON", no silent no-op. Why: #34 (shipped in 0.36.9, PR #36) routes launch to one of three modes via launchMode(interactive, instanceType, stdinIsTTY):

    • The "parse stdin as truffle JSON" path (modePipe, the source of failed to parse input: failed to parse JSON) requires instanceType == "". nf-spawn always passes --instance-type, so it's modeFlags — stdin is never read.
    • The only stdin reads left in launch are two fmt.Scanln cost/locality prompts, both guarded by if !autoYes (launch.go:1380, 3148), and one of those only fires on a cross-region data-locality mismatch. On closed stdin Scanln returns an error harmlessly and proceeds — it doesn't abort with a JSON error.

    So the repro in the issue looks like it was captured against a pre-0.36.9 / pre-#34 spawn, where --instance-type + piped stdin still hit the truffle-parse path. On 0.36.9 it's already fixed.

    That said — adding -y is still correct and worth doing. It's harmless in modeFlags, and it future-proofs against the cost-approval prompt ever becoming reachable (e.g. the cross-region locality path, or a behavior change). Cheap insurance; no objection. Just want the issue's stated mechanism on record as not the actual 0.36.9 behavior, so we don't believe we fixed a silent-failure bug that wasn't there.

    One correction to the issue body regardless of version: spawn does not "return exit 0 with a failed-to-parse error" — in the genuine pipe path it returns the error with a nonzero exit (return i18n.Te("error.input_parse_failed", err)). If a real run truly saw exit 0 + that message, that's a separate spawn bug and I'd want the spawn version (spawn version) + the literal stderr to chase it.

    The --ami half is REAL ✅

    Confirmed: without --ami, spawn auto-detects via ssm:GetParameter on /aws/service/ami-amazon-linux-latest/... (pkg/aws/ami.go:22-27,59), which needs the instance/caller role to have that SSM permission — exactly spawn#38 (open). Passing ext.ami when provided is a good way to sidestep that dependency. 👍

    Suggested resolution

    Both flag changes are reasonable to land in nf-spawn:

    1. Add -y to buildLaunchCommand() — defensive, not a 0.36.9 bugfix.
    2. Add optional --ami from ext.ami — real, avoids the spawn#38 SSM-permission dependency.

    Want me to take both (with a guard test asserting -y is present and --ami is passed iff ext.ami is set)? If you can also share spawn version from the failing run, I'll confirm whether the silent-failure was a genuinely older binary or something still live.

  3. scttfrdmn commented on Jun 3, 2026

    @scttfrdmn
    CollaboratorAuthor

    Thank you — the version confusion makes sense. The head node AMI was baked with spawn 0.36.6 (installed via spawn_0.36.6_linux_arm64.rpm in the bake script). We upgraded spawn on the laptop to 0.36.9 before testing, but the head instance itself was still running 0.36.6, where the pipe-mode bug was live. That explains the observed behaviour.

    The AMI bake script installs whichever version is latest from GitHub releases at bake time — so the next rebake will pick up 0.36.9 and the pipe issue goes away automatically.

    Please do take both flag changes: -y for defensive forward-compat, and --ami from ext.ami to sidestep spawn#38. Both are clean improvements regardless of version.

    spawn version from the failing run: 0.36.6 (confirmed from the instance; the laptop had 0.36.9 at the time of testing which caused the version mismatch).

  4. added a commit that references this issue on Jun 3, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions