Skip to content

No way for a shell command to intentionally outlive its own tool call (long-running background jobs get killed by design) #465

Closed

Description

Summary

Every bash tool invocation's spawned process tree is torn down the moment the top-level process exits — including descendants that deliberately try to detach via setsid/disown. This appears fully intentional (there's even a comment in process-ledger.ts acknowledging the setsid-escape case), and it's a reasonable default for safety/resource hygiene. But there's currently no supported way for an agent to say "actually, let this one keep running past this tool call, and let me check on it later" — which real workloads (long downloads, model training, genome index builds, anything multi-hour) genuinely need.

What I found (traced through the source)

  • backend/cli/src/tool/bash.ts spawns every command with detached: true on Linux.
  • On exit (success or failure — not just timeout/abort), CommandRuntime's registered complete() callback in backend/cli/src/science/command/registry.ts calls CredentialProcessLedger.complete().
  • groupMembers() in backend/cli/src/credentials/process-ledger.ts walks the full descendant tree by PPID, not just process-group membership:
    const descendants = new Set([entry.pid])
    let changed = true
    while (changed) {
      changed = false
      for (const row of rows) {
        if (descendants.has(row.pid) || !descendants.has(row.ppid)) continue
        descendants.add(row.pid)
        selected.set(row.pid, row.pgid === entry.pid)
        changed = true
      }
    }
  • A setsid'd child changes its session/process-group ID but not its PPID, so it's still discovered here (with groupBound: false). signalMember()'s guard only skips members whose group changed while still groupBound — a non-group-bound member goes straight to SIGKILL.

So this isn't a bug in the traditional sense — it's a deliberate, well-engineered containment guarantee. But it means there's no way to intentionally opt out of it for a specific command.

Concrete case where this bites

Running a real bioinformatics pipeline (downloading ~18 SRA runs via fasterq-dump, building STAR genome indexes) through the agent — every one of these is naturally a multi-minute-to-hour job. The agent correctly discovered it cannot background any of this across tool calls (confirmed via the mechanism above), and had to fall back to running everything synchronously inside single long-timeout bash calls, using --cache-dir for resumability when a call's timeout is hit mid-job. That works, but it's a workaround for a missing capability, not a good long-term story for any workload with real long-running jobs.

Proposed direction

A first-class, supervised background-task primitive on the bash tool — something like Claude Code's own run_in_background parameter: a command that's explicitly registered as intentionally long-lived, tracked (so list/status tooling still knows about it and it's still subject to session/project cleanup on teardown), but not torn down just because the tool call that launched it returned. The agent could then poll/check on it in later tool calls instead of needing to keep a single bash call open for the entire job duration.

Happy to discuss the design here before attempting anything — flagging per CONTRIBUTING.md's guidance that this looks like a core-behavior change, not a small bug fix. Glad to help however's useful (more repro detail, testing a prototype, etc.).

Activity

  1. satya-arjunan commented on Aug 31, 2026

    @satya-arjunan
    ContributorAuthor

    Correction/update: after filing this, I found that compute_job (the start action, with target: {"kind":"local"}) already provides exactly this — a detached job dispatch that survives independent of any single bash tool call, checkable later via status/wait/logs/artifacts. ComputeCapabilities.describe() marks the local target as available: true unconditionally, no Modal/SSH setup required, and it's permitted by default for at least the research agent.

    So the premise above was incomplete — there is a supported way to do this, I just hadn't found it yet. Sorry for the noise on that front.

    I think there's still a real, smaller gap worth keeping this issue open for: nothing in the bash tool's own description points toward compute_job for long-running work, so an agent hitting a multi-minute-plus job has no signal to reach for it instead of shell-level backgrounding (nohup/setsid/disown), which — as traced above — gets reliably torn down. A one-line pointer in the bash tool's description (something like "for work that should outlive this call, use compute_job instead") would probably close most of the gap without any behavior change.

    Happy to help test/verify that framing, or close this out if you'd rather track it differently.

  2. satya-arjunan commented on Aug 31, 2026

    @satya-arjunan
    ContributorAuthor

    Follow-up: tested this empirically (isolated project, nothing to do with the original repro) rather than just reading the source. Had an agent, via compute_job:

    1. Start a local job: sleep 90 && echo JOB_COMPLETE > marker.txt
    2. Check status immediately — running at t≈0s
    3. wait ~30s, then check status again — still running at t≈60s, with nothing in between keeping it alive except its own schedule
    4. wait until terminal — succeeded, exit_code: 0, completed at t≈91s (matches sleep 90)
    5. Read marker.txt from the job's working directory — present, exact expected contents (JOB_COMPLETE\n)

    So: confirmed, not just architecturally plausible — the job ran on its own clock across multiple separate tool calls with zero keep-alive from the calling agent. This matches the FileLease/disk-backed job-tracking design in jobs.ts, distinct from the bash tool's in-memory CommandRuntime ledger that tears down on tool-call exit.

    Given that, I'd frame the actionable ask here as purely the documentation/discoverability nudge from my earlier comment (a line in the bash tool's description pointing toward compute_job for anything long-running) rather than any new capability — the capability itself already works exactly as intended.

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