Skip to content

A session that abandons a hung background task fails a Run whose work is done #302

Closed

Description

@JacobStephens2

This was generated by AI during triage.

A Spec run on a private repository (2026-10-01) ended as a Failed run with its Spec PR left a draft, although the Spec review had finished: fixes committed and pushed, PR body rewritten, CI green. The cause thirdshift gave was

spec-review session ended while waiting on a background task (Run each browser test file except the one that stalled, in the foreground), which was killed

The session was not waiting on that task. It had abandoned it.

What happened

  1. spec-review session. The agent ran the target repo's browser test suite. One test file in that repo hangs, so the command outlived its Bash timeout and was moved to the background. The agent tried to kill its own hung process; the auto mode classifier denied that four times ([Interfere With Workloads]). It never used TaskStop. It finished the review, pushed, and ended its turn with the hung task and a watcher on it still running. Both were killed as claude -p exited.

  2. Resume. Told to re-run the work in the foreground, the agent ran the browser test files one at a time in a single command. A second test file hangs too, so that command hit the 600s Bash timeout and was moved to the background. The agent ran the remaining files in a separate command, recorded 22 of 24 files passing in the PR body, and ended its turn saying:

    One background run is still stuck inside …BrowserTest (task b05rbh8is). Nothing depends on it, and it will end with the session.

  3. thirdshift. The stuck task was killed after the last result, so it counted as killed background work a second time, and the Run failed. The steps after the Spec review never ran: the Tickets checklist was not written back, the Spec PR was not marked ready, and it was not taken to its goal.

Why this is a bug

The prompt and the detector disagree.

  • Every Session prompt ends: "Never end your turn while a background task you depend on is still running: ending the turn kills it." That permits ending the turn with a task the agent no longer depends on, which is what this agent did, and said so.
  • The detector treats every task killed after the last result as "work the session was still waiting on". It cannot tell an abandoned task from an awaited one.

A hung command in the target repo is not rare, and the agent cannot always kill it with kill: auto mode may deny it. TaskStop works (an implement session in the same Spec run used it on the same hang and its Run landed), but it is a deferred tool the prompts never mention.

Sessions from the run, on the machine that ran it: the …-spec-review.jsonl and …-spec-review-resume.jsonl logs stamped 20261001T191722Z.

Related: #58 introduced the detection and the Resume; #180 added waiting on a task by its own id.

Activity

  1. JacobStephens2 commented on Oct 2, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Agent Brief

    Category: bug
    Summary: A session that ends its turn with an abandoned background task should not fail a Run whose work is done

    Current behavior:
    Progress::killed_background_work returns every background task killed after the session's last result, and Sessions::run_to_final_message treats a non-empty list as work the session was waiting on: one Resume, then a hard failure, <kind> session ended while waiting on a background task (<task>), which was killed. A task the agent deliberately abandoned (a hung test run it could not kill) is indistinguishable from one it was waiting on, so a session that finished its job fails the Run. In a Spec run this skips writing the Tickets checklist, marking the Spec PR ready and delivering it.

    The headless paragraph that ends every Session prompt, and the Resume prompt, tell the agent not to end its turn while a task it depends on is running. Neither says what to do with a task it no longer needs, and neither names TaskStop.

    Desired behavior:

    Prompt. The headless paragraph tells the agent that before ending its turn it must stop every background task it no longer needs with the TaskStop tool, by task id, and that a task still running when the turn ends is taken as work it was waiting on. The Resume prompt says the same and covers the case that led here: if the re-run hangs or is moved to the background again, stop it with TaskStop and say what could not be run, rather than leaving it running. Keep the existing guidance (foreground, raised Bash timeout, wait by task id or output file, never by process name).

    Detector. A first session that ends with killed background work still gets its one Resume, as now. If the Resume also ends with killed background work, the session no longer fails for that reason alone: thirdshift prints a progress line naming the killed work and carries on, so the steps that follow (PR check, marking ready, CI, mergeability) decide the Run's outcome. If the Run then fails at a later step, the cause it reports and records (stderr, the Failed run commit, the Run notification) also names the killed work, so a session that really did stop short is not reduced to a bare no PR found (the problem #58 fixed).

    The same holds wherever a session's ending is judged this way, including the Architect run's review session, which reads the final message: it gets the final message of the Resume rather than an error.

    A session with no session id to resume, which today fails on killed work without a Resume, behaves like a Resume that ended with killed work: warn and carry on.

    Key interfaces:

    • HEADLESS and prompt::resume() in the prompt module: the new wording. prompts/ is generated: regenerate it with UPDATE_PROMPTS=1 cargo test prompts_page, never edit it by hand.
    • Sessions::run / Sessions::run_to_final_message: no longer return an error for killed background work after a Resume. How the killed work reaches a later failure's cause is the implementer's choice (for example, returned alongside the final message, or kept on Sessions); it must not depend on the caller remembering to ask.
    • Progress::killed_background_work: its doc comment, and the Progress doc comment, stop claiming a task killed after the last result is work the session was waiting on; it is work that may have been.
    • CONTEXT.md: the Resume entry, and any entry describing this failure, say what a second ending with killed work now means. Use the glossary's terms (Run, Resume, Failed run, Session prompt).

    Acceptance criteria:

    • The headless paragraph and the Resume prompt both name TaskStop and tell the agent to stop background tasks it no longer needs before ending its turn; prompts/ is regenerated and the prompts page test passes
    • A session whose Resume ends with a killed background task returns successfully, with the Resume's final message, and a progress line names the killed task
    • A session that ends with killed background work still gets exactly one Resume, never two
    • A Run whose session ended that way and whose PR is in order goes on to mark the PR ready (and, for a Spec run, writes the Tickets checklist first)
    • A Run whose session ended that way and then fails at a later step (for example no PR found) reports a cause that names the killed background work as well as the later failure
    • A session whose last result was an error is unaffected: no Resume, no warning
    • Tests cover the Resume-then-carry-on path and the later-failure-names-the-work path
    • CONTEXT.md and the doc comments match the new behavior

    Out of scope:

    • Deciding from the agent's final message whether a task was abandoned or awaited
    • thirdshift stopping or killing a session's background tasks itself, or putting a time limit on sessions
    • A second Resume, or counting a Resume against the Repair cap
    • Changing Claude Code's auto mode permissions or which tools are deferred
    • The hanging tests in the target repository
  2. added
    bug
    ready-for-agent
    in-progress
    and removed
    ready-for-agent
    on Oct 2, 2026
  3. removed
    in-progress
    on Oct 2, 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