Skip to content

Shell: a command that ends just as its timeout passes is reported as moved to the background #63747

Open

Description

@cevr

Since #63699, a foreground shell call still running at its timeout is moved to the background (Effect.timeoutOption on jobs.block, then shell.timeout(id, 0)).

There is a race: if the command exits between the timeout firing and the move, the call returns the "moved to the background" result, and the real result arrives later as a background notice, although the command had already finished in the foreground.

Expected: when the command has already settled by the time the move happens, the call returns its normal foreground result (output and exit code) and no background notice follows.

In our fork we move the job only while it is still running (jobs.background(id, { running: true }) is a no-op once it has settled), and the call then reads the settled result. Happy to send a PR.

Activity

  1. added
    area/core
    type/bug
    version/v2
    on Nov 13, 2026
  2. opencodejr commented on Nov 13, 2026

    @opencodejr
    Contributor

    Not observed; this looks likely from reading the code.

    Thanks for the precise report. I confirmed this by reading the code on the latest dev (46aefe3). I did not catch it happening in a run.

    • In packages/core/src/tool/plugin/shell.ts, when the foreground jobs.block wait times out, any info returned by jobs.background(job.id) is treated as "moved to the background". The call then runs shell.timeout(id, 0) and notifyWhenDone.
    • In packages/core/src/job.ts, Job.background skips a settled job only when it has no recovery. Shell jobs are always started with recovery, so a command that settles between the timeout firing and the move is still marked as backgrounded. The call then returns the background result, and the real output arrives later as a notice.

    I also drove dev from source with a simulated model making parallel foreground sleep ~1s calls with timeout: 1000. Commands near the boundary were reported as moved to the background and then completed shortly after. From outside I could not tell which of them had already exited before the move, so that run does not prove the race on its own.

    Only running the job move while the command is still running, as you describe, matches how the code reads. A maintainer will look at it.

  3. added
    status/repro-plausible
    on Nov 13, 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

    area/corestatus/repro-plausibletype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions