Skip to content

senior-dev: a service it starts in the background is killed when the run ends #2901

Backlog

Description

@santoshkumarradha

What happens

When a task asks senior-dev to start a service and leave it running (for example "start a Flask API on port 5000 in the background"), senior-dev starts it, checks it, and reports success. Then the run ends and the service is gone. Anything that talks to the service after the run gets Connection refused.

Steps to reproduce:

  1. In a plain folder, run codeaf senior-dev run --in-place -- "Write a small HTTP server in server.py and start it in the background on port 5000 so it keeps serving after you finish."
  2. Senior-dev starts the server (for example nohup python3 server.py &), curls it successfully, and submits with status pass.
  3. After the command exits, curl localhost:5000 is refused and the process no longer exists.

Why

Closing the run's runtime kills every process group the bash tool started:

  • internal/seniordev/app/runtime.go: runtimeAdapter.Close() calls registry.CloseShellProcesses().
  • internal/seniordev/tool/bash.go: CloseShellProcesses() sends SIGKILL to each registered group (syscall.Kill(-pid, SIGKILL)). After closed is set, registerShellGroup kills any group it is handed.

A nohup … & job stays in the bash tool's process group, so it is killed. Only a process that leaves the group (for example with setsid) survives. The model is not told this, and it has no reason to expect it.

This is present on dev (ca8e437) and on main.

Why it matters

Cleaning up stray jobs is right for builds, watchers and test servers the agent used for itself. When the deliverable is a running process, though, the cleanup undoes the work after senior-dev has reported success:

  • services, daemons and dev servers the person asked to be left up
  • background workers or schedulers the task sets running

The run says it passed, but what the person asked for is not there.

Possible directions

  • Let the model mark a process as the deliverable (a tool option or a recorded "left running" list), keep those, and name them in the ending. The chat already has a notion of a left-running service (see Left-running service description can name an unrelated process if a member's PID is reused #2260).
  • Or, at least, tell the model in the tool description that background jobs are killed when the run ends and that setsid detaches one on purpose, and say in the ending which processes were stopped.

Activity

  1. santoshkumarradha commented on Nov 24, 2026

    @santoshkumarradha
    MemberAuthor

    Correction to the description above: setsid does not let a process escape either. There are two more sweeps behind the bash tool's group kill:

    • internal/seniordev/app/run.go makes the engine a child subreaper (processgroup.EnableSubreaper) and defers processgroup.CleanupDescendants(), which SIGKILLs every process descended from the engine, detached or not.
    • processgroup.CleanupRun(marker) kills every process carrying CODEAF_DELEGATE_RUN after the engine itself is SIGKILLed.

    So any fix needs to account for all three (CloseShellProcesses, CleanupDescendants, CleanupRun), and the "tell the model to use setsid" direction does not work as written.

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